Distutils installation script.
[redakcja.git] / platforma / static / js / wiki / history.js
1 (function($){
2
3     function fetchDiff(success, failed){
4         var changelist = $('#changes-list');
5         var rev_a = $("input[name='rev_from']:checked", changelist);
6         var rev_b = $("input[name='rev_to']:checked", changelist);
7         
8         if (rev_a.length != 1 || rev_b.length != 1) {
9             window.alert("Musisz zaznaczyć dwie wersje do porównania.");
10             failed();
11         }
12         
13         if (rev_a.val() == rev_b.val()) {
14             window.alert("Musisz zaznaczyć dwie różne wersje do porównania.");
15             failed();
16         }
17         
18         $.blockUI({
19             message: 'Wczytywanie porównania...'
20         });
21         
22         $.ajax({
23             url: document.location.href + '/diff/' + rev_a.val() + '/' + rev_b.val(),
24             dataType: 'html',
25             error: function(){
26                 $.unblockUI();
27                 error();
28             },
29             success: function(data){
30                 var diffview = $('#diff-view');
31                 diffview.html(data);
32                 diffview.show();
33                 $.unblockUI();
34                 success();
35             }
36         });
37     }
38     
39     function HistoryPerspective(doc, callback) {
40                 this.perspective_id = 'HistoryPerspective';
41                 this.doc = doc;
42                 
43         // first time page is rendered
44         $('#make-diff-button').click(fetchDiff);
45                 callback.call(this);
46     };
47     
48     HistoryPerspective.prototype = new $.wiki.Perspective();
49     
50     HistoryPerspective.prototype.freezeState = function(){
51         // must 
52     };
53     
54     HistoryPerspective.prototype.onEnter = function(success, failure) 
55         {               
56                 $.wiki.Perspective.prototype.onEnter.call(this);
57                 
58         $.blockUI({
59             message: 'Odświeżanie historii...'
60         });
61                 
62                 function _finalize(s) {
63                         $.unblockUI();
64                         
65                         if(s) { if(success) success(); }
66                         else { if(failure) failure(); }
67                 }
68         
69         function _failure(doc, message) {
70           $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show();
71                   _finalize(false);    
72         };
73           
74                 function _success(doc, data) {
75                 $('#history-view .message-box').hide();
76             var changes_list = $('#changes-list');
77             var $stub = $('#history-view .row-stub');                
78             changes_list.html('');
79                 
80             $.each(data, function(){
81                 $.wiki.renderStub(changes_list, $stub, this);
82             });
83                         
84                         _finalize(true);                        
85         };
86                 
87                 return this.doc.fetchHistory({success: _success, failure: _failure});
88     };    
89                 
90         $.wiki.HistoryPerspective = HistoryPerspective;
91         
92 })(jQuery);