X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/2936591f2732b8c8f23c4edffc0f1a7b30d4bcf0..e573418502325e80c42523264424fa547a435de5:/modules/data/data.js diff --git a/modules/data/data.js b/modules/data/data.js index 22c77fe..108f2ea 100644 --- a/modules/data/data.js +++ b/modules/data/data.js @@ -6,6 +6,7 @@ return function(sandbox) { var doc = sandbox.getBootstrappedData().document; var document_id = sandbox.getBootstrappedData().document_id; + var document_version = sandbox.getBootstrappedData().version var history = sandbox.getBootstrappedData().history; @@ -92,6 +93,39 @@ return function(sandbox) { }, getHistory: function() { return history; + }, + fetchDiff: function(ver1, ver2) { + $.ajax({ + method: 'get', + url: '/' + gettext('editor') + '/' + document_id + '/diff', + data: {from: ver1, to: ver2}, + success: function(data) { + sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2}) + }, + }); + }, + restoreVersion: function(options) { + if(options.version && options.description) { + sandbox.publish('restoringStarted', {version: options.version}); + $.ajax({ + method: 'post', + dataType: 'json', + url: '/' + gettext('editor') + '/' + document_id + '/revert', + data: JSON.stringify(options), + success: function(data) { + doc = data.document; + document_version = data.version; + reloadHistory(); + sandbox.publish('documentReverted', data); + }, + }); + } + }, + getDocumentId: function() { + return document_id; + }, + getDocumentVersion: function() { + return document_version; } } };