Fixes issue 26898: Tree node is not hidden after being moved to the root
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 24 Jun 2014 12:10:40 +0200
changeset 23863 b3671e259f50
parent 23862 400fab36bc29
child 23864 f3972fa0041b
child 26579 c4b498f42575
Fixes issue 26898: Tree node is not hidden after being moved to the root

If a tree node if moved to the root, the tree cache is invalidated to force redrawing it. Otherwise, the new root node is not shown until the tree is manually refreshed.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-view-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-view-grid.js	Tue Jun 24 10:39:45 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-tree-view-grid.js	Tue Jun 24 12:10:40 2014 +0200
@@ -135,13 +135,19 @@
       // the new callback checks if the node movement has to be reverted
       var newCallback = function (dsResponse, data, dsRequest) {
           var i, node, parentNode;
-          for (i = 0; i < data.length; i++) {
-            node = data[i];
-            if (node.revertMovement) {
-              parentNode = dsRequest.dragTree.find('id', node.parentId);
-              if (parentNode) {
-                // move the node back to its previous index
-                dsRequest.dragTree.move(node, parentNode, node.prevIndex);
+          if (dsRequest.newParentNode && dsRequest.dragTree && dsRequest.newParentNode.nodeId === dsRequest.dragTree.rootValue) {
+            // if the node is being moved to the root, reload the grid to force
+            // displaying properly the node in its new position. see issue https://issues.openbravo.com/view.php?id=26898
+            dsRequest.dragTree.invalidateCache();
+          } else {
+            for (i = 0; i < data.length; i++) {
+              node = data[i];
+              if (node.revertMovement) {
+                parentNode = dsRequest.dragTree.find('id', node.parentId);
+                if (parentNode) {
+                  // move the node back to its previous index
+                  dsRequest.dragTree.move(node, parentNode, node.prevIndex);
+                }
               }
             }
           }