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);
21 sandbox.getPlugins().forEach(function(plugin) {
22 if(plugin.documentExtension) {
23 wlxmlDocument.registerExtension(plugin.documentExtension);
28 function readCookie(name) {
29 /* global escape, unescape, document */
30 var nameEQ = escape(name) + '=';
31 var ca = document.cookie.split(';');
32 for (var i = 0; i < ca.length; i++) {
34 while (c.charAt(0) === ' ') {
35 c = c.substring(1, c.length);
37 if (c.indexOf(nameEQ) === 0) {
38 return unescape(c.substring(nameEQ.length, c.length));
46 beforeSend: function(xhr, settings) {
47 if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {
48 xhr.setRequestHeader('X-CSRFToken', readCookie('csrftoken'));
53 var reloadHistory = function() {
56 url: '/' + gettext('editor') + '/' + document_id + '/history',
57 success: function(data) {
59 sandbox.publish('historyItemAdded', data.slice(-1)[0]);
66 sandbox.publish('ready');
68 getDocument: function() {
71 saveDocument: function() {
73 var dialog = saveDialog.create();
74 dialog.on('save', function(event) {
75 sandbox.publish('savingStarted');
76 dialog.toggleButtons(false);
79 url: '/' + gettext('editor') + '/' + document_id,
80 data: JSON.stringify({document:wlxmlDocument.toXML(), description: event.data.description}),
83 sandbox.publish('savingEnded', 'success');
86 error: function() {event.error(); sandbox.publish('savingEnded', 'error');}
89 dialog.on('cancel', function() {
95 getHistory: function() {
98 fetchDiff: function(ver1, ver2) {
101 url: '/' + gettext('editor') + '/' + document_id + '/diff',
102 data: {from: ver1, to: ver2},
103 success: function(data) {
104 sandbox.publish('diffFetched', {table: data, ver1: ver1, ver2: ver2});
108 restoreVersion: function(options) {
109 if(options.version && options.description) {
110 sandbox.publish('restoringStarted', {version: options.version});
114 url: '/' + gettext('editor') + '/' + document_id + '/revert',
115 data: JSON.stringify(options),
116 success: function(data) {
117 document_version = data.current_version;
119 wlxmlDocument.loadXML(data.document);
120 sandbox.publish('documentReverted', data);
125 getDocumentId: function() {
128 getDocumentVersion: function() {
129 return document_version;