+ var dirty = {\r
+ sourceEditor: false,\r
+ documentCanvas: false,\r
+ metadataEditor: false,\r
+ };\r
+ \r
+ var synchronizeTab = function(slug) {\r
+ function tabIsDirty(slug) {\r
+ if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))\r
+ return true;\r
+ if(slug === 'sourceEditor' && dirty.sourceEditor)\r
+ return true;\r
+ return false;\r
+ }\r
+ \r
+ if(tabIsDirty(slug)) {\r
+ var reason, doc;\r
+ if(slug === 'sourceEditor') {\r
+ doc = sandbox.getModule('sourceEditor').getDocument();\r
+ reason = 'source_edit';\r
+ dirty.sourceEditor = false;\r
+ }\r
+ if(slug === 'editor') {\r
+ var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();\r
+ if(dirty.metadataEditor) {\r
+ doc = sandbox.getModule('metadataEditor').attachMetadata(doc);\r
+ }\r
+ reason = 'edit';\r
+ dirty.documentCanvas = dirty.metadataEditor = false;\r
+ }\r
+ sandbox.getModule('data').commitDocument(doc, reason);\r
+ }\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
+ resetDocument: function(document, reason) {\r
+ var modules = [];\r
+ if(reason === 'source_edit')\r
+ modules = ['documentCanvas', 'metadataEditor'];\r
+ else if (reason === 'edit')\r
+ modules = ['sourceEditor'];\r
+ else if (reason === 'revert')\r
+ modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];\r
+ \r
+ modules.forEach(function(moduleName) {\r
+ sandbox.getModule(moduleName).setDocument(document);\r
+ });\r
+ }\r
+ }\r
+ \r
+\r