X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/95f83648504b6552ff3cbf956f55c6bf5f542a9b..c66ddb7dbe763b261c7dd4a037239a667f60cd95:/modules/data.js diff --git a/modules/data.js b/modules/data.js index 2848454..33c8df6 100644 --- a/modules/data.js +++ b/modules/data.js @@ -6,6 +6,7 @@ return function(sandbox) { var doc = sandbox.getBootstrappedData().document; var document_id = sandbox.getBootstrappedData().document_id; + var history = sandbox.getBootstrappedData().history; if(doc === '') { @@ -42,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'); @@ -59,10 +71,13 @@ return function(sandbox) { method: 'post', url: '/' + gettext('editor') + '/' + document_id, data: JSON.stringify({document:doc}), - success: function() {sandbox.publish('savingEnded', 'success');}, + success: function() {sandbox.publish('savingEnded', 'success'); reloadHistory();}, error: function() {sandbox.publish('savingEnded', 'error');} }); - } + }, + getHistory: function() { + return history; + } } };