Permalink
Browse files

mangling my way around weird recursively generated IDs

  • Loading branch information...
ralphbean committed Feb 28, 2011
1 parent c54c655 commit dd2591daa8f80828f875cdfe44ab0f80bc9cb877
Showing with 14 additions and 17 deletions.
  1. +14 −17 tw2/jit/widgets/ajax.py
View
@@ -33,21 +33,7 @@ def prepare(self):
""" TODO """, attribute=True,
default=JSSymbol(src="""
(function(json) {
- var ch = json.children;
- var getNode = function(nodeName) {
- for(var i=0; i<ch.length; i++) {
- if(ch[i].name == nodeName) return ch[i];
- }
- return false;
- };
json.id = jitwidget.root;
- $jit.Graph.Util.eachAdjacency(
- jitwidget.graph.getNode(jitwidget.root),
- function(elem) {
- var nodeTo = elem.nodeTo, jsonNode = getNode(nodeTo.name);
- if(jsonNode) { jsonNode.id = nodeTo.id; }
- }
- );
})"""))
requestGraph = twc.Param(
@@ -70,12 +56,23 @@ def prepare(self):
onBeforeCompute: (function(){}),
});
- var old = jitwidget.graph.getNode(jitwidget.oldRootToRemove);
+ function hasID(json, id) {
+ if ( json.id == id ) return true;
+
+ for ( var i = 0; i < json.children.length; i++ ) {
+ if ( hasID(json.children[i], id) ) return true;
+ }
+ return false;
+ }
+
+ var old = jitwidget.graph.getNode(jitwidget.root);
if ( !old ) return;
- var subnodes = old.getSubnodes(0);
+ var subnodes = old.getSubnodes(1);
var map = [];
for ( var i = 0; i < subnodes.length; i++ ) {
- map.push(subnodes[i].id);
+ if ( ! hasID(json, subnodes[i].id) ) {
+ map.push(subnodes[i].id);
+ }
}
jitwidget.op.removeNode(map.reverse(), {

0 comments on commit dd2591d

Please sign in to comment.