success: function() {sandbox.publish('savingEnded', 'success');},\r
error: function() {sandbox.publish('savingEnded', 'error');}\r
});\r
- },\r
- fakeSave: function() {\r
- sandbox.publish('savingStarted');\r
- window.setTimeout(function() {\r
- sandbox.publish('savingEnded', 'success')\r
- }, 2000);\r
- }\r
- \r
+ } \r
}\r
};\r
\r
},\r
modifyCurrentNode: function(attr, value) {\r
if(view.currentNode) {\r
- view.currentNode.attr('wlxml-'+attr, value);\r
- sandbox.publish('contentEdited');\r
+ view.getNodeElement(view.currentNode).attr('wlxml-'+attr, value);\r
+ sandbox.publish('contentChanged');\r
}\r
},\r
highlightNode: function(wlxmlNode) {\r
views.mainTabs.addTab(title, slug, view);\r
}\r
\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
var dirty = {\r
sourceEditor: false,\r
documentCanvas: false,\r
metadataEditor: false,\r
};\r
\r
+ var synchronizeTab = function(slug) {\r
+ if(tabIsDirty(slug)) {\r
+ if(slug === 'sourceEditor') {\r
+ sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit');\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
+ sandbox.getModule('data').commitDocument(doc, 'edit');\r
+ }\r
+ }\r
+ }\r
+ \r
var commands = {\r
highlightDocumentNode: function(wlxmlNode, origin) {\r
['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) {\r
\r
views.mainTabs.on('tabSelected', function(event) {\r
if(event.prevSlug) {\r
- if(event.prevSlug === 'sourceEditor' && dirty.sourceEditor) {\r
- sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit');\r
- }\r
- if(event.prevSlug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) {\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
- sandbox.getModule('data').commitDocument(doc, 'edit');\r
- }\r
- \r
+ synchronizeTab(event.prevSlug);\r
}\r
});\r
\r
views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
},\r
'cmd.save': function() {\r
- sandbox.getModule('data').fakeSave();\r
+ synchronizeTab(views.mainTabs.getCurrentSlug());\r
+ sandbox.getModule('data').saveDocument();\r
}\r
}\r
\r