5 'wlxml/extensions/list/list'
7 ], function($, saveDialog, wlxml, listExtension) {
11 return function(sandbox) {
14 var document_id = sandbox.getBootstrappedData().document_id;
15 var document_version = sandbox.getBootstrappedData().version;
16 var history = sandbox.getBootstrappedData().history;
18 var wlxmlDocument = wlxml.WLXMLDocumentFromXML(sandbox.getBootstrappedData().document);
20 wlxmlDocument.registerExtension(listExtension);
23 function readCookie(name) {
24 /* global escape, unescape, document */
25 var nameEQ = escape(name) + '=';
26 var ca = document.cookie.split(';');
27 for (var i = 0; i < ca.length; i++) {
29 while (c.charAt(0) === ' ') {
30 c = c.substring(1, c.length);
32 if (c.indexOf(nameEQ) === 0) {
33 return unescape(c.substring(nameEQ.length, c.length));
41 beforeSend: function(xhr, settings) {
42 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
43 xhr.setRequestHeader('X-CSRFToken', readCookie('csrftoken'));
48 var reloadHistory = function() {
51 url: '/' + gettext('editor') + '/' + document_id + '/history',
52 success: function(data) {
54 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
61 sandbox.publish('ready');
63 getDocument: function() {
66 saveDocument: function() {
68 var dialog = saveDialog.create();
69 dialog.on('save', function(event) {
70 sandbox.publish('savingStarted');
71 dialog.toggleButtons(false);
74 url: '/' + gettext('editor') + '/' + document_id,
75 data: JSON.stringify({document:wlxmlDocument.toXML(), description: event.data.description}),
78 sandbox.publish('savingEnded', 'success');
81 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
84 dialog.on('cancel', function() {
90 getHistory: function() {
93 fetchDiff: function(ver1, ver2) {
96 url: '/' + gettext('editor') + '/' + document_id + '/diff',
97 data: {from: ver1, to: ver2},
98 success: function(data) {
99 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
103 restoreVersion: function(options) {
104 if(options.version && options.description) {
105 sandbox.publish('restoringStarted', {version: options.version});
109 url: '/' + gettext('editor') + '/' + document_id + '/revert',
110 data: JSON.stringify(options),
111 success: function(data) {
112 document_version = data.current_version;
114 wlxmlDocument.loadXML(data.document);
115 sandbox.publish('documentReverted', data);
120 getDocumentId: function() {
123 getDocumentVersion: function() {
124 return document_version;