aa9258d57e81df9a21b8baaac8b29e2b72aa8792
[redakcja.git] / redakcja / static / js / wiki / dialog_save.js
1 /*
2  * Dialog for saving document to the server
3  *
4  */
5 (function($) {
6
7         function SaveDialog(element) {
8                 this.ctx = $.wiki.exitContext();
9                 this.clearForm();
10
11                 /* fill out hidden fields */
12                 this.$form = $('form', element);
13
14                 $("input[name='textsave-id']", this.$form).val(CurrentDocument.id);
15                 $("input[name='textsave-parent_revision']", this.$form).val(CurrentDocument.revision);
16
17                 $.wiki.cls.GenericDialog.call(this, element);
18         };
19
20         SaveDialog.prototype = new $.wiki.cls.GenericDialog();
21
22         SaveDialog.prototype.cancelAction = function() {
23                 $.wiki.enterContext(this.ctx);
24                 this.hide();
25         };
26
27         SaveDialog.prototype.saveAction = function() {
28                         var self = this;
29
30                         self.$elem.block({
31                                 message: "Zapisywanie... <br/><button id='save-hide'>ukryj</button>",
32                                 fadeIn: 0,
33                         });
34             $.wiki.blocking = self.$elem;
35
36                         try {
37
38                                 CurrentDocument.save({
39                                         form: self.$form,
40                                         success: function(doc, changed, info){
41                                                 self.$elem.block({
42                                                         message: info,
43                                                         timeout: 2000,
44                                                         fadeOut: 0,
45                                                         onUnblock: function() {
46                                                                 self.hide();
47                                                                 $.wiki.enterContext(self.ctx);
48                                                         }
49                                                 });
50                                         },
51                                         failure: function(doc, info) {
52                                                 console.log("Failure", info);
53                                                 self.reportErrors(info);
54                                                 self.$elem.unblock();
55                                         }
56                                 });
57                         } catch(e) {
58                                 console.log('Exception:', e)
59                                 self.$elem.unblock();
60                         }
61         }; /* end of save dialog */
62
63         /* make it global */
64         $.wiki.cls.SaveDialog = SaveDialog;
65 })(jQuery);