Sha256: 17254e8ad6a87e8642bd8a5af12d6373cb1eb71d50a14763dc4640d59beb78d4

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

$ ->
  if $('#list')[0]
    $("#list input.toggle").live "click", ->
      checked = $(this).is(":checked")
      $("#list [name='ids[]']").attr "checked", checked
      $('#list tbody tr').toggleClass('active_row', checked)

    $("#list tbody input").live "click", ->
      $(this).closest('tr').toggleClass('active_row')

    submitBatch = (el) ->
      if $("#list [name='ids[]']:checked")[0]
        $el = $(el)
        ids = $("#list [name='ids[]']:checked").map(-> $(this).val()).get()
        action = $el.data('action')
        $('#batch_action').val(action)
        $form = $('#batch_action_form')
        $form.append("<input type='checkbox' name='ids[]' checked='1' value='#{id}'/>") for id in ids
        $form.submit()

    $('#list tbody tr').live 'click', (e) ->
      return true unless _.include(['TR', 'TD'], e.target.tagName)
      e.preventDefault()
      e.stopPropagation()
      $el = $(this)
      $el.closest('tr').toggleClass('active_row')
      $el.find('td:first input').attr 'checked', (i, v) -> !v

    $('.batch_action_link').live
      click: (e) ->
        e.preventDefault()
        submitBatch(this)
      'confirm:success': ->
        submitBatch(this)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ab_admin-0.1.2 app/assets/javascripts/ab_admin/core/batch_actions.js.coffee
ab_admin-0.1.1 app/assets/javascripts/ab_admin/core/batch_actions.js.coffee