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