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 $('#changes-list .entry').live('click', 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 + '], *[data-enabled-when~=*]').
68 attr('disabled', null);
71 $('#changes-list span.tag').live('click', function(event){
75 old_callback.call(this);
78 $.wiki.Perspective.call(this, options);
81 HistoryPerspective.prototype = new $.wiki.Perspective();
83 HistoryPerspective.prototype.freezeState = function(){
87 HistoryPerspective.prototype.onEnter = function(success, failure){
88 $.wiki.Perspective.prototype.onEnter.call(this);
91 message: 'Odświeżanie historii...'
94 function _finalize(s){
107 function _failure(doc, message){
108 $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
112 function _success(doc, data){
113 $('#history-view .message-box').hide();
114 var changes_list = $('#changes-list');
115 var $stub = $('#history-view .row-stub');
116 changes_list.html('');
118 var tags = $('select#id_addtag-tag option');
120 $.each(data, function(){
122 container: changes_list,
126 // tag: function(value) {
127 // return tags.filter("*[value='"+value+"']").text();
129 // description: function(value) {
130 // return value.replace('\n', ');
139 return this.doc.fetchHistory({
145 HistoryPerspective.prototype.showPubmarkForm = function(){
146 var selected = $('#changes-list .entry.selected');
148 if (selected.length != 1) {
149 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
153 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
154 $.wiki.showDialog('#pubmark_dialog', {'revision': version});
157 HistoryPerspective.prototype.makeDiff = function() {
158 var changelist = $('#changes-list');
159 var selected = $('.entry.selected', changelist);
161 if (selected.length != 2) {
162 window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania.");
167 message: 'Wczytywanie porównania...'
170 var rev_from = $("*[data-stub-value='version']", selected[1]).text();
171 var rev_to = $("*[data-stub-value='version']", selected[0]).text();
173 return this.doc.fetchDiff({
176 success: function(doc, data){
177 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
179 $(result.view).html(data);
180 $.wiki.switchToTab(result.tab);
183 failure: function(doc){
189 HistoryPerspective.prototype.revertDialog = function(){
191 var selected = $('#changes-list .entry.selected');
193 if (selected.length != 1) {
194 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
198 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
199 $.wiki.showDialog('#revert_dialog', {revision: version});
202 $.wiki.HistoryPerspective = HistoryPerspective;