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 $('#changes-list .entry').live('click', function(){
20 if ($this.hasClass('selected'))
21 return $this.removeClass('selected');
23 if ($("#changes-list .entry.selected").length < 2)
24 return $this.addClass('selected');
27 $('#changes-list span.tag').live('click', function(event){
31 old_callback.call(this);
34 $.wiki.Perspective.call(this, options);
37 HistoryPerspective.prototype = new $.wiki.Perspective();
39 HistoryPerspective.prototype.freezeState = function(){
43 HistoryPerspective.prototype.onEnter = function(success, failure){
44 $.wiki.Perspective.prototype.onEnter.call(this);
47 message: 'Odświeżanie historii...'
50 function _finalize(s){
63 function _failure(doc, message){
64 $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
68 function _success(doc, data){
69 $('#history-view .message-box').hide();
70 var changes_list = $('#changes-list');
71 var $stub = $('#history-view .row-stub');
72 changes_list.html('');
74 $.each(data, function(){
75 $.wiki.renderStub(changes_list, $stub, this);
78 $('span[data-version-tag]', changes_list).each(function(){
79 $(this).text($(this).attr('data-version-tag'));
85 return this.doc.fetchHistory({
91 HistoryPerspective.prototype.showTagForm = function(){
92 var selected = $('#changes-list .entry.selected');
94 if (selected.length != 1) {
95 window.alert("Musisz dokładnie jedną wersję do oznaczenia.");
99 var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
100 var dialog = $('#add_tag_dialog');
102 $("input[name='version']", dialog).val(version);
104 console.log($('form', dialog).serialize());
111 HistoryPerspective.prototype.makeDiff = function() {
112 var changelist = $('#changes-list');
113 var selected = $('.entry.selected', changelist);
115 if (selected.length != 2) {
116 window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania.");
121 message: 'Wczytywanie porównania...'
124 var rev_from = $("*[data-stub-value='version']", selected[1]).text();
125 var rev_to = $("*[data-stub-value='version']", selected[0]).text();
127 return this.doc.fetchDiff({
130 success: function(doc, data){
131 var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
133 $(result.view).html(data);
134 $.wiki.switchToTab(result.tab);
137 failure: function(doc){
143 $.wiki.HistoryPerspective = HistoryPerspective;