Some modernizations.
[redakcja.git] / src / redakcja / static / js / wiki / dialog_revert.js
1 /*
2  * Dialog for reverting document on the server
3  *
4  */
5 (function($) {
6
7     class RevertDialog extends $.wiki.cls.GenericDialog {
8         constructor(element, options) {
9             super(element);
10             this.ctx = $.wiki.exitContext();
11             this.clearForm();
12
13             /* fill out hidden fields */
14             this.$form = $('form', element);
15
16             $("input[name='textrevert-revision']", this.$form).val(options.revision);
17         }
18
19         cancelAction() {
20             $.wiki.enterContext(this.ctx);
21             this.hide();
22         };
23
24         revertAction() {
25             var self = this;
26
27             self.$elem.block({
28                 message: "Przywracanie...",
29                 fadeIn: 0,
30             });
31             $.wiki.blocking = self.$elem;
32
33             try {
34                 CurrentDocument.revertToVersion({
35                     form: self.$form,
36                     success: function(e, msg) {
37                         self.$elem.block({
38                             message: msg,
39                             timeout: 2000,
40                             fadeOut: 0,
41                             onUnblock: function() {
42                                 self.hide();
43                                 $.wiki.enterContext(self.ctx);
44                             }
45                         });
46                     },
47                     'failure': function(e, info) {
48                         console.log("Failure", info);
49                         self.reportErrors(info);
50                         self.$elem.unblock();
51                     }
52                 });
53
54             } catch(e) {
55                 console.log('Exception:', e)
56                 self.$elem.unblock();
57             }
58         }
59     }
60
61     /* make it global */
62     $.wiki.cls.RevertDialog = RevertDialog;
63 })(jQuery);