From: Bill Erickson Date: Wed, 21 Mar 2012 15:32:39 +0000 (-0400) Subject: custom org tree : admin ui X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4311ae2f0c7af4e249ff2ba77c717d9ec6ce64cb;p=evergreen%2Fequinox.git custom org tree : admin ui Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js b/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js index 96e004a5fc..0817f8b7a9 100644 --- a/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js +++ b/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js @@ -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()); }