Fixing breaking node into two
[fnpeditor.git] / modules / nodeFamilyTree / nodeFamilyTree.js
index bd9c42c..b5cb56e 100644 (file)
@@ -13,34 +13,50 @@ return function(sandbox) {
     var view = {\r
         dom: $('<div>' + template({children: null, parent: null}) + '</div>'),\r
         setup: function() {\r
     var view = {\r
         dom: $('<div>' + template({children: null, parent: null}) + '</div>'),\r
         setup: function() {\r
+            var view = this;\r
             this.dom.on('click', 'a', function(e) {\r
                 var target = $(e.target);\r
             this.dom.on('click', 'a', function(e) {\r
                 var target = $(e.target);\r
-                sandbox.publish('nodeSelected', target.attr('data-id'));\r
+                sandbox.publish('nodeSelected', view.nodes[target.attr('data-id')]);\r
             });\r
             \r
             this.dom.on('mouseenter', 'a', function(e) {\r
                 var target = $(e.target);\r
             });\r
             \r
             this.dom.on('mouseenter', 'a', function(e) {\r
                 var target = $(e.target);\r
-                sandbox.publish('nodeEntered', target.attr('data-id'));\r
+                sandbox.publish('nodeEntered', view.nodes[target.attr('data-id')])\r
             });\r
             this.dom.on('mouseleave', 'a', function(e) {\r
                 var target = $(e.target);\r
             });\r
             this.dom.on('mouseleave', 'a', function(e) {\r
                 var target = $(e.target);\r
-                sandbox.publish('nodeLeft', target.attr('data-id'));\r
+                sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')])\r
             });\r
         },\r
         setNode: function(node) {\r
             });\r
         },\r
         setNode: function(node) {\r
-            var parentClass = node.parent().attr('wlxml-class');\r
-            var parent = node.parent('[wlxml-tag]').length ? {\r
-                repr: node.parent().attr('wlxml-tag') + (parentClass ? ' / ' + parentClass : ''),\r
-                id: node.parent().attr('id')\r
-            } : undefined;\r
+            console.log('familyTree sets node');\r
+            var nodes = this.nodes = {};\r
+            this.currentNode = node;\r
+            var parentNode = node.parent();\r
+            var parent = undefined;\r
+            \r
+            if(parentNode) {\r
+                parent = {\r
+                    repr: parentNode.getTag() + (parentNode.getClass() ? ' / ' + parentNode.getClass() : ''),\r
+                    id: parentNode.getId()\r
+                };\r
+                this.nodes[parentNode.getId()] = parentNode;\r
+            }\r
+        \r
             var children = [];\r
             var children = [];\r
-            node.children('[wlxml-tag]').each(function() {\r
-                var child = $(this);\r
-                var childClass = child.attr('wlxml-class');\r
-                children.push({repr: child.attr('wlxml-tag') + (childClass ? ' / ' + childClass : ''), id: child.attr('id')});\r
+            node.children().each(function() {\r
+                var child = this;\r
+                children.push({repr: child.getTag() + (child.getClass() ? ' / ' + child.getClass() : ''), id: child.getId()});\r
+                nodes[child.getId()] = child;\r
             });\r
             this.dom.empty();\r
             this.dom.append($(template({parent: parent, children: children})));\r
             });\r
             this.dom.empty();\r
             this.dom.append($(template({parent: parent, children: children})));\r
+        },\r
+        highlightNode: function(canvasNode) {\r
+            this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');\r
+        },\r
+        dimNode: function(canvasNode) {\r
+            this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');\r
         }\r
     }\r
     \r
         }\r
     }\r
     \r
@@ -50,17 +66,18 @@ return function(sandbox) {
         start: function() {\r
             sandbox.publish('ready');\r
         },\r
         start: function() {\r
             sandbox.publish('ready');\r
         },\r
-        setNode: function(node) {\r
-            view.setNode(node);\r
+        setNode: function(canvasNode) {\r
+            if(!canvasNode.isSame(view.currentNode))\r
+                view.setNode(canvasNode);\r
         },\r
         getView: function() {\r
             return view.dom;\r
         },\r
         },\r
         getView: function() {\r
             return view.dom;\r
         },\r
-        highlightNode: function(id) {\r
-            view.dom.find('a[data-id="'+id+'"]').addClass('rng-hover');\r
+        highlightNode: function(canvasNode) {\r
+            view.highlightNode(canvasNode);\r
         },\r
         },\r
-        dimNode: function(id) {\r
-            view.dom.find('a[data-id="'+id+'"]').removeClass('rng-hover');\r
+        dimNode: function(canvasNode) {\r
+            view.dimNode(canvasNode);\r
         }\r
     };\r
 };\r
         }\r
     };\r
 };\r