-
- var dirty = {
- sourceEditor: false,
- documentCanvas: false,
- metadataEditor: false,
- };
-
- var synchronizeTab = function(slug) {
- function tabIsDirty(slug) {
- if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor))
- return true;
- if(slug === 'sourceEditor' && dirty.sourceEditor)
- return true;
- return false;
- }
-
- if(tabIsDirty(slug)) {
- var reason, doc;
- if(slug === 'sourceEditor') {
- doc = sandbox.getModule('sourceEditor').getDocument();
- reason = 'source_edit';
- dirty.sourceEditor = false;
- }
- if(slug === 'editor') {
- doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();
- if(dirty.metadataEditor) {
- doc = sandbox.getModule('metadataEditor').attachMetadata(doc);
- }
- reason = 'edit';
- dirty.documentCanvas = dirty.metadataEditor = false;
- }
- sandbox.getModule('data').commitDocument(doc, reason);
- }
- };
-