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();
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) {
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());
}