X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6384a81fa481cb43fddca23742e37761592be66d..e16c2ba3a8b07ced3d7a1c53834985775e9c7c51:/modules/data.js diff --git a/modules/data.js b/modules/data.js index 5a48572..9e18512 100644 --- a/modules/data.js +++ b/modules/data.js @@ -1,9 +1,12 @@ -define(function() { +define(['./data/saveDialog'], function(saveDialog) { + +'use strict'; return function(sandbox) { var doc = sandbox.getBootstrappedData().document; var document_id = sandbox.getBootstrappedData().document_id; + var history = sandbox.getBootstrappedData().history; if(doc === '') { @@ -40,6 +43,17 @@ return function(sandbox) { } }); + var reloadHistory = function() { + $.ajax({ + method: 'get', + url: '/' + gettext('editor') + '/' + document_id + '/history', + success: function(data) { + history = data; + sandbox.publish('historyItemAdded', data.slice(-1)[0]); + }, + }); + } + return { start: function() { sandbox.publish('ready'); @@ -52,15 +66,33 @@ return function(sandbox) { sandbox.publish('documentChanged', doc, reason); }, saveDocument: function() { - sandbox.publish('savingStarted'); - $.ajax({ - method: 'post', - url: '/' + gettext('editor') + '/' + document_id, - data: JSON.stringify({document:doc}), - success: function() {sandbox.publish('savingEnded', 'success');}, - error: function() {sandbox.publish('savingEnded', 'error');} + + var dialog = saveDialog.create(); + dialog.on('save', function(event) { + sandbox.publish('savingStarted'); + dialog.toggleButtons(false); + $.ajax({ + method: 'post', + url: '/' + gettext('editor') + '/' + document_id, + data: JSON.stringify({document:doc, description: event.data.description}), + success: function() { + event.success(); + sandbox.publish('savingEnded', 'success'); + reloadHistory(); + }, + error: function() {event.error(); sandbox.publish('savingEnded', 'error');} + }); + console.log('save'); }); - } + dialog.on('cancel', function() { + }); + dialog.show(); + + + }, + getHistory: function() { + return history; + } } };