3 function HistoryPerspective(options) {
4 var old_callback = options.callback || function() {};
6 options.callback = function() {
9 // first time page is rendered
10 $('#make-diff-button').click(function() {
14 $('#tag-changeset-button').click(function() {
18 $('#doc-revert-button').click(function() {
19 self.revertDocumentToVersion();
22 $('#open-preview-button').click(function(event) {
23 var selected = $('#changes-list .entry.selected');
25 if (selected.length != 1) {
26 window.alert("Wybierz dokładnie *jedną* wersję.");
30 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
31 window.open($(this).attr('data-basehref') + "?revision=" + version);
33 event.preventDefault();
36 $('#changes-list .entry').live('click', function(){
39 var selected_count = $("#changes-list .entry.selected").length;
41 if ($this.hasClass('selected')) {
42 $this.removeClass('selected');
46 if (selected_count < 2) {
47 $this.addClass('selected');
52 $('#history-view-editor .toolbar button').attr('disabled', 'disabled').
53 filter('*[data-enabled-when~=' + selected_count + '], *[data-enabled-when~=*]').
54 attr('disabled', null);
57 $('#changes-list span.tag').live('click', function(event){
61 old_callback.call(this);
64 $.wiki.Perspective.call(this, options);
67 HistoryPerspective.prototype = new $.wiki.Perspective();
69 HistoryPerspective.prototype.freezeState = function(){
73 HistoryPerspective.prototype.onEnter = function(success, failure){
74 $.wiki.Perspective.prototype.onEnter.call(this);
77 message: 'Odświeżanie historii...'
80 function _finalize(s){
93 function _failure(doc, message){
94 $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
98 function _success(doc, data){
99 $('#history-view .message-box').hide();
100 var changes_list = $('#changes-list');
101 var $stub = $('#history-view .row-stub');
102 changes_list.html('');
104 var tags = $('select#id_addtag-tag option');
106 $.each(data, function(){
108 container: changes_list,
112 tag: function(value) {
113 return tags.filter("*[value='"+value+"']").text();
115 // description: function(value) {
116 // return value.replace('\n', ');
125 return this.doc.fetchHistory({
131 HistoryPerspective.prototype.showTagForm = function(){
132 var selected = $('#changes-list .entry.selected');
134 if (selected.length != 1) {
135 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
139 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
140 $.wiki.showDialog('#add_tag_dialog', {'revision': version});
143 HistoryPerspective.prototype.makeDiff = function() {
144 var changelist = $('#changes-list');
145 var selected = $('.entry.selected', changelist);
147 if (selected.length != 2) {
148 window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania.");
153 message: 'Wczytywanie porównania...'
156 var rev_from = $("*[data-stub-value='version']", selected[1]).text();
157 var rev_to = $("*[data-stub-value='version']", selected[0]).text();
159 return this.doc.fetchDiff({
162 success: function(doc, data){
163 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
165 $(result.view).html(data);
166 $.wiki.switchToTab(result.tab);
169 failure: function(doc){
175 HistoryPerspective.prototype.revertDocumentToVersion = function(){
176 var selected = $('#changes-list .entry.selected');
178 if (selected.length != 1) {
179 window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
183 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
184 this.doc.revertToVersion({'revision': version});
187 $.wiki.HistoryPerspective = HistoryPerspective;