X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/49752f4017dbd3a15b36634541010a029a73a744..30cff3b4aec008ee33ddb413f814d5962a5e3727:/src/editor/modules/data/data.js diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 84f0af8..0bce5dc 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -16,11 +16,20 @@ var logger = logging.getLogger('editor.modules.data'), 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 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) { @@ -41,11 +50,14 @@ return function(sandbox) { }); var modificationFlag = true; - wlxmlDocument.on('change', function() { + var handleChange = function() { documentDirty = true; draftDirty = true; modificationFlag = true; - }); + }; + wlxmlDocument.on('change', handleChange); + wlxmlDocument.on('contentSet', handleChange); + if(window.localStorage) { window.setInterval(function() { if(modificationFlag) { @@ -101,7 +113,7 @@ return function(sandbox) { }; var getLocalStorageKey = function() { - return 'draft-id:' + document_id + '-ver:' + document_version; + return 'draft-id:' + document_id + '-ver:' + documentProperties.version; }; @@ -160,7 +172,7 @@ return function(sandbox) { 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); } @@ -172,8 +184,16 @@ return function(sandbox) { 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');} @@ -224,7 +244,13 @@ return function(sandbox) { 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; @@ -235,11 +261,17 @@ return function(sandbox) { }); dialog.show(); }, + dropDraft: function() { + logger.debug('Dropping a draft...'); + wlxmlDocument.loadXML(sandbox.getBootstrappedData().document); + draftDirty = false; + logger.debug('Draft dropped'); + }, getDocumentId: function() { return document_id; }, - getDocumentVersion: function() { - return document_version; + getDocumentProperties: function() { + return documentProperties; } }; };