X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/072a91dee12e07caf91a693c29fd9f3be5ee177b..e16c2ba3a8b07ced3d7a1c53834985775e9c7c51:/modules/data.js diff --git a/modules/data.js b/modules/data.js index 8debbd3..9e18512 100644 --- a/modules/data.js +++ b/modules/data.js @@ -1,12 +1,16 @@ -rng.modules.data = function(sandbox) { +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 === '') { - doc = '\n\ - '; } @@ -40,6 +43,17 @@ rng.modules.data = 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,13 +66,34 @@ rng.modules.data = function(sandbox) { sandbox.publish('documentChanged', doc, reason); }, saveDocument: function() { - $.ajax({ - method: 'post', - url: '/editor/' + document_id, - data: JSON.stringify({document:doc}) + + 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; } - } +}; -}; \ No newline at end of file +}); \ No newline at end of file