Sha256: deaa2b092b4da8cb7aefaf2a8a9ba3109645bc92ac40756b052c841572601f1b

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

@append_children_to_node = (node, html) ->
  html = html.trim()
  item = node.children('.item')

  button = node.children('.item').children('.expand')

  if html.length is 0
    button.addClass 'empty'

  if html.length > 0
    button.removeClass('plus').addClass('minus').html('–')
    item.after html
    

@upload_nodes_children = (node, expand_node_url, tree_type = 'expandable') ->
  node_id = node.attr 'id'

  $.ajax
    type:     'POST'
    dataType: 'html'
    url:      expand_node_url
    data:
      id: node_id
      tree_type: tree_type

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

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

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

$ ->
  for sortable_tree in $('ol.sortable_tree')
    sortable_tree   = $ sortable_tree
    expand_node_url = sortable_tree.data('expand_node_url')
    tree_type       = sortable_tree.data('tree_type')

    pluses = $ '.expand.plus', sortable_tree

    pluses.live 'click', (e) ->
      node = $(@).parent().parent()
      upload_nodes_children(node, expand_node_url, tree_type)

      false

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
the_sortable_tree-2.3.3 app/assets/javascripts/expandable_tree/initializer.js.coffee
the_sortable_tree-2.3.2 app/assets/javascripts/expandable_tree/initializer.js.coffee
the_sortable_tree-2.3.1 app/assets/javascripts/expandable_tree/initializer.js.coffee