Sha256: af681ff970ec437c1c53454b4e688d4a05a64078eefbfd9479a4ff2004430151

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

reorder = (event, diff, edit) ->
  change = diff.find (obj) -> obj.node == edit.triggerRow.node()
  return unless change?

  oldNode = $("<div>#{change.oldData}</div>").find('input[data-reorder-resource]')
  newNode = $("<div>#{change.newData}</div>").find('input[data-reorder-resource]')
  return unless oldNode? && newNode?

  url = @context[0].ajax.url.replace('.json', '/reorder.json')
  data = {'reorder[id]': oldNode.data('reorder-resource'), 'reorder[old]': oldNode.val(), 'reorder[new]': newNode.val()}

  @context[0].rowreorder.c.enable = false

  $.ajax(
    method: 'post',
    url: url,
    data: data,
    async: false
  ).fail((response, text, status) =>
    $(event.target).closest('table').DataTable().flash(status)
  ).always((response) =>
    @context[0].rowreorder.c.enable = true
  )

$.fn.DataTable.Api.register('reorder()', reorder);

$(document).on 'click', '.dataTables_wrapper a.buttons-reorder', (event) ->
  event.preventDefault() # prevent the click

  $link = $(event.currentTarget)
  $table = $link.closest('.dataTables_wrapper').find('table.dataTable').first()

  column = $table.DataTable().column('.col-_reorder')
  return unless column.length > 0

  column.visible(!column.visible())

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_datatables-4.3.9 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.3.8 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.3.7 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.3.6 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.3.5 app/assets/javascripts/effective_datatables/reorder.js.coffee