903c0e1cdee3dc2201197621344c12ec4c97c03b
[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         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-parent_revision']", this.$form).val(CurrentDocument.revision);
15
16                 $.wiki.cls.GenericDialog.call(this, element);
17         };
18
19         SaveDialog.prototype = new $.wiki.cls.GenericDialog();
20
21         SaveDialog.prototype.cancelAction = function() {
22                 $.wiki.enterContext(this.ctx);
23                 this.hide();
24         };
25
26         SaveDialog.prototype.saveAction = function() {
27                         var self = this;
28
29                         self.$elem.block({
30                                 message: "Zapisywanie... <br/><button id='save-hide'>ukryj</button>",
31                                 fadeIn: 0,
32                         });
33             $.wiki.blocking = self.$elem;
34
35                         try {
36
37                                 CurrentDocument.save({
38                                         form: self.$form,
39                                         success: function(doc, changed, info){
40                                                 self.$elem.block({
41                                                         message: info,
42                                                         timeout: 2000,
43                                                         fadeOut: 0,
44                                                         onUnblock: function() {
45                                                                 self.hide();
46                                                                 $.wiki.enterContext(self.ctx);
47                                                         }
48                                                 });
49                                         },
50                                         failure: function(doc, info) {
51                                                 console.log("Failure", info);
52                                                 self.reportErrors(info);
53                                                 self.$elem.unblock();
54                                         }
55                                 });
56                         } catch(e) {
57                                 console.log('Exception:', e)
58                                 self.$elem.unblock();
59                         }
60         }; /* end of save dialog */
61
62         /* make it global */
63         $.wiki.cls.SaveDialog = SaveDialog;
64 })(jQuery);