3 function HistoryPerspective(options) {
4 var old_callback = options.callback || function() {};
6 options.callback = function() {
8 if (CurrentDocument.diff) {
9 rev_from = CurrentDocument.diff[0];
10 rev_to = CurrentDocument.diff[1];
14 success: function(doc, data){
15 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
17 $(result.view).html(data);
18 $.wiki.switchToTab(result.tab);
23 // first time page is rendered
24 $('#make-diff-button').click(function() {
28 $('#pubmark-changeset-button').click(function() {
29 self.showPubmarkForm();
32 $('#doc-revert-button').click(function() {
36 $('#open-preview-button').click(function(event) {
37 var selected = $('#changes-list .entry.selected');
39 if (selected.length != 1) {
40 window.alert("Wybierz dokładnie *jedną* wersję.");
44 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
45 window.open($(this).attr('data-basehref') + "?revision=" + version);
47 event.preventDefault();
50 $(document).on('click', '#changes-list .entry', function(){
53 var selected_count = $("#changes-list .entry.selected").length;
55 if ($this.hasClass('selected')) {
56 $this.removeClass('selected');
60 if (selected_count < 2) {
61 $this.addClass('selected');
66 $('#history-view-editor .toolbar button').attr('disabled', 'disabled').
67 filter('*[data-enabled-when~="' + selected_count + '"]').
68 attr('disabled', null);
71 $(document).on('click', '#changes-list span.tag', function(event){
75 $('#history-view').on('scroll', function() {
76 if (self.finished || self.fetching) return;
77 var elemTop = $('#history-view .message-box').offset().top;
78 var windowH = $(window).innerHeight();
79 if (elemTop - 20 < windowH) {
84 old_callback.call(this);
87 $.wiki.Perspective.call(this, options);
90 HistoryPerspective.prototype = new $.wiki.Perspective();
92 HistoryPerspective.prototype.freezeState = function(){
96 HistoryPerspective.prototype.onEnter = function(success, failure){
97 $.wiki.Perspective.prototype.onEnter.call(this);
102 HistoryPerspective.prototype.startFetching = function() {
103 $('#history-view .message-box').html('Wczytywanie historii…').show();
104 $('#changes-list').html('');
105 this.finished = false;
109 HistoryPerspective.prototype.stopFetching = function() {
110 self.finished = true;
111 $('#history-view .message-box').hide()
115 HistoryPerspective.prototype.triggerFetch = function() {
117 self.fetching = true;
119 function _finalize() {
120 self.fetching = false;
123 function _failure(doc, message){
124 $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
128 function _success(doc, data){
129 //$('#history-view .message-box').hide(); ONLY AFTER LAST!
130 var changes_list = $('#changes-list');
131 var $stub = $('#history-view .row-stub');
137 $.each(data, function(){
139 container: changes_list,
143 self.before = this.version;
144 if (this.version == 1) {
152 this.doc.fetchHistory({
160 HistoryPerspective.prototype.showPubmarkForm = function(){
161 var selected = $('#changes-list .entry.selected');
163 if (selected.length != 1) {
164 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
168 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
169 $.wiki.showDialog('#pubmark_dialog', {'revision': version});
172 HistoryPerspective.prototype.makeDiff = function() {
173 var changelist = $('#changes-list');
174 var selected = $('.entry.selected', changelist);
176 if (selected.length != 2) {
177 window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania.");
182 message: 'Wczytywanie porównania...'
185 var rev_from = $("*[data-stub-value='version']", selected[1]).text();
186 var rev_to = $("*[data-stub-value='version']", selected[0]).text();
188 return this.doc.fetchDiff({
191 success: function(doc, data){
192 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
194 $(result.view).html(data);
195 $.wiki.switchToTab(result.tab);
198 failure: function(doc){
204 HistoryPerspective.prototype.revertDialog = function(){
206 var selected = $('#changes-list .entry.selected');
208 if (selected.length != 1) {
209 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
213 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
214 $.wiki.showDialog('#revert_dialog', {revision: version});
217 $.wiki.HistoryPerspective = HistoryPerspective;