From: Aleksander Ɓukasz Date: Tue, 10 Dec 2013 21:50:23 +0000 (+0100) Subject: integration wip: saving document X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/801f91bc1ea859cc45be1de2cd5cd38901f03005?ds=inline;hp=811645a7d810c562f38edc705affff6822ebbdc9 integration wip: saving document - configurable save form - configurable api urls --- diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 006bf0f..8757389 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -53,7 +53,7 @@ return function(sandbox) { var reloadHistory = function() { $.ajax({ method: 'get', - url: '/' + gettext('editor') + '/' + document_id + '/history', + url: sandbox.getConfig().documentHistoryUrl(document_id), success: function(data) { history = data; sandbox.publish('historyItemAdded', data.slice(-1)[0]); @@ -69,18 +69,34 @@ return function(sandbox) { return wlxmlDocument; }, saveDocument: function() { - - var dialog = saveDialog.create(); + var documentSaveForm = $.extend({ + fields: [], + content_field_name: 'text', + version_field_name: 'version' + }, + sandbox.getConfig().documentSaveForm + ), + dialog = saveDialog.create({fields: documentSaveForm.fields}); + dialog.on('save', function(event) { sandbox.publish('savingStarted'); + + var formData = event.formData; + formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML(); + formData[documentSaveForm.version_field_name] = document_version; + if(sandbox.getConfig().jsonifySentData) { + formData = JSON.stringify(formData); + } + dialog.toggleButtons(false); $.ajax({ method: 'post', - url: '/' + gettext('editor') + '/' + document_id, - data: JSON.stringify({document:wlxmlDocument.toXML(), description: event.data.description}), - success: function() { + url: sandbox.getConfig().documentSaveUrl(document_id), + data: formData, + success: function(data) { event.success(); - sandbox.publish('savingEnded', 'success'); + sandbox.publish('savingEnded', 'success', data.version); + document_version = data.version; reloadHistory(); }, error: function() {event.error(); sandbox.publish('savingEnded', 'error');} @@ -98,7 +114,7 @@ return function(sandbox) { fetchDiff: function(ver1, ver2) { $.ajax({ method: 'get', - url: '/' + gettext('editor') + '/' + document_id + '/diff', + url: '/' + gettext('editor') + '/diff/' + document_id, data: {from: ver1, to: ver2}, success: function(data) { sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2}); diff --git a/src/editor/modules/data/saveDialog.html b/src/editor/modules/data/saveDialog.html index 0846910..d0238e0 100644 --- a/src/editor/modules/data/saveDialog.html +++ b/src/editor/modules/data/saveDialog.html @@ -4,8 +4,6 @@

Zapisz dokument