From 6384a81fa481cb43fddca23742e37761592be66d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 12 Jun 2013 12:34:03 +0200 Subject: [PATCH 1/1] Saving document --- modules/data.js | 9 +----- modules/documentCanvas/documentCanvas.js | 4 +-- modules/rng/rng.js | 38 ++++++++++++++++-------- views/tabs/tabs.js | 4 +++ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/modules/data.js b/modules/data.js index 0fab1a7..5a48572 100644 --- a/modules/data.js +++ b/modules/data.js @@ -60,14 +60,7 @@ return function(sandbox) { success: function() {sandbox.publish('savingEnded', 'success');}, error: function() {sandbox.publish('savingEnded', 'error');} }); - }, - fakeSave: function() { - sandbox.publish('savingStarted'); - window.setTimeout(function() { - sandbox.publish('savingEnded', 'success') - }, 2000); - } - + } } }; diff --git a/modules/documentCanvas/documentCanvas.js b/modules/documentCanvas/documentCanvas.js index df11ea0..6e1d07c 100644 --- a/modules/documentCanvas/documentCanvas.js +++ b/modules/documentCanvas/documentCanvas.js @@ -239,8 +239,8 @@ return function(sandbox) { }, modifyCurrentNode: function(attr, value) { if(view.currentNode) { - view.currentNode.attr('wlxml-'+attr, value); - sandbox.publish('contentEdited'); + view.getNodeElement(view.currentNode).attr('wlxml-'+attr, value); + sandbox.publish('contentChanged'); } }, highlightNode: function(wlxmlNode) { diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 6029e7c..8202346 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -13,12 +13,35 @@ return function(sandbox) { views.mainTabs.addTab(title, slug, view); } + function tabIsDirty(slug) { + if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) + return true; + if(slug === 'sourceEditor' && dirty.sourceEditor) + return true; + return false; + } + var dirty = { sourceEditor: false, documentCanvas: false, metadataEditor: false, }; + var synchronizeTab = function(slug) { + if(tabIsDirty(slug)) { + if(slug === 'sourceEditor') { + sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit'); + } + if(slug === 'editor') { + var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument(); + if(dirty.metadataEditor) { + doc = sandbox.getModule('metadataEditor').attachMetadata(doc); + } + sandbox.getModule('data').commitDocument(doc, 'edit'); + } + } + } + var commands = { highlightDocumentNode: function(wlxmlNode, origin) { ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) { @@ -59,17 +82,7 @@ return function(sandbox) { views.mainTabs.on('tabSelected', function(event) { if(event.prevSlug) { - if(event.prevSlug === 'sourceEditor' && dirty.sourceEditor) { - sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit'); - } - if(event.prevSlug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) { - var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument(); - if(dirty.metadataEditor) { - doc = sandbox.getModule('metadataEditor').attachMetadata(doc); - } - sandbox.getModule('data').commitDocument(doc, 'edit'); - } - + synchronizeTab(event.prevSlug); } }); @@ -124,7 +137,8 @@ return function(sandbox) { views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView()); }, 'cmd.save': function() { - sandbox.getModule('data').fakeSave(); + synchronizeTab(views.mainTabs.getCurrentSlug()); + sandbox.getModule('data').saveDocument(); } } diff --git a/views/tabs/tabs.js b/views/tabs/tabs.js index f533785..de776c6 100644 --- a/views/tabs/tabs.js +++ b/views/tabs/tabs.js @@ -67,6 +67,10 @@ define([ return this.$el; }, + getCurrentSlug: function() { + return this.selectedTab; + }, + /* Events */ _onTabTitleClicked: function(e) { -- 2.20.1