Skip to content
This repository
Browse code

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

  • Loading branch information...
commit ae9c2e78a11260cecaf1d2719be5d20497312d6a 1 parent e9c8674
Ingo Schommer authored August 22, 2012

Showing 1 changed file with 13 additions and 10 deletions. Show diff stats Hide diff stats

  1. 23  admin/javascript/LeftAndMain.Tree.js
23  admin/javascript/LeftAndMain.Tree.js
@@ -285,7 +285,8 @@
285 285
 				}
286 286
 
287 287
 				// Replace inner content
288  
-				node.addClass(origClasses).html(newNode.html());
  288
+				var origChildren = node.children('ul').detach();
  289
+				node.addClass(origClasses).html(newNode.html()).append(origChildren);
289 290
 
290 291
 				if (nextNode && nextNode.length) {
291 292
 					this.jstree('move_node', node, nextNode, 'before');
@@ -354,23 +355,25 @@
354 355
 								return;
355 356
 							}
356 357
 
  358
+							var correctStateFn = function(node) {
  359
+								self.jstree('deselect_all');
  360
+								self.jstree('select_node', node);
  361
+								// Similar to jstree's correct_state, but doesn't remove children
  362
+								var hasChildren = (node.children('ul').length > 0);
  363
+								node.toggleClass('jstree-leaf', !hasChildren);
  364
+								if(!hasChildren) node.removeClass('jstree-closed jstree-open');
  365
+							};
  366
+
357 367
 							// Check if node exists, create if necessary
358 368
 							if(node.length) {
359 369
 								self.updateNode(node, nodeData.html, nodeData);
360 370
 								setTimeout(function() {
361  
-									self.jstree('deselect_all');
362  
-									self.jstree('select_node', node);
363  
-									// Manually correct state, which checks for children and
364  
-									// removes toggle arrow (should really be done by jstree internally)
365  
-									self.jstree('correct_state', node);	
  371
+									correctStateFn(node)	;
366 372
 								}, 500);
367 373
 							} else {
368 374
 								includesNewNode = true;
369 375
 								self.createNode(nodeData.html, nodeData, function(newNode) {
370  
-									self.jstree('deselect_all');
371  
-									self.jstree('select_node', newNode);
372  
-									// Manually remove toggle node, see above
373  
-									self.jstree('correct_state', newNode);
  376
+									correctStateFn(newNode);
374 377
 								});
375 378
 							}
376 379
 						});

0 notes on commit ae9c2e7

Please sign in to comment.
Something went wrong with that request. Please try again.