<commit_before>Dust.sortables = {

  options : 
    disableNesting: "no-nest"
    forcePlaceholderSize: true
    handle: ".handle"
    listType: "ul"
    items: "li"
    maxLevels: 2
    opacity: .6
    placeholder: "placeholder"
    tabSize: 15
    tolerance: "pointer"
    revert: 250
    toleranceElement: "> div"

  init : ()->
    $("ul#tree").nestedSortable @options

    $('.order').bind 'click', ()=>
      @saveItems()
      false

  saveItems : ()->
    list = @buildData()
    url = $('.order').data('url')

    $.post url, list

  buildData: ()->
    return {
      class_name: @className()
      list: @list()
    }

  className: ()->
    $('.order').data('class')

  list: ()->
    children = new Array()
    @itemList = _.map($('.index-item, .sortable-item'), (item, index)->
      data =
        id: $(item).data('id')
        position: index
        parent_id: $(item).parent().parent().data('id')
        children: new Array()
      if data.parent_id
        children.push(data)
        return false
      else
        return data
    )
    @buildChildren(children)
    #console.log @itemList
    #console.log children

    _.compact(@itemList)

  buildChildren: (children)->
    _.each children, (item)=>
      parent = _.findWhere(@itemList, {id: item.parent_id})
      parent.children.push(item)<commit_msg>Add multiple list support. `data-list-class` attr on the `.order` link and a matching class on the #tree ul is required.<commit_after>Dust.sortables = {

  options : 
    disableNesting: "no-nest"
    forcePlaceholderSize: true
    handle: ".handle"
    listType: "ul"
    items: "li"
    maxLevels: 2
    opacity: .6
    placeholder: "placeholder"
    tabSize: 15
    tolerance: "pointer"
    revert: 250
    toleranceElement: "> div"

  init : ()->
    $("ul#tree").nestedSortable @options

    $('.order').bind 'click', ()->
      if $(@).data("list-class")
        Dust.sortables.listClass = "." + $(@).data("list-class") + " .index-item"
      else
        Dust.sortables.listClass = null
      Dust.sortables.saveItems()
      false

  saveItems : ()->
    list = @buildData()
    url = $('.order').data('url')

    $.post url, list

  buildData: ()->
    return {
      class_name: @className()
      list: @list()
    }

  className: ()->
    $('.order').data('class')

  list: ()->
    if @listClass == null
      @listClass = '.index-item, .sortable-item'
    children = new Array()
    @itemList = _.map($(@listClass), (item, index)->
      data =
        id: $(item).data('id')
        position: index
        parent_id: $(item).parent().parent().data('id')
        children: new Array()
      if data.parent_id
        children.push(data)
        return false
      else
        return data
    )
    @buildChildren(children)
    #console.log @itemList
    #console.log children

    _.compact(@itemList)

  buildChildren: (children)->
    _.each children, (item)=>
      parent = _.findWhere(@itemList, {id: item.parent_id})
      parent.children.push(item)
{'fraction_non_alphanumeric': 0.16472157385795266, 'fraction_numerical': 0.004668222740913638, 'mean_word_length': 2.3632286995515694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6810166', 'n_tokens_mistral': 993, 'n_tokens_neox': 949, 'n_words': 215}