Fix error with revision check during saving.
[redakcja.git] / src / redakcja / static / js / wiki / view_column_diff.js
1 (function($){
2
3     class DiffPerspective extends $.wiki.Perspective {
4         constructor(options) {
5             super(options);
6             this.base_id = options.base_id;
7         }
8
9         static openId(id) {
10             let match = id.match(/R(\d+)-(\d+)/);
11             if (!match)
12                 return [];
13             return this.open(match[1], match[2]);
14         }
15
16         static open(revFrom, revTo) {
17             let tabId = 'R' + revFrom + '-' + revTo;
18             let tab = $(".tabs #DiffPerspective_" + tabId);
19             if (tab.length) {
20                 $.wiki.switchToTab(tab);
21             } else {
22                 let result = $.wiki.newTab(CurrentDocument, ''+revFrom +' → ' + revTo, 'DiffPerspective', tabId);
23                 $.blockUI({
24                     message: 'Wczytywanie porównania...'
25                 });
26
27                 CurrentDocument.fetchDiff({
28                     from: revFrom,
29                     to: revTo,
30                     success: function(doc, data){
31                         $(result.view).html(data);
32                         $.wiki.switchToTab(result.tab);
33                         $.unblockUI();
34                     },
35                     failure: function(doc){
36                         $.unblockUI();
37                     }
38                 });
39                 return result.tab;
40             }
41         }
42
43         destroy() {
44             $.wiki.switchToTab('#HistoryPerspective');
45             $('#' + this.base_id).remove();
46             $('#' + this.perspective_id).remove();
47         }
48     }
49     $.wiki.DiffPerspective = DiffPerspective;
50
51 })(jQuery);