X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/8e8b2c44fc1345b2b4ae2806f2ef5f2187d760c0..cb900d10b9d0d42b0b6aa035be45dcbaa2f61af6:/src/redakcja/static/js/wiki/view_history.js?ds=inline diff --git a/src/redakcja/static/js/wiki/view_history.js b/src/redakcja/static/js/wiki/view_history.js index 6e306391..e9693b71 100644 --- a/src/redakcja/static/js/wiki/view_history.js +++ b/src/redakcja/static/js/wiki/view_history.js @@ -1,219 +1,215 @@ (function($){ - function HistoryPerspective(options) { - var old_callback = options.callback || function() {}; - - options.callback = function() { - var self = this; - if (CurrentDocument.diff) { - rev_from = CurrentDocument.diff[0]; - rev_to = CurrentDocument.diff[1]; - this.doc.fetchDiff({ - from: rev_from, - to: rev_to, - success: function(doc, data){ - var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); - - $(result.view).html(data); - $.wiki.switchToTab(result.tab); - } - }); - } - - // first time page is rendered - $('#make-diff-button').click(function() { - self.makeDiff(); - }); - - $('#pubmark-changeset-button').click(function() { - self.showPubmarkForm(); - }); - - $('#doc-revert-button').click(function() { - self.revertDialog(); - }); - - $('#open-preview-button').click(function(event) { - var selected = $('#changes-list .entry.selected'); - - if (selected.length != 1) { - window.alert("Wybierz dokładnie *jedną* wersję."); - return; - } - - var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); - window.open($(this).attr('data-basehref') + "?revision=" + version); + class HistoryPerspective extends $.wiki.Perspective { + constructor(options) { + var old_callback = options.callback || function() {}; + + options.callback = function() { + var self = this; + if (CurrentDocument.diff) { + rev_from = CurrentDocument.diff[0]; + rev_to = CurrentDocument.diff[1]; + this.doc.fetchDiff({ + from: rev_from, + to: rev_to, + success: function(doc, data){ + var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); + + $(result.view).html(data); + $.wiki.switchToTab(result.tab); + } + }); + } - event.preventDefault(); - }); + // first time page is rendered + $('#make-diff-button').click(function() { + self.makeDiff(); + }); - $(document).on('click', '#changes-list .entry', function(){ - var $this = $(this); + $('#pubmark-changeset-button').click(function() { + self.showPubmarkForm(); + }); - var selected_count = $("#changes-list .entry.selected").length; + $('#doc-revert-button').click(function() { + self.revertDialog(); + }); - if ($this.hasClass('selected')) { - $this.removeClass('selected'); - selected_count -= 1; - } - else { - if (selected_count < 2) { - $this.addClass('selected'); - selected_count += 1; - }; - }; + $('#open-preview-button').click(function(event) { + var selected = $('#changes-list .entry.selected'); - $('#history-view-editor .toolbar button').attr('disabled', 'disabled'). - filter('*[data-enabled-when~="' + selected_count + '"]'). - attr('disabled', null); - }); + if (selected.length != 1) { + window.alert("Wybierz dokładnie *jedną* wersję."); + return; + } - $(document).on('click', '#changes-list span.tag', function(event){ - return false; - }); + var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); + window.open($(this).attr('data-basehref') + "?revision=" + version); - $('#history-view').on('scroll', function() { - if (self.finished || self.fetching) return; - var elemTop = $('#history-view .message-box').offset().top; - var windowH = $(window).innerHeight(); - if (elemTop - 20 < windowH) { - self.triggerFetch(); - } - }); + event.preventDefault(); + }); - old_callback.call(this); - } + $(document).on('click', '#changes-list .entry', function(){ + var $this = $(this); - $.wiki.Perspective.call(this, options); - }; + var selected_count = $("#changes-list .entry.selected").length; - HistoryPerspective.prototype = new $.wiki.Perspective(); + if ($this.hasClass('selected')) { + $this.removeClass('selected'); + selected_count -= 1; + } + else { + if (selected_count < 2) { + $this.addClass('selected'); + selected_count += 1; + }; + }; + + $('#history-view-editor .toolbar button').attr('disabled', 'disabled'). + filter('*[data-enabled-when~="' + selected_count + '"]'). + attr('disabled', null); + }); - HistoryPerspective.prototype.freezeState = function(){ - // must - }; + $(document).on('click', '#changes-list span.tag', function(event){ + return false; + }); - HistoryPerspective.prototype.onEnter = function(success, failure){ - $.wiki.Perspective.prototype.onEnter.call(this); - this.startFetching(); - success && success(); - }; + $('#history-view').on('scroll', function() { + if (self.finished || self.fetching) return; + var elemTop = $('#history-view .message-box').offset().top; + var windowH = $(window).innerHeight(); + if (elemTop - 20 < windowH) { + self.triggerFetch(); + } + }); - HistoryPerspective.prototype.startFetching = function() { - $('#history-view .message-box').html('Wczytywanie historii…').show(); - $('#changes-list').html(''); - this.finished = false; - this.befored = ''; - this.triggerFetch(); - }; - HistoryPerspective.prototype.stopFetching = function() { - self.finished = true; - $('#history-view .message-box').hide() - }; + old_callback.call(this); + } + super(options); + } - HistoryPerspective.prototype.triggerFetch = function() { - var self = this; - self.fetching = true; + freezeState() { + // must + } - function _finalize() { - self.fetching = false; + onEnter(success, failure) { + super.onEnter(); + this.startFetching(); + success && success(); } - function _failure(doc, message){ - $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); - _finalize(); - }; + startFetching() { + $('#history-view .message-box').html('Wczytywanie historii…').show(); + $('#changes-list').html(''); + this.finished = false; + this.before = ''; + this.triggerFetch(); + } + stopFetching() { + self.finished = true; + $('#history-view .message-box').hide() + } - function _success(doc, data){ - //$('#history-view .message-box').hide(); ONLY AFTER LAST! - var changes_list = $('#changes-list'); - var $stub = $('#history-view .row-stub'); + triggerFetch() { + var self = this; + self.fetching = true; - if (!data.length) { - self.stopFetching(); + function _finalize() { + self.fetching = false; } - $.each(data, function(){ - $.wiki.renderStub({ - container: changes_list, - stub: $stub, - data: this, - }); - self.before = this.version; - if (this.version == 1) { - self.stopFetching(); - } - }); + function _failure(doc, message){ + $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); + _finalize(); + }; - _finalize(); - }; + function _success(doc, data){ + //$('#history-view .message-box').hide(); ONLY AFTER LAST! + var changes_list = $('#changes-list'); + var $stub = $('#history-view .row-stub'); - this.doc.fetchHistory({ - success: _success, - failure: _failure, - before: this.before, - }); - } + if (!data.length) { + self.stopFetching(); + } + $.each(data, function(){ + $.wiki.renderStub({ + container: changes_list, + stub: $stub, + data: this, + }); + self.before = this.version; + if (this.version == 1) { + self.stopFetching(); + } + }); - HistoryPerspective.prototype.showPubmarkForm = function(){ - var selected = $('#changes-list .entry.selected'); + _finalize(); + }; - if (selected.length != 1) { - window.alert("Musisz zaznaczyć dokładnie jedną wersję."); - return; + this.doc.fetchHistory({ + success: _success, + failure: _failure, + before: this.before, + }); } - var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); - $.wiki.showDialog('#pubmark_dialog', {'revision': version}); - }; + showPubmarkForm() { + var selected = $('#changes-list .entry.selected'); - HistoryPerspective.prototype.makeDiff = function() { - var changelist = $('#changes-list'); - var selected = $('.entry.selected', changelist); + if (selected.length != 1) { + window.alert("Musisz zaznaczyć dokładnie jedną wersję."); + return; + } - if (selected.length != 2) { - window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania."); - return; + var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); + $.wiki.showDialog('#pubmark_dialog', {'revision': version}); } - $.blockUI({ - message: 'Wczytywanie porównania...' - }); - - var rev_from = $("*[data-stub-value='version']", selected[1]).text(); - var rev_to = $("*[data-stub-value='version']", selected[0]).text(); - - return this.doc.fetchDiff({ - from: rev_from, - to: rev_to, - success: function(doc, data){ - var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); - - $(result.view).html(data); - $.wiki.switchToTab(result.tab); - $.unblockUI(); - }, - failure: function(doc){ - $.unblockUI(); + makeDiff() { + var changelist = $('#changes-list'); + var selected = $('.entry.selected', changelist); + + if (selected.length != 2) { + window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania."); + return; } - }); - }; - HistoryPerspective.prototype.revertDialog = function(){ - var self = this; - var selected = $('#changes-list .entry.selected'); + $.blockUI({ + message: 'Wczytywanie porównania...' + }); - if (selected.length != 1) { - window.alert("Musisz zaznaczyć dokładnie jedną wersję."); - return; + var rev_from = $("*[data-stub-value='version']", selected[1]).text(); + var rev_to = $("*[data-stub-value='version']", selected[0]).text(); + + return this.doc.fetchDiff({ + from: rev_from, + to: rev_to, + success: function(doc, data){ + var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective'); + $(result.view).html(data); + $.wiki.switchToTab(result.tab); + $.unblockUI(); + }, + failure: function(doc){ + $.unblockUI(); + } + }); } - var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); - $.wiki.showDialog('#revert_dialog', {revision: version}); - }; + revertDialog() { + var self = this; + var selected = $('#changes-list .entry.selected'); + + if (selected.length != 1) { + window.alert("Musisz zaznaczyć dokładnie jedną wersję."); + return; + } + var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); + $.wiki.showDialog('#revert_dialog', {revision: version}); + } + } $.wiki.HistoryPerspective = HistoryPerspective; })(jQuery);