Saving document
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 12 Jun 2013 10:34:03 +0000 (12:34 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 12 Jun 2013 10:34:03 +0000 (12:34 +0200)
modules/data.js
modules/documentCanvas/documentCanvas.js
modules/rng/rng.js
views/tabs/tabs.js

index 0fab1a7..5a48572 100644 (file)
@@ -60,14 +60,7 @@ return function(sandbox) {
                 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
index df11ea0..6e1d07c 100644 (file)
@@ -239,8 +239,8 @@ return function(sandbox) {
         },\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
index 6029e7c..8202346 100644 (file)
@@ -13,12 +13,35 @@ return function(sandbox) {
         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
@@ -59,17 +82,7 @@ return function(sandbox) {
 \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
@@ -124,7 +137,8 @@ return function(sandbox) {
             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
index f533785..de776c6 100644 (file)
@@ -67,6 +67,10 @@ define([
             return this.$el;\r
         },\r
         \r
+        getCurrentSlug: function() {\r
+            return this.selectedTab;\r
+        },\r
+        \r
         /* Events */\r
         \r
         _onTabTitleClicked: function(e) {\r