custom org tree : admin ui
authorBill Erickson <berick@esilibrary.com>
Wed, 21 Mar 2012 15:32:39 +0000 (11:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 21 Mar 2012 18:19:37 +0000 (14:19 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js

index 96e004a..0817f8b 100644 (file)
@@ -141,11 +141,18 @@ function applyChanges() {
 function applyChanges2() {
     ctNodes = [];
     var newCtNodes = [];
+    var nodeList = [];
     var sorder = 0;
     var prevTn;
 
-    // extract the tree structure creating new aoucnt's as we go
-    function traverseAndCreate(pnode, node) {
+    function flatten(node) {
+        nodeList.push(node);
+        dojo.forEach(node.getChildren(), flatten);
+    }
+    flatten(magicTree.rootNode);
+
+    // travers the node, creating new aoucnt's as we go
+    function traverseAndCreate(node) {
         var item = node.item;
 
         var tn = new fieldmapper.aouctn();
@@ -153,6 +160,8 @@ function applyChanges2() {
         tn.org_unit(item.id[0])
         console.log("Traversing node for org unit " + tn.org_unit());
 
+        var pnode = node.getParent();
+
         if (pnode) {
             // find the newly created parent node and extract the ID 
             var ptn = ctNodes.filter(function(n) {
@@ -171,16 +180,16 @@ function applyChanges2() {
                 var newTn = objs[0];
                 ctNodes.push(newTn);
                 prevTn = newTn;
-                dojo.forEach(node.getChildren(), 
-                    function(child) {
-                        traverseAndCreate(node, child)
-                    }
-                );
+
+                if (nodeList.length == 0) {
+                    // all done
+                } else {
+                    traverseAndCreate(nodeList.shift());
+                }
             }
         });
     }
-
-    traverseAndCreate(null, magicTree.rootNode);
+    traverseAndCreate(nodeList.shift());
 }