Saving document
[fnpeditor.git] / modules / nodeFamilyTree / nodeFamilyTree.js
index 68ab8f0..7415b2d 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 = this;\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
-                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
-                sandbox.publish('nodeLeft', target.attr('data-id'));\r
+                sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')])\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.tag + (parentNode.klass ? ' / ' + parentNode.klass : ''),\r
+                    id: parentNode.id\r
+                };\r
+                this.nodes[parentNode.id] = parentNode;\r
+            }\r
+        \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.tag + (child.klass ? ' / ' + child.klass : ''), id: child.id});\r
+                nodes[child.id] = child;\r
             });\r
             this.dom.empty();\r
             this.dom.append($(template({parent: parent, children: children})));\r
+        },\r
+        highlightNode: function(wlxmlNode) {\r
+            this.dom.find('a[data-id="'+wlxmlNode.id+'"]').addClass('rng-common-hoveredNode');\r
+        },\r
+        dimNode: function(wlxmlNode) {\r
+            this.dom.find('a[data-id="'+wlxmlNode.id+'"]').removeClass('rng-common-hoveredNode');\r
         }\r
     }\r
     \r
@@ -50,11 +66,18 @@ return function(sandbox) {
         start: function() {\r
             sandbox.publish('ready');\r
         },\r
-        setNode: function(node) {\r
-            view.setNode(node);\r
+        setNode: function(wlxmlNode) {\r
+            if(!wlxmlNode.is(view.currentNode))\r
+                view.setNode(wlxmlNode);\r
         },\r
         getView: function() {\r
             return view.dom;\r
+        },\r
+        highlightNode: function(wlxmlNode) {\r
+            view.highlightNode(wlxmlNode);\r
+        },\r
+        dimNode: function(wlxmlNode) {\r
+            view.dimNode(wlxmlNode);\r
         }\r
     };\r
 };\r