X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/28866d0f2520b7515f3c06e9b61bcce4f44d53b1..491078616e2129745f300c1f0357f5bac52e801d:/src/redakcja/static/js/wiki/wikiapi.js?ds=sidebyside diff --git a/src/redakcja/static/js/wiki/wikiapi.js b/src/redakcja/static/js/wiki/wikiapi.js index 426c7f62..73642ac0 100644 --- a/src/redakcja/static/js/wiki/wikiapi.js +++ b/src/redakcja/static/js/wiki/wikiapi.js @@ -35,6 +35,9 @@ return base_path + "/history/" + arguments[1] + '/'; } + if (vname == "ajax_document_scans") { + return base_path + "/scans/" + arguments[1] + '/'; + } if (vname == "ajax_document_gallery") { return base_path + "/gallery/" + arguments[1] + '/'; } @@ -117,26 +120,15 @@ this.readonly = !!$("*[data-key='readonly']", meta).text(); this.bookSlug = $("*[data-key='book-slug']", meta).text(); + this.scansLink = $("*[data-key='scans']", meta).text(); this.galleryLink = $("*[data-key='gallery']", meta).text(); this.galleryStart = parseInt($("*[data-key='gallery-start']", meta).text()); this.fullUri = $("*[data-key='full-uri']", meta).text(); - 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.galleryImages = []; this.text = null; + this.saving = false; this.has_local_changes = false; - this.active = true; + this.active = new Date(); this._lock = -1; this._context_lock = -1; this._lock_count = 0; @@ -162,6 +154,7 @@ if (self.text === null || self.revision !== data.revision) { self.text = data.text; + $.wiki.undo.push(data.text); self.revision = data.revision; self.gallery = data.gallery; changed = true; @@ -224,44 +217,83 @@ checkRevision(params) { /* this doesn't modify anything, so no locks */ var self = this; - let active = self.active; - self.active = false; + let active = new Date() - self.active < 30 * 1000; + let saving = self.saving; $.ajax({ method: "GET", url: reverse("ajax_document_rev", self.id), data: { 'a': active, + 'new': 1, }, - dataType: 'text', + dataType: 'json', success: function(data) { if (data == '') { if (params.error) params.error(); } - else if (data != self.revision) - params.outdated(); + else { + let people = $('
'); + data.people.forEach((p) => { + let item = $(''); + item.attr('src', p.gravatar), + item.attr( + 'title', + p.name + ' (' + + (p.active ? 'akt.' : 'nieakt.') + + ' od ' + p.since + ')') + if (p.active) { + item.addClass('active'); + } + people.append(item); + }); + $("#people").html(people); + + if (!saving && (data.rev != self.revision)) { + params.outdated(); + } + } } }); } + refreshImageGallery(params) { + if (this.galleryLink) { + params = $.extend({}, params, { + url: reverse("ajax_document_gallery", this.galleryLink) + }); + } + this.refreshGallery(params); + } + + refreshScansGallery(params) { + if (this.scansLink) { + params = $.extend({}, params, { + url: reverse("ajax_document_scans", this.scansLink) + }); + this.refreshGallery(params); + } else { + // Fallback to image gallery. + this.refreshImageGallery(params) + } + } + /* * Fetch gallery */ refreshGallery(params) { params = $.extend({}, noops, params); var self = this; - if (!self.galleryLink) { - params['failure'](self, 'Brak galerii.'); + if (!params.url) { + params.failure('Brak galerii.'); return; - } + } $.ajax({ method: "GET", - url: reverse("ajax_document_gallery", self.galleryLink), + url: params.url, dataType: 'json', - // data: {}, success: function(data) { - self.galleryImages = data; - params['success'](self, data); + params.success(data); }, error: function(xhr) { switch (xhr.status) { @@ -269,12 +301,11 @@ var msg = 'Galerie dostępne tylko dla zalogowanych użytkowników.'; break; case 404: - var msg = "Nie znaleziono galerii o nazwie: '" + self.galleryLink + "'."; + var msg = "Nie znaleziono galerii."; default: - var msg = "Nie udało się wczytać galerii o nazwie: '" + self.galleryLink + "'."; + var msg = "Nie udało się wczytać galerii."; } - self.galleryImages = []; - params['failure'](self, msg); + params.failure(msg); } }); } @@ -300,12 +331,32 @@ /* * Set document's text */ - setText(text) { + setText(text, silent=false) { if (text == this.text) return; + if (!silent) { + $.wiki.undo.push(text); + } this.text = text; this.has_local_changes = true; } + undo() { + let ctx = $.wiki.exitContext(); + this.setText( + $.wiki.undo.undo(), + true + ); + $.wiki.enterContext(ctx); + } + redo() { + let ctx = $.wiki.exitContext(); + this.setText( + $.wiki.undo.redo(), + true + ); + $.wiki.enterContext(ctx); + } + /* * Save text back to the server */ @@ -326,6 +377,7 @@ data['textsave-text'] = self.text; + self.saving = true; $.ajax({ url: reverse("ajax_document_text", self.id), type: "POST", @@ -343,10 +395,12 @@ changed = true; self.triggerDocumentChanged(); }; + self.saving = false; params['success'](self, changed, ((changed && "Udało się zapisać :)") || "Twoja wersja i serwera jest identyczna")); }, error: function(xhr) { + self.saving = false; if ($('#header').hasClass('saving')) { $('#header').removeClass('saving'); $.blockUI({