Sha256: 253e155a450cf17a2e6bd90e599efb5b40cb645c7bf4b4dad1878d7248323358

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

class @TheSortableTree
  max_levels  = 3
  rebuild_url = '/'

  init: ->
    $('ol.sortable').nestedSortable
      disableNesting: 'no-nest'
      forcePlaceholderSize: true
      handle: 'i.handle'
      helper: 'clone'
      items:  'li'
      maxLevels: @max_levels
      opacity: .6
      placeholder: 'placeholder'
      revert: 250
      tabSize: 25
      tolerance: 'pointer'
      toleranceElement: '> div'

    $('ol.sortable').sortable
      update: (event, ui) =>
        parent_id = ui.item.parent().parent().attr('id')
        item_id   = ui.item.attr('id')
        prev_id   = ui.item.prev().attr('id')
        next_id   = ui.item.next().attr('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:        @rebuild_url
      data:
        id:        item_id
        parent_id: parent_id
        prev_id:   prev_id
        next_id:   next_id

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

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

      error: (xhr, status, error) ->
        alert error

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
the_sortable_tree-1.9.4 app/assets/javascripts/sortable/base.js.coffee