X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5ef8e304790026b27417d8ff3c76c18858ba708f..92407309a3a6c4cd125086728910effddd92ab20:/redakcja/static/js/wiki_img/wikiapi.js?ds=sidebyside
diff --git a/redakcja/static/js/wiki_img/wikiapi.js b/redakcja/static/js/wiki_img/wikiapi.js
index 0990e604..377e4f94 100644
--- a/redakcja/static/js/wiki_img/wikiapi.js
+++ b/redakcja/static/js/wiki_img/wikiapi.js
@@ -17,36 +17,23 @@
var vname = arguments[0];
var base_path = "/images";
- if (vname == "ajax_document_text") {
- var path = "/" + arguments[1] + "/text";
+ if (vname == "ajax_document_text")
+ return base_path + "/text/" + arguments[1] + "/";
- if (arguments[2] !== undefined)
- path += "/" + arguments[2];
- return base_path + path;
- }
-
- /*if (vname == "ajax_document_history") {
+ if (vname == "ajax_document_revert") {
+ return base_path + "/revert/" + arguments[1] + '/';
+ }
- return base_path + "/" + arguments[1] + "/history";
+ if (vname == "ajax_document_history") {
+ return base_path + "/history/" + arguments[1] + '/';
}
-*/
- if (vname == "ajax_document_gallery") {
- return base_path + "/" + arguments[1] + "/gallery";
- }
-/*
if (vname == "ajax_document_diff")
- return base_path + "/" + arguments[1] + "/diff";
-
- if (vname == "ajax_document_rev")
- return base_path + "/" + arguments[1] + "/rev";
+ return base_path + "/diff/" + arguments[1] + '/';
- if (vname == "ajax_document_addtag")
- return base_path + "/" + arguments[1] + "/tags";
-
- if (vname == "ajax_publish")
- return base_path + "/" + arguments[1] + "/publish";*/
+ if (vname == "ajax_document_pubmark")
+ return base_path + "/pubmark/" + arguments[1] + '/';
console.log("Couldn't reverse match:", vname);
return "/404.html";
@@ -57,14 +44,23 @@
*/
function WikiDocument(element_id) {
var meta = $('#' + element_id);
- this.id = meta.attr('data-document-name');
+ this.id = meta.attr('data-object-id');
this.revision = $("*[data-key='revision']", meta).text();
- this.commit = $("*[data-key='commit']", meta).text();
this.readonly = !!$("*[data-key='readonly']", meta).text();
- this.galleryLink = $("*[data-key='gallery']", meta).text();
- this.galleryImages = [];
+ var diff = $("*[data-key='diff']", meta).text();
+ if (diff) {
+ diff = diff.split(',');
+ if (diff.length == 2 && diff[0] < diff[1])
+ this.diff = diff;
+ else if (diff.length == 1) {
+ diff = parseInt(diff);
+ if (diff != NaN)
+ this.diff = [diff - 1, diff];
+ }
+ }
+
this.text = null;
this.has_local_changes = false;
this._lock = -1;
@@ -84,18 +80,18 @@
$.ajax({
method: "GET",
url: reverse("ajax_document_text", self.id),
- data: {"commit": self.commit},
+ data: {"revision": self.revision},
dataType: 'json',
success: function(data) {
var changed = false;
- if (self.text === null || self.commit !== data.commit) {
+ if (self.text === null || self.revision !== data.revision) {
self.text = data.text;
if (self.text === '') {
- self.text = '';
+ self.text = '';
}
self.revision = data.revision;
- self.commit = data.commit;
+// self.commit = data.commit;
changed = true;
self.triggerDocumentChanged();
};
@@ -108,6 +104,56 @@
}
});
};
+ /*
+ * Fetch history of this document.
+ *
+ * from - First revision to fetch (default = 0) upto - Last revision to
+ * fetch (default = tip)
+ *
+ */
+ WikiDocument.prototype.fetchHistory = function(params) {
+ /* this doesn't modify anything, so no locks */
+ params = $.extend({}, noops, params);
+ var self = this;
+ $.ajax({
+ method: "GET",
+ url: reverse("ajax_document_history", self.id),
+ dataType: 'json',
+ data: {
+ "from": params['from'],
+ "upto": params['upto']
+ },
+ success: function(data) {
+ params['success'](self, data);
+ },
+ error: function() {
+ params['failure'](self, "Nie udaÅo siÄ wczytaÄ historii dokumentu.");
+ }
+ });
+ };
+ WikiDocument.prototype.fetchDiff = function(params) {
+ /* this doesn't modify anything, so no locks */
+ var self = this;
+ params = $.extend({
+ 'from': self.revision,
+ 'to': self.revision
+ }, noops, params);
+ $.ajax({
+ method: "GET",
+ url: reverse("ajax_document_diff", self.id),
+ dataType: 'html',
+ data: {
+ "from": params['from'],
+ "to": params['to']
+ },
+ success: function(data) {
+ params['success'](self, data);
+ },
+ error: function() {
+ params['failure'](self, "Nie udaÅo siÄ wczytaÄ porównania wersji.");
+ }
+ });
+ };
/*
* Set document's text
@@ -150,7 +196,7 @@
if (data.text) {
self.text = data.text;
self.revision = data.revision;
- self.commit = data.commit;
+// self.commit = data.commit;
changed = true;
self.triggerDocumentChanged();
};
@@ -185,37 +231,50 @@
});
}; /* end of save() */
- WikiDocument.prototype.publish = function(params) {
- params = $.extend({}, noops, params);
- var self = this;
- $.ajax({
- url: reverse("ajax_publish", self.id),
- type: "POST",
- dataType: "json",
- success: function(data) {
- params.success(self, data);
- },
- error: function(xhr) {
- if (xhr.status == 403 || xhr.status == 401) {
- params.failure(self, "Nie masz uprawnieÅ lub nie jesteÅ zalogowany.");
- }
- else {
- try {
- params.failure(self, xhr.responseText);
- }
- catch (e) {
- params.failure(self, "Nie udaÅo siÄ - bÅÄ
d serwera.");
- };
- };
+ WikiDocument.prototype.revertToVersion = function(params) {
+ var self = this;
+ params = $.extend({}, noops, params);
- }
- });
- };
- WikiDocument.prototype.setTag = function(params) {
+ if (params.revision >= this.revision) {
+ params.failure(self, 'ProszÄ wybraÄ rewizjÄ starszÄ
niż aktualna.');
+ return;
+ }
+
+ // Serialize form to dictionary
+ var data = {};
+ $.each(params['form'].serializeArray(), function() {
+ data[this.name] = this.value;
+ });
+
+ $.ajax({
+ url: reverse("ajax_document_revert", self.id),
+ type: "POST",
+ dataType: "json",
+ data: data,
+ success: function(data) {
+ if (data.text) {
+ self.text = data.text;
+ self.revision = data.revision;
+ self.gallery = data.gallery;
+ self.triggerDocumentChanged();
+
+ params.success(self, "UdaÅo siÄ przywróciÄ wersjÄ :)");
+ }
+ else {
+ params.failure(self, "Przywracana wersja identyczna z aktualnÄ
. Anulowano przywracanie.");
+ }
+ },
+ error: function(xhr) {
+ params.failure(self, "Nie udaÅo siÄ przywróciÄ wersji - bÅÄ
d serwera.");
+ }
+ });
+ };
+
+ WikiDocument.prototype.pubmark = function(params) {
params = $.extend({}, noops, params);
var self = this;
var data = {
- "addtag-id": self.id,
+ "pubmark-id": self.id,
};
/* unpack form */
@@ -224,7 +283,7 @@
});
$.ajax({
- url: reverse("ajax_document_addtag", self.id),
+ url: reverse("ajax_document_pubmark", self.id),
type: "POST",
dataType: "json",
data: data,
@@ -251,6 +310,8 @@
});
};
+
+
WikiDocument.prototype.getImageItems = function(tag) {
var self = this;
@@ -263,15 +324,30 @@
}
var a = [];
- $(tag, doc).each(function(i, e) {
+ $('sem[type="'+tag+'"]', doc).each(function(i, e) {
var $e = $(e);
- a.push([
- $e.text(),
- $e.attr('x1'),
- $e.attr('y1'),
- $e.attr('x2'),
- $e.attr('y2')
- ]);
+ var $div = $e.children().first()
+ var value = $e.attr(tag);
+ $e.find('div').each(function(i, div) {
+ var $div = $(div);
+ switch ($div.attr('type')) {
+ case 'rect':
+ a.push([
+ value,
+ $div.attr('x1'),
+ $div.attr('y1'),
+ $div.attr('x2'),
+ $div.attr('y2')
+ ]);
+ break;
+ case 'whole':
+ a.push([
+ value,
+ null, null, null, null
+ ]);
+ break
+ }
+ });
});
return a;
@@ -289,18 +365,25 @@
return null;
}
- $(tag, doc).remove();
+ $('sem[type="'+tag+'"]', doc).remove();
$root = $(doc.firstChild);
$.each(items, function(i, e) {
- var el = $(doc.createElement(tag));
- el.text(e[0]);
- if (e[1] !== null) {
- el.attr('x1', e[1]);
- el.attr('y1', e[2]);
- el.attr('x2', e[3]);
- el.attr('y2', e[4]);
+ var $sem = $(doc.createElement("sem"));
+ $sem.attr('type', tag);
+ $sem.attr(tag, e[0]);
+ $div = $(doc.createElement("div"));
+ if (e[1]) {
+ $div.attr('type', 'rect');
+ $div.attr('x1', e[1]);
+ $div.attr('y1', e[2]);
+ $div.attr('x2', e[3]);
+ $div.attr('y2', e[4]);
+ }
+ else {
+ $div.attr('type', 'whole');
}
- $root.append(el);
+ $sem.append($div);
+ $root.append($sem);
});
self.setText(serializer.serializeToString(doc));
}
@@ -308,3 +391,28 @@
$.wikiapi.WikiDocument = WikiDocument;
})(jQuery);
+
+
+
+// Wykonuje block z zaÅadowanymi kanonicznymi motywami
+function withThemes(code_block, onError)
+{
+ if (typeof withThemes.canon == 'undefined') {
+ $.ajax({
+ url: '/editor/themes',
+ dataType: 'text',
+ success: function(data) {
+ withThemes.canon = data.split('\n');
+ code_block(withThemes.canon);
+ },
+ error: function() {
+ withThemes.canon = null;
+ code_block(withThemes.canon);
+ }
+ })
+ }
+ else {
+ code_block(withThemes.canon);
+ }
+}
+