From 4311ae2f0c7af4e249ff2ba77c717d9ec6ce64cb Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 21 Mar 2012 11:32:39 -0400 Subject: [PATCH] custom org tree : admin ui Signed-off-by: Bill Erickson --- .../conify/global/actor/org_unit_custom_tree.js | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) 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()); } -- 2.11.0