1 define(['./saveDialog'], function(saveDialog) {
5 return function(sandbox) {
7 var doc = sandbox.getBootstrappedData().document;
8 var document_id = sandbox.getBootstrappedData().document_id;
9 var document_version = sandbox.getBootstrappedData().version;
10 var history = sandbox.getBootstrappedData().history;
15 xmlns="http://nowoczesnapolska.org.pl/sst#"\n\
16 xmlns:xlink="http://www.w3.org/1999/xlink"\n\
17 xmlns:dc="http://purl.org/dc/elements/1.1/"\n\
18 xmlns:dcterms="http://purl.org/dc/terms/"\n\
22 <div class="p"></div>\n\
27 function readCookie(name) {
28 var nameEQ = escape(name) + "=";
29 var ca = document.cookie.split(';');
30 for (var i = 0; i < ca.length; i++) {
32 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
33 if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
40 beforeSend: function(xhr, settings) {
41 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
42 xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));
47 var reloadHistory = function() {
50 url: '/' + gettext('editor') + '/' + document_id + '/history',
51 success: function(data) {
53 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
60 sandbox.publish('ready');
62 getDocument: function() {
65 commitDocument: function(newDocument, reason) {
67 sandbox.publish('documentChanged', doc, reason);
69 saveDocument: function() {
71 var dialog = saveDialog.create();
72 dialog.on('save', function(event) {
73 sandbox.publish('savingStarted');
74 dialog.toggleButtons(false);
77 url: '/' + gettext('editor') + '/' + document_id,
78 data: JSON.stringify({document:doc, description: event.data.description}),
81 sandbox.publish('savingEnded', 'success');
84 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
88 dialog.on('cancel', function() {
94 getHistory: function() {
97 fetchDiff: function(ver1, ver2) {
100 url: '/' + gettext('editor') + '/' + document_id + '/diff',
101 data: {from: ver1, to: ver2},
102 success: function(data) {
103 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
107 restoreVersion: function(options) {
108 if(options.version && options.description) {
109 sandbox.publish('restoringStarted', {version: options.version});
113 url: '/' + gettext('editor') + '/' + document_id + '/revert',
114 data: JSON.stringify(options),
115 success: function(data) {
117 document_version = data.version;
119 sandbox.publish('documentReverted', data);
124 getDocumentId: function() {
127 getDocumentVersion: function() {
128 return document_version;