Woblink
[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             let ctx = $.wiki.exitContext();
10             super(element);
11             this.ctx = ctx;
12             this.clearForm();
13
14             /* fill out hidden fields */
15             this.$form = $('form', element);
16
17             $("input[name='textrevert-revision']", this.$form).val(options.revision);
18         }
19
20         cancelAction() {
21             $.wiki.enterContext(this.ctx);
22             this.hide();
23         };
24
25         revertAction() {
26             var self = this;
27
28             self.$elem.block({
29                 message: "Przywracanie...",
30                 fadeIn: 0,
31             });
32             $.wiki.blocking = self.$elem;
33
34             try {
35                 CurrentDocument.revertToVersion({
36                     form: self.$form,
37                     success: function(e, msg) {
38                         self.$elem.block({
39                             message: msg,
40                             timeout: 2000,
41                             fadeOut: 0,
42                             onUnblock: function() {
43                                 self.hide();
44                                 $.wiki.enterContext(self.ctx);
45                             }
46                         });
47                     },
48                     'failure': function(e, info) {
49                         console.log("Failure", info);
50                         self.reportErrors(info);
51                         self.$elem.unblock();
52                     }
53                 });
54
55             } catch(e) {
56                 console.log('Exception:', e)
57                 self.$elem.unblock();
58             }
59         }
60     }
61
62     /* make it global */
63     $.wiki.cls.RevertDialog = RevertDialog;
64 })(jQuery);