Require PIL.
[redakcja.git] / platforma / static / js / wiki / save_dialog.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='id']", this.$form).val(CurrentDocument.id);
15                 $("input[name='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...",
32                                 fadeIn: 0,
33                         });
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);