X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/c0e11a8f6d0d9a4c030aa90fe91f0fc49cd05e0e..c66ddb7dbe763b261c7dd4a037239a667f60cd95:/modules/data.js diff --git a/modules/data.js b/modules/data.js index 5f3fd39..33c8df6 100644 --- a/modules/data.js +++ b/modules/data.js @@ -1,12 +1,16 @@ -rng.modules.data = function(sandbox) { +define(function() { + +'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,19 @@ rng.modules.data = 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}) + data: JSON.stringify({document:doc}), + success: function() {sandbox.publish('savingEnded', 'success'); reloadHistory();}, + error: function() {sandbox.publish('savingEnded', 'error');} }); + }, + getHistory: function() { + return history; } - } +}; -}; \ No newline at end of file +}); \ No newline at end of file