editor: refactoring the way document properties are kept
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 13:07:02 +0000 (14:07 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 13:07:02 +0000 (14:07 +0100)
src/editor/modules/data/data.js
src/editor/modules/rng/rng.js

index ef1c87d..0bce5dc 100644 (file)
@@ -16,11 +16,20 @@ var logger = logging.getLogger('editor.modules.data'),
 return function(sandbox) {
 
     var document_id = sandbox.getBootstrappedData().document_id;
 return function(sandbox) {
 
     var document_id = sandbox.getBootstrappedData().document_id;
-    var document_version = sandbox.getBootstrappedData().version;
     var history = sandbox.getBootstrappedData().history;
     var documentDirty = false;
     var draftDirty = false;
 
     var history = sandbox.getBootstrappedData().history;
     var documentDirty = false;
     var draftDirty = false;
 
+    var documentProperties = {};
+    var data = sandbox.getBootstrappedData();
+    Object.keys(data)
+        .filter(function(key) {
+            return key !== 'history' && key !== 'document';
+        })
+        .forEach(function(key) {
+            documentProperties[key] = data[key];
+        });
+
     var wlxmlDocument, text;
 
     var loadDocument = function(text) {
     var wlxmlDocument, text;
 
     var loadDocument = function(text) {
@@ -104,7 +113,7 @@ return function(sandbox) {
     };
 
     var getLocalStorageKey = function() {
     };
 
     var getLocalStorageKey = function() {
-        return 'draft-id:' + document_id + '-ver:' + document_version;
+        return 'draft-id:' + document_id + '-ver:' + documentProperties.version;
     };
 
    
     };
 
    
@@ -163,7 +172,7 @@ return function(sandbox) {
 
                 var formData = event.formData;
                 formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML();
 
                 var formData = event.formData;
                 formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML();
-                formData[documentSaveForm.version_field_name] = document_version;
+                formData[documentSaveForm.version_field_name] = documentProperties.version;
                 if(sandbox.getConfig().jsonifySentData) {
                     formData = JSON.stringify(formData);
                 }
                 if(sandbox.getConfig().jsonifySentData) {
                     formData = JSON.stringify(formData);
                 }
@@ -175,8 +184,16 @@ return function(sandbox) {
                     data: formData,
                     success: function(data) {
                         event.success();
                     data: formData,
                     success: function(data) {
                         event.success();
-                        sandbox.publish('savingEnded', 'success', 'remote', data.version);
-                        document_version = data.version;
+                        sandbox.publish('savingEnded', 'success', 'remote', data);
+
+                        Object.keys(data)
+                            .filter(function(key) {
+                                return key !== 'text';
+                            })
+                            .forEach(function(key) {
+                                documentProperties[key] = data[key];
+                            });
+
                         reloadHistory();
                     },
                     error: function() {event.error(); sandbox.publish('savingEnded', 'error', 'remote');}
                         reloadHistory();
                     },
                     error: function() {event.error(); sandbox.publish('savingEnded', 'error', 'remote');}
@@ -227,7 +244,13 @@ return function(sandbox) {
                     url: sandbox.getConfig().documentRestoreUrl(document_id),
                     data: formData,
                     success: function(data) {
                     url: sandbox.getConfig().documentRestoreUrl(document_id),
                     data: formData,
                     success: function(data) {
-                        document_version = data.version;
+                        Object.keys(data)
+                            .filter(function(key) {
+                                return key !== 'document';
+                            })
+                            .forEach(function(key) {
+                                documentProperties = data[key];
+                            });
                         reloadHistory();
                         wlxmlDocument.loadXML(data.document);
                         documentDirty = false;
                         reloadHistory();
                         wlxmlDocument.loadXML(data.document);
                         documentDirty = false;
@@ -247,8 +270,8 @@ return function(sandbox) {
         getDocumentId: function() {
             return document_id;
         },
         getDocumentId: function() {
             return document_id;
         },
-        getDocumentVersion: function() {
-            return document_version;
+        getDocumentProperties: function() {
+            return documentProperties;
         }
     };
 };
         }
     };
 };
index 78145a5..42ab636 100644 (file)
@@ -110,7 +110,7 @@ return function(sandbox) {
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
             sandbox.getModule('indicator').showMessage(msg[what] + '...');
         },
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
             sandbox.getModule('indicator').showMessage(msg[what] + '...');
         },
-        savingEnded: function(status, what, current_version) {
+        savingEnded: function(status, what, data) {
             void(status);
             var msg = {
                 remote: gettext('Document saved'),
             void(status);
             var msg = {
                 remote: gettext('Document saved'),
@@ -119,7 +119,7 @@ return function(sandbox) {
             documentIsDirty = false;
             sandbox.getModule('mainBar').setCommandEnabled('save', true);
             sandbox.getModule('indicator').clearMessage({message: msg[what]});
             documentIsDirty = false;
             sandbox.getModule('mainBar').setCommandEnabled('save', true);
             sandbox.getModule('indicator').clearMessage({message: msg[what]});
-            sandbox.getModule('mainBar').setVersion(current_version);
+            sandbox.getModule('mainBar').setVersion(data.version);
         },
         restoringStarted: function(event) {
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
         },
         restoringStarted: function(event) {
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
@@ -141,7 +141,7 @@ return function(sandbox) {
     
     eventHandlers.mainBar = {
         ready: function() {
     
     eventHandlers.mainBar = {
         ready: function() {
-            sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());
+            sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentProperties().version);
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
         },
         'cmd.save': function() {
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
         },
         'cmd.save': function() {