'libs/text!./editingLayout.html',\r
], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate) {\r
\r
+'use strict';\r
+\r
return function(sandbox) {\r
- 'use strict';\r
\r
function addMainTab(title, slug, view) {\r
views.mainTabs.addTab(title, slug, view);\r
}\r
\r
+ 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
+ }\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
+ }\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
\r
views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView());\r
\r
+ views.mainTabs.on('tabSelected', function(event) {\r
+ if(event.prevSlug) {\r
+ synchronizeTab(event.prevSlug);\r
+ }\r
+ });\r
\r
/* Events handling */\r
\r
\r
eventHandlers.sourceEditor = {\r
ready: function() {\r
- addMainTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());\r
+ addMainTab(gettext('Source'), 'sourceEditor', sandbox.getModule('sourceEditor').getView());\r
sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());\r
+ },\r
+ xmlChanged: function() {\r
+ dirty.sourceEditor = true;\r
+ },\r
+ documentSet: function() {\r
+ dirty.sourceEditor = false;\r
}\r
};\r
\r
ready: function() {\r
views.mainLayout.setView('mainView', views.mainTabs.getAsView());\r
\r
- _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) {\r
+ _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory'], function(moduleName) {\r
sandbox.getModule(moduleName).start();\r
});\r
},\r
documentChanged: function(document, reason) {\r
- var slug = (reason === 'visual_edit' ? 'source' : 'visual');\r
- sandbox.getModule(slug+'Editor').setDocument(document);\r
+ var modules = [];\r
+ if(reason === 'source_edit')\r
+ modules = ['documentCanvas', 'metadataEditor'];\r
+ else if (reason === 'edit')\r
+ modules = ['sourceEditor'];\r
+ \r
+ modules.forEach(function(moduleName) {\r
+ sandbox.getModule(moduleName).setDocument(document);\r
+ });\r
},\r
savingStarted: function() {\r
sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
},\r
savingEnded: function(status) {\r
sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
- sandbox.getModule('indicator').clearMessage();\r
+ sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});\r
+ },\r
+ historyItemAdded: function(item) {\r
+ sandbox.getModule('documentHistory').addHistory([item], {animate: true});\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
sandbox.getModule('documentCanvas').setDocument(sandbox.getModule('data').getDocument());\r
views.visualEditing.setView('leftColumn', sandbox.getModule('documentCanvas').getView());\r
},\r
+ documentSet: function() {\r
+ dirty.documentCanvas = false;\r
+ },\r
\r
nodeSelected: function(wlxmlNode) {\r
commands.selectNode(wlxmlNode);\r
},\r
\r
contentChanged: function() {\r
- \r
+ dirty.documentCanvas = true;\r
},\r
\r
nodeHovered: function(wlxmlNode) {\r
\r
eventHandlers.metadataEditor = {\r
ready: function() {\r
- sandbox.getModule('metadataEditor').setMetadata(sandbox.getModule('data').getDocument());\r
+ sandbox.getModule('metadataEditor').setDocument(sandbox.getModule('data').getDocument());\r
views.visualEditingSidebar.addTab({icon: 'info-sign'}, 'metadataEditor', sandbox.getModule('metadataEditor').getView());\r
- }\r
+ },\r
+ metadataChanged: function(metadata) {\r
+ dirty.metadataEditor = true;\r
+ },\r
+ metadataSet: function() {\r
+ dirty.metadataEditor = false;\r
+ },\r
};\r
\r
eventHandlers.nodeFamilyTree = {\r
} \r
}\r
\r
+ eventHandlers.documentHistory = {\r
+ ready: function() {\r
+ sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory());\r
+ addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView());\r
+ }\r
+ }\r
+ \r
/* api */\r
\r
return {\r