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 history = sandbox.getBootstrappedData().history;
\r
14 xmlns="http://nowoczesnapolska.org.pl/sst#"\n\
\r
15 xmlns:xlink="http://www.w3.org/1999/xlink"\n\
\r
16 xmlns:dc="http://purl.org/dc/elements/1.1/"\n\
\r
17 xmlns:dcterms="http://purl.org/dc/terms/"\n\
\r
21 <div class="p"></div>\n\
\r
26 function readCookie(name) {
\r
27 var nameEQ = escape(name) + "=";
\r
28 var ca = document.cookie.split(';');
\r
29 for (var i = 0; i < ca.length; i++) {
\r
31 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
\r
32 if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
\r
39 beforeSend: function(xhr, settings) {
\r
40 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
\r
41 xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));
\r
46 var reloadHistory = function() {
\r
49 url: '/' + gettext('editor') + '/' + document_id + '/history',
\r
50 success: function(data) {
\r
52 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
\r
59 sandbox.publish('ready');
\r
61 getDocument: function() {
\r
64 commitDocument: function(newDocument, reason) {
\r
66 sandbox.publish('documentChanged', doc, reason);
\r
68 saveDocument: function() {
\r
70 var dialog = saveDialog.create();
\r
71 dialog.on('save', function(event) {
\r
72 sandbox.publish('savingStarted');
\r
73 dialog.toggleButtons(false);
\r
76 url: '/' + gettext('editor') + '/' + document_id,
\r
77 data: JSON.stringify({document:doc, description: event.data.description}),
\r
78 success: function() {
\r
80 sandbox.publish('savingEnded', 'success');
\r
83 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
\r
85 console.log('save');
\r
87 dialog.on('cancel', function() {
\r
93 getHistory: function() {
\r
96 fetchDiff: function(ver1, ver2) {
\r
99 url: '/' + gettext('editor') + '/' + document_id + '/diff',
\r
100 data: {from: ver1, to: ver2},
\r
101 success: function(data) {
\r
102 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2})
\r