e3402b178f263971358eddfb5d824407a07f4121
[redakcja.git] / src / redakcja / static / js / wiki / dialog_save.js
1 /*
2  * Dialog for saving document to the server
3  *
4  */
5 (function($) {
6
7     class SaveDialog extends $.wiki.cls.GenericDialog {
8         constructor(element) {
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='textsave-parent_revision']", this.$form).val(CurrentDocument.revision);
17         }
18
19         cancelAction() {
20             $.wiki.enterContext(this.ctx);
21             this.hide();
22         }
23
24         saveAction() {
25             var self = this;
26
27             self.$elem.block({
28                 message: "Zapisywanie... <br/><button id='save-hide'>ukryj</button>",
29                 fadeIn: 0,
30             });
31             $.wiki.blocking = self.$elem;
32
33             try {
34
35                 CurrentDocument.save({
36                     form: self.$form,
37                     success: function(doc, changed, info){
38                         self.$elem.block({
39                             message: info,
40                             timeout: 2000,
41                             fadeOut: 0,
42                             onUnblock: function() {
43                                 self.hide();
44                                 $.wiki.enterContext(self.ctx);
45                             }
46                         });
47                     },
48                     failure: function(doc, info) {
49                         console.log("Failure", info);
50                         self.reportErrors(info);
51                         self.$elem.unblock();
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.SaveDialog = SaveDialog;
63 })(jQuery);