Thomas Bruederli
2014-06-24 a6a66b687f5ebb7ac085b5cc8812b41ae1af65df
Fix updating and re-sorting treelist nodes
1 files modified
10 ■■■■ changed files
program/js/treelist.js 10 ●●●● patch | view | raw | blame | history
program/js/treelist.js
@@ -339,18 +339,22 @@
      if (updates.id || updates.html || updates.children || updates.classes || updates.parent) {
        if (updates.parent && (parent_node = indexbyid[updates.parent])) {
          // remove reference from old parent's child list
          if (old_parent = indexbyid[dom2id(parent_ul.closest('li'))]) {
          if (parent_ul.closest('li').length && (old_parent = indexbyid[dom2id(parent_ul.closest('li'))])) {
            old_parent.children = $.grep(old_parent.children, function(elem, i){ return elem.id != node.id; });
          }
          // append to new parent node
          parent_ul = id2dom(updates.parent).children('ul').first();
          if (!parent_node.children)
            parent_node.children = [];
          parent_node.children.push(node);
        }
        else if (updates.parent !== undefined) {
          parent_ul = container;
        }
        $.extend(node, updates);
        render_node(node, parent_ul, li);
        li = render_node(node, parent_ul, li);
      }
      if (node.id != id) {
@@ -677,7 +681,7 @@
   */
  function dom2id(li)
  {
    var domid = li.attr('id').replace(new RegExp('^' + (p.id_prefix) || '%'), '').replace(/--xsR$/, '');
    var domid = String(li.attr('id')).replace(new RegExp('^' + (p.id_prefix) || '%'), '').replace(/--xsR$/, '');
    return p.id_decode ? p.id_decode(domid) : domid;
  }