3 class HistoryPerspective extends $.wiki.Perspective {
5 var old_callback = options.callback || function() {};
7 options.callback = function() {
9 if (CurrentDocument.diff) {
10 rev_from = CurrentDocument.diff[0];
11 rev_to = CurrentDocument.diff[1];
15 success: function(doc, data){
16 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
18 $(result.view).html(data);
19 $.wiki.switchToTab(result.tab);
24 // first time page is rendered
25 $('#make-diff-button').click(function() {
29 $('#pubmark-changeset-button').click(function() {
30 self.showPubmarkForm();
33 $('#doc-revert-button').click(function() {
37 $('#open-preview-button').click(function(event) {
38 var selected = $('#changes-list .entry.selected');
40 if (selected.length != 1) {
41 window.alert("Wybierz dokładnie *jedną* wersję.");
45 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
46 window.open($(this).attr('data-basehref') + "?revision=" + version);
48 event.preventDefault();
51 $(document).on('click', '#changes-list .entry', function(){
54 var selected_count = $("#changes-list .entry.selected").length;
56 if ($this.hasClass('selected')) {
57 $this.removeClass('selected');
61 if (selected_count < 2) {
62 $this.addClass('selected');
67 $('#history-view-editor .toolbar button').attr('disabled', 'disabled').
68 filter('*[data-enabled-when~="' + selected_count + '"]').
69 attr('disabled', null);
72 $(document).on('click', '#changes-list span.tag', function(event){
76 $('#history-view').on('scroll', function() {
77 if (self.finished || self.fetching) return;
78 var elemTop = $('#history-view .message-box').offset().top;
79 var windowH = $(window).innerHeight();
80 if (elemTop - 20 < windowH) {
85 old_callback.call(this);
95 onEnter(success, failure) {
102 $('#history-view .message-box').html('Wczytywanie historii…').show();
103 $('#changes-list').html('');
104 this.finished = false;
109 self.finished = true;
110 $('#history-view .message-box').hide()
115 self.fetching = true;
117 function _finalize() {
118 self.fetching = false;
121 function _failure(doc, message){
122 $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
126 function _success(doc, data){
127 //$('#history-view .message-box').hide(); ONLY AFTER LAST!
128 var changes_list = $('#changes-list');
129 var $stub = $('#history-view .row-stub');
135 $.each(data, function(){
137 container: changes_list,
141 self.before = this.version;
142 if (this.version == 1) {
150 this.doc.fetchHistory({
158 var selected = $('#changes-list .entry.selected');
160 if (selected.length != 1) {
161 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
165 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
166 $.wiki.showDialog('#pubmark_dialog', {'revision': version});
170 var changelist = $('#changes-list');
171 var selected = $('.entry.selected', changelist);
173 if (selected.length != 2) {
174 window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania.");
179 message: 'Wczytywanie porównania...'
182 var rev_from = $("*[data-stub-value='version']", selected[1]).text();
183 var rev_to = $("*[data-stub-value='version']", selected[0]).text();
185 return this.doc.fetchDiff({
188 success: function(doc, data){
189 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
190 $(result.view).html(data);
191 $.wiki.switchToTab(result.tab);
194 failure: function(doc){
202 var selected = $('#changes-list .entry.selected');
204 if (selected.length != 1) {
205 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
209 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
210 $.wiki.showDialog('#revert_dialog', {revision: version});
213 $.wiki.HistoryPerspective = HistoryPerspective;