X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/02a98d2af6f1fabf567b575c5f2d818688af1594..24c1d259ba4af084959d70c6a1f355d0a57f1191:/platforma/static/js/wiki/history_view.js diff --git a/platforma/static/js/wiki/history_view.js b/platforma/static/js/wiki/history_view.js index 0f35ca3b..2ee4558e 100644 --- a/platforma/static/js/wiki/history_view.js +++ b/platforma/static/js/wiki/history_view.js @@ -1,58 +1,37 @@ (function($){ - - function fetchDiff(success, failed){ - var changelist = $('#changes-list'); - - var selected = $('div.selected', changelist); - - if (selected.length != 2) { - window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania."); - if(failed) failed(); - } - - $.blockUI({ - message: 'Wczytywanie porównania...' - }); - - $.ajax({ - method: "GET", - url: document.location.href + '/diff/' + rev_a.val() + '/' + rev_b.val(), - dataType: 'html', - error: function(){ - $.unblockUI(); - if(failed) failed('Nie udało się wczytać porównania z serwera.'); - }, - success: function(data){ - var diffview = $('#diff-view'); - diffview.html(data); - diffview.show(); - $.unblockUI(); - if(success) success(data); - } - }); - } - function HistoryPerspective(doc, callback) { - this.perspective_id = 'HistoryPerspective'; - this.doc = doc; - - // first time page is rendered - $('#make-diff-button').click(fetchDiff); - - $('#changes-list div').live('click', function() { - var $this = $(this); - if($this.hasClass('selected')) - return $this.removeClass('selected'); - - if($("#changes-list div.selected").length < 2) - return $this.addClass('selected'); - }); + function HistoryPerspective(options) { + var old_callback = options.callback || function() {}; - $('#changes-list span.tag').live('click', function(event) { - return false; - }); + options.callback = function() { + var self = this; + + // first time page is rendered + $('#make-diff-button').click(function() { + self.makeDiff(); + }); + + $('#tag-changeset-button').click(function() { + self.showTagForm(); + }); + + $('#changes-list .entry').live('click', function(){ + var $this = $(this); + if ($this.hasClass('selected')) + return $this.removeClass('selected'); + + if ($("#changes-list .entry.selected").length < 2) + return $this.addClass('selected'); + }); + + $('#changes-list span.tag').live('click', function(event){ + return false; + }); + + old_callback.call(this); + } - callback.call(this); + $.wiki.Perspective.call(this, options); }; HistoryPerspective.prototype = new $.wiki.Perspective(); @@ -61,46 +40,106 @@ // must }; - HistoryPerspective.prototype.onEnter = function(success, failure) - { - $.wiki.Perspective.prototype.onEnter.call(this); - + HistoryPerspective.prototype.onEnter = function(success, failure){ + $.wiki.Perspective.prototype.onEnter.call(this); + $.blockUI({ message: 'Odświeżanie historii...' }); - - function _finalize(s) { - $.unblockUI(); - - if(s) { if(success) success(); } - else { if(failure) failure(); } - } - function _failure(doc, message) { - $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); - _finalize(false); + function _finalize(s){ + $.unblockUI(); + + if (s) { + if (success) + success(); + } + else { + if (failure) + failure(); + } + } + + function _failure(doc, message){ + $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); + _finalize(false); }; - - function _success(doc, data) { - $('#history-view .message-box').hide(); + + function _success(doc, data){ + $('#history-view .message-box').hide(); var changes_list = $('#changes-list'); - var $stub = $('#history-view .row-stub'); + var $stub = $('#history-view .row-stub'); changes_list.html(''); - + $.each(data, function(){ - $.wiki.renderStub(changes_list, $stub, this); + $.wiki.renderStub(changes_list, $stub, this); }); - - $('span[data-version-tag]', changes_list).each(function() { - $(this).text($(this).attr('data-version-tag')); - }); - - _finalize(true); + + $('span[data-version-tag]', changes_list).each(function(){ + $(this).text($(this).attr('data-version-tag')); + }); + + _finalize(true); }; + + return this.doc.fetchHistory({ + success: _success, + failure: _failure + }); + }; + + HistoryPerspective.prototype.showTagForm = function(){ + var selected = $('#changes-list .entry.selected'); + + if (selected.length != 1) { + window.alert("Musisz dokładnie jedną wersję do oznaczenia."); + return; + } - return this.doc.fetchHistory({success: _success, failure: _failure}); - }; + var version = parseInt($("*[data-stub-value='version']", selected[0]).text()); + var dialog = $('#add_tag_dialog'); - $.wiki.HistoryPerspective = HistoryPerspective; + $("input[name='version']", dialog).val(version); + + console.log($('form', dialog).serialize()); + + $.blockUI({ + message: dialog + }); + }; + HistoryPerspective.prototype.makeDiff = function() { + 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; + } + + $.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(); + } + }); + }; + + $.wiki.HistoryPerspective = HistoryPerspective; + })(jQuery);