Sha256: 8299702e175d3264cd2deb8e8441b3cb73741e24e6a1040c88079a696839efdd

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

class window.SortableTree
  constructor: (@cont) ->
    @url = @cont.data('url')
    @max_levels = @cont.data('max_levels')
    @initTree()

  initTree: ->
    @cont.nestedSortable
      items: 'li'
      helper: 'clone'
      handle: 'i.icon-move'
      tolerance: 'pointer'
      maxLevels: @max_levels
      revert: 250
      tabSize: 25
      opacity: 0.6
      placeholder: 'placeholder'
      disableNesting: 'no-nest'
      toleranceElement: '> div'
      forcePlaceholderSize: true

    @cont.on 'sortupdate', (event, ui) =>
      item = ui.item
      item_id = item.data('id')
      prev_id = item.prev().data('id')
      next_id = item.next().data('id')
      parent_id = item.parent().parent().data('id')

      @rebuild(item_id, parent_id, prev_id, next_id)

  rebuild: (item_id, parent_id, prev_id, next_id) =>
    $.ajax
      type: 'POST'
      dataType: 'script'
      url: @url
      data:
        id: item_id
        parent_id: parent_id
        prev_id: prev_id
        next_id: next_id

      beforeSend: (xhr) ->
        $('.sortable_tree i.handle').hide()

      success: (data, status, xhr) ->
        $('.sortable_tree i.handle').show()

      error: (xhr, status, error) ->
        console.log error

$.fn.sortableTree = ->
  @each ->
    $el = $(this)
    $el.data('sortableTree') or $el.data('sortableTree', new SortableTree($el))

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ab_admin-0.3.6 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.5 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.4 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.3 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.2 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.1 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.3.0 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.2.3 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.2.2 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.2.1 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.2.0 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.1.2 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.1.1 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee
ab_admin-0.1.0 app/assets/javascripts/ab_admin/components/sortable_tree.js.coffee