Fix error handling.
[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, 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='textsave-parent_revision']", this.$form).val(CurrentDocument.revision);
18         }
19
20         cancelAction() {
21             $.wiki.enterContext(this.ctx);
22             this.hide();
23         }
24
25         saveAction() {
26             var self = this;
27
28             self.$elem.block({
29                 message: "Zapisywanie... <br/><button id='save-hide'>ukryj</button>",
30                 fadeIn: 0,
31             });
32             $.wiki.blocking = self.$elem;
33
34             try {
35
36                 CurrentDocument.save({
37                     form: self.$form,
38                     success: function(doc, changed, info){
39                         self.$elem.block({
40                             message: info,
41                             timeout: 2000,
42                             fadeOut: 0,
43                             onUnblock: function() {
44                                 self.hide();
45                                 $.wiki.enterContext(self.ctx);
46                             }
47                         });
48                     },
49                     failure: function(doc, info) {
50                         console.log("Failure", info);
51                         self.reportErrors(info);
52                         self.$elem.unblock();
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.SaveDialog = SaveDialog;
64 })(jQuery);