Improving test
[fnpeditor.git] / modules / nodeFamilyTree / nodeFamilyTree.js
index 3c78bd1..39ea20f 100644 (file)
@@ -1,83 +1,85 @@
-define([\r
-'libs/jquery-1.9.1.min',\r
-'libs/underscore-min',\r
-'libs/text!./template.html'\r
-], function($, _, templateSrc) {\r
-\r
-'use strict';\r
-\r
-return function(sandbox) {\r
-    \r
-    var template = _.template(templateSrc);\r
-    \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
-                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', view.nodes[target.attr('data-id')])\r
-            });\r
-            this.dom.on('mouseleave', 'a', function(e) {\r
-                var target = $(e.target);\r
-                sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')])\r
-            });\r
-        },\r
-        setNode: function(node) {\r
-            console.log('familyTree sets node');\r
-            var nodes = this.nodes = {};\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().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
-    view.setup();\r
-    \r
-    return {\r
-        start: function() {\r
-            sandbox.publish('ready');\r
-        },\r
-        setNode: function(node) {\r
-            view.setNode(node);\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
-\r
+define([
+'libs/jquery-1.9.1.min',
+'libs/underscore-min',
+'libs/text!./template.html'
+], function($, _, templateSrc) {
+
+'use strict';
+
+return function(sandbox) {
+    
+    var template = _.template(templateSrc);
+    
+    var view = {
+        dom: $('<div>' + template({children: null, parent: null}) + '</div>'),
+        setup: function() {
+            var view = this;
+            this.dom.on('click', 'a', function(e) {
+                var target = $(e.target);
+                sandbox.publish('nodeSelected', view.nodes[target.attr('data-id')]);
+            });
+            
+            this.dom.on('mouseenter', 'a', function(e) {
+                var target = $(e.target);
+                sandbox.publish('nodeEntered', view.nodes[target.attr('data-id')]);
+            });
+            this.dom.on('mouseleave', 'a', function(e) {
+                var target = $(e.target);
+                sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')]);
+            });
+        },
+        setNode: function(node) {
+            console.log('familyTree sets node');
+            var nodes = this.nodes = {};
+            this.currentNode = node;
+            var parentNode = node.parent();
+            var parent;
+            
+            if(parentNode) {
+                parent = {
+                    repr: parentNode.getTag() + (parentNode.getClass() ? ' / ' + parentNode.getClass() : ''),
+                    id: parentNode.getId()
+                };
+                this.nodes[parentNode.getId()] = parentNode;
+            }
+        
+            var children = [];
+            node.children().each(function() {
+                var child = this;
+                children.push({repr: child.getTag() + (child.getClass() ? ' / ' + child.getClass() : ''), id: child.getId()});
+                nodes[child.getId()] = child;
+            });
+            this.dom.empty();
+            this.dom.append($(template({parent: parent, children: children})));
+        },
+        highlightNode: function(canvasNode) {
+            this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode');
+        },
+        dimNode: function(canvasNode) {
+            this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode');
+        }
+    };
+    
+    view.setup();
+    
+    return {
+        start: function() {
+            sandbox.publish('ready');
+        },
+        setNode: function(canvasNode) {
+            if(!canvasNode.isSame(view.currentNode))
+                view.setNode(canvasNode);
+        },
+        getView: function() {
+            return view.dom;
+        },
+        highlightNode: function(canvasNode) {
+            view.highlightNode(canvasNode);
+        },
+        dimNode: function(canvasNode) {
+            view.dimNode(canvasNode);
+        }
+    };
+};
+
 });
\ No newline at end of file