Sha256: 343ea729705d8542274febe91aa51d3d3f9501b03e378850919d8082b3ceaf9b

Contents?: true

Size: 1.47 KB

Versions: 72

Compression:

Stored size: 1.47 KB

Contents

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

  $table = $(event.currentTarget)
  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 = {
    'authenticity_token': $('head').find("meta[name='csrf-token']").attr('content'),
    'reorder[id]': oldNode.data('reorder-resource'),
    'reorder[old]': oldNode.val(),
    'reorder[new]': newNode.val(),
    'attributes': $table.data('attributes')
  }

  @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, 'danger')
  ).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

  if column.visible()
    $table.removeClass('reordering')
  else
    $table.addClass('reordering')

  column.visible(!column.visible())

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
effective_datatables-4.30.1 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.30.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.29.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.26.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.25.3 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.25.2 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.25.1 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.25.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.24.2 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.24.1 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.24.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.23.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.22.3 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.22.2 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.22.1 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.22.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.21.1 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.21.0 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.20.6 app/assets/javascripts/effective_datatables/reorder.js.coffee
effective_datatables-4.20.5 app/assets/javascripts/effective_datatables/reorder.js.coffee