5 ], function(saveDialog, wlxml) {
9 return function(sandbox) {
11 var doc = sandbox.getBootstrappedData().document;
12 var document_id = sandbox.getBootstrappedData().document_id;
13 var document_version = sandbox.getBootstrappedData().version;
14 var history = sandbox.getBootstrappedData().history;
16 var wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document);
20 xmlns="http://nowoczesnapolska.org.pl/sst#"\n\
21 xmlns:xlink="http://www.w3.org/1999/xlink"\n\
22 xmlns:dc="http://purl.org/dc/elements/1.1/"\n\
23 xmlns:dcterms="http://purl.org/dc/terms/"\n\
27 <div class="p"></div>\n\
32 function readCookie(name) {
33 var nameEQ = escape(name) + "=";
34 var ca = document.cookie.split(';');
35 for (var i = 0; i < ca.length; i++) {
37 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
38 if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
45 beforeSend: function(xhr, settings) {
46 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
47 xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));
52 var reloadHistory = function() {
55 url: '/' + gettext('editor') + '/' + document_id + '/history',
56 success: function(data) {
58 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
65 sandbox.publish('ready');
67 getDocument: function() {
70 getDocument2: function() {
73 commitDocument: function(newDocument, reason) {
75 sandbox.publish('documentChanged', doc, reason);
77 saveDocument: function() {
79 var dialog = saveDialog.create();
80 dialog.on('save', function(event) {
81 sandbox.publish('savingStarted');
82 dialog.toggleButtons(false);
85 url: '/' + gettext('editor') + '/' + document_id,
86 data: JSON.stringify({document:doc, description: event.data.description}),
89 sandbox.publish('savingEnded', 'success');
92 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
96 dialog.on('cancel', function() {
102 getHistory: function() {
105 fetchDiff: function(ver1, ver2) {
108 url: '/' + gettext('editor') + '/' + document_id + '/diff',
109 data: {from: ver1, to: ver2},
110 success: function(data) {
111 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
115 restoreVersion: function(options) {
116 if(options.version && options.description) {
117 sandbox.publish('restoringStarted', {version: options.version});
121 url: '/' + gettext('editor') + '/' + document_id + '/revert',
122 data: JSON.stringify(options),
123 success: function(data) {
125 document_version = data.version;
127 sandbox.publish('documentReverted', data);
132 getDocumentId: function() {
135 getDocumentVersion: function() {
136 return document_version;