Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUG Restore tree children after updateNode() (fixes #7761)

  • Loading branch information...
commit ae9c2e78a11260cecaf1d2719be5d20497312d6a 1 parent e9c8674
@chillu chillu authored
Showing with 13 additions and 10 deletions.
  1. +13 −10 admin/javascript/LeftAndMain.Tree.js
View
23 admin/javascript/LeftAndMain.Tree.js
@@ -285,7 +285,8 @@
}
// Replace inner content
- node.addClass(origClasses).html(newNode.html());
+ var origChildren = node.children('ul').detach();
+ node.addClass(origClasses).html(newNode.html()).append(origChildren);
if (nextNode && nextNode.length) {
this.jstree('move_node', node, nextNode, 'before');
@@ -354,23 +355,25 @@
return;
}
+ var correctStateFn = function(node) {
+ self.jstree('deselect_all');
+ self.jstree('select_node', node);
+ // Similar to jstree's correct_state, but doesn't remove children
+ var hasChildren = (node.children('ul').length > 0);
+ node.toggleClass('jstree-leaf', !hasChildren);
+ if(!hasChildren) node.removeClass('jstree-closed jstree-open');
+ };
+
// Check if node exists, create if necessary
if(node.length) {
self.updateNode(node, nodeData.html, nodeData);
setTimeout(function() {
- self.jstree('deselect_all');
- self.jstree('select_node', node);
- // Manually correct state, which checks for children and
- // removes toggle arrow (should really be done by jstree internally)
- self.jstree('correct_state', node);
+ correctStateFn(node) ;
}, 500);
} else {
includesNewNode = true;
self.createNode(nodeData.html, nodeData, function(newNode) {
- self.jstree('deselect_all');
- self.jstree('select_node', newNode);
- // Manually remove toggle node, see above
- self.jstree('correct_state', newNode);
+ correctStateFn(newNode);
});
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.