summaryrefslogtreecommitdiff
path: root/program/js/treelist.js
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-06-24 11:59:40 +0200
committerThomas Bruederli <thomas@roundcube.net>2014-06-24 11:59:40 +0200
commita6a66b687f5ebb7ac085b5cc8812b41ae1af65df (patch)
tree9022b816b6f7075e7ffec4a9e2c288da22e07915 /program/js/treelist.js
parent9cc0c12bcd9f610d78e6e2346a283603b105a348 (diff)
Fix updating and re-sorting treelist nodes
Diffstat (limited to 'program/js/treelist.js')
-rw-r--r--program/js/treelist.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/program/js/treelist.js b/program/js/treelist.js
index 631a81a6a..052d77bd5 100644
--- a/program/js/treelist.js
+++ b/program/js/treelist.js
@@ -339,18 +339,22 @@ function rcube_treelist_widget(node, p)
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 rcube_treelist_widget(node, p)
*/
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;
}