5 ], function(saveDialog, wlxml) {
9 return function(sandbox) {
11 var document_id = sandbox.getBootstrappedData().document_id;
12 var document_version = sandbox.getBootstrappedData().version;
13 var history = sandbox.getBootstrappedData().history;
15 var wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document);
18 function readCookie(name) {
19 var nameEQ = escape(name) + "=";
20 var ca = document.cookie.split(';');
21 for (var i = 0; i < ca.length; i++) {
23 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
24 if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
31 beforeSend: function(xhr, settings) {
32 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
33 xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));
38 var reloadHistory = function() {
41 url: '/' + gettext('editor') + '/' + document_id + '/history',
42 success: function(data) {
44 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
51 sandbox.publish('ready');
53 getDocument: function() {
56 commitDocument: function(newDocument, reason) {
58 // sandbox.publish('documentChanged', doc, reason);
60 saveDocument: function() {
62 var dialog = saveDialog.create();
63 dialog.on('save', function(event) {
64 sandbox.publish('savingStarted');
65 dialog.toggleButtons(false);
68 url: '/' + gettext('editor') + '/' + document_id,
69 data: JSON.stringify({document:doc, description: event.data.description}),
72 sandbox.publish('savingEnded', 'success');
75 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
79 dialog.on('cancel', function() {
85 getHistory: function() {
88 fetchDiff: function(ver1, ver2) {
91 url: '/' + gettext('editor') + '/' + document_id + '/diff',
92 data: {from: ver1, to: ver2},
93 success: function(data) {
94 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
98 restoreVersion: function(options) {
99 if(options.version && options.description) {
100 sandbox.publish('restoringStarted', {version: options.version});
104 url: '/' + gettext('editor') + '/' + document_id + '/revert',
105 data: JSON.stringify(options),
106 success: function(data) {
108 document_version = data.version;
110 sandbox.publish('documentReverted', data);
115 getDocumentId: function() {
118 getDocumentVersion: function() {
119 return document_version;