Refactor
[fnpeditor.git] / modules / rng / rng.js
index c42b985..6f65c19 100644 (file)
@@ -13,6 +13,29 @@ return function(sandbox) {
         views.mainTabs.addTab(title, slug, view);\r
     }\r
     \r
+    var commands = {\r
+        highlightDocumentNode: function(wlxmlNode, origin) {\r
+            ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+                if(!origin || moduleName != origin)\r
+                    sandbox.getModule(moduleName).highlightNode(wlxmlNode)\r
+            });\r
+        },\r
+        dimDocumentNode: function(wlxmlNode, origin) {\r
+            ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
+                if(!origin || moduleName != origin)\r
+                    sandbox.getModule(moduleName).dimNode(wlxmlNode)\r
+            });\r
+        },\r
+        selectNode: function(wlxmlNode, origin) {\r
+            sandbox.getModule('documentCanvas').selectNode(wlxmlNode);\r
+            sandbox.getModule('nodePane').setNode(wlxmlNode);\r
+            sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);\r
+            sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);\r
+            \r
+        }\r
+    }\r
+    \r
+\r
     var views = {\r
         mainLayout: new layout.Layout(mainLayoutTemplate),\r
         mainTabs: (new tabs.View()).render(),\r
@@ -27,8 +50,6 @@ return function(sandbox) {
     sandbox.getDOM().append(views.mainLayout.getAsView());\r
     \r
     views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());\r
-    \r
-    \r
 \r
     \r
     /* Events handling */\r
@@ -64,13 +85,6 @@ return function(sandbox) {
         }\r
     }\r
     \r
-    eventHandlers.rng2 = {\r
-        ready: function() {\r
-           addMainTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());\r
-           \r
-        }\r
-    }\r
-    \r
     eventHandlers.mainBar = {\r
         ready: function() {\r
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
@@ -94,27 +108,20 @@ return function(sandbox) {
             views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());\r
         },\r
         \r
-        nodeSelected: function(node) {\r
-            sandbox.getModule('nodePane').setNode(node);\r
-            sandbox.getModule('nodeFamilyTree').setNode(node);\r
-            sandbox.getModule('nodeBreadCrumbs').setNode(node);\r
+        nodeSelected: function(wlxmlNode) {\r
+            commands.selectNode(wlxmlNode);\r
         },\r
         \r
         contentChanged: function() {\r
         \r
         },\r
         \r
-        nodeHovered: function(node) {\r
-            sandbox.getModule('documentCanvas').highlightNode(node.attr('id'));\r
-            sandbox.getModule('nodeFamilyTree').highlightNode(node.attr('id'));\r
-            sandbox.getModule('nodeBreadCrumbs').highlightNode(node.attr('id'));\r
-            \r
+        nodeHovered: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode);\r
         },\r
         \r
-        nodeBlured: function(node) {\r
-            sandbox.getModule('documentCanvas').dimNode(node.attr('id'));\r
-            sandbox.getModule('nodeFamilyTree').dimNode(node.attr('id'));\r
-            sandbox.getModule('nodeBreadCrumbs').dimNode(node.attr('id'));\r
+        nodeBlured: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode);\r
         }\r
     };\r
 \r
@@ -139,14 +146,14 @@ return function(sandbox) {
         ready: function() {\r
             views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView());\r
         },\r
-        nodeEntered: function(id) {\r
-            sandbox.getModule('documentCanvas').highlightNode(id);\r
+        nodeEntered: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree');\r
         },\r
-        nodeLeft: function(id) {\r
-            sandbox.getModule('documentCanvas').dimNode(id);\r
+        nodeLeft: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree');\r
         },\r
-        nodeSelected: function(id) {\r
-            sandbox.getModule('documentCanvas').selectNode(id);\r
+        nodeSelected: function(wlxmlNode) {\r
+            commands.selectNode(wlxmlNode);\r
         }\r
     };\r
     \r
@@ -170,14 +177,14 @@ return function(sandbox) {
         ready: function() {\r
             views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView());\r
         },\r
-        nodeHighlighted: function(id) {\r
-            sandbox.getModule('documentCanvas').highlightNode(id);\r
+        nodeHighlighted: function(wlxmlNode) {\r
+            commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs');\r
         },\r
-        nodeDimmed: function(id) {\r
-            sandbox.getModule('documentCanvas').dimNode(id);\r
+        nodeDimmed: function(wlxmlNode) {\r
+            commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs');\r
         },\r
-        nodeSelected: function(id) {\r
-            sandbox.getModule('documentCanvas').selectNode(id);\r
+        nodeSelected: function(wlxmlNode) {\r
+            commands.selectNode(wlxmlNode);\r
         }        \r
     }\r
     \r