1a90ccf66b9acad0cdeb3295df9e320caf741242
[redakcja.git] / platforma / static / js / wiki / dialog_addtag.js
1 /*
2  * Dialog for saving document to the server
3  *
4  */
5 (function($){
6
7     function AddTagDialog(element, options){
8         if (!options.revision  && options.revision != 0)
9             throw "AddTagDialog needs a revision number.";
10
11         this.ctx = $.wiki.exitContext();
12         this.clearForm();
13
14         /* fill out hidden fields */
15         this.$form = $('form', element);
16
17         $("input[name='addtag-id']", this.$form).val(CurrentDocument.id);
18         $("input[name='addtag-revision']", this.$form).val(options.revision);
19
20         $.wiki.cls.GenericDialog.call(this, element);
21     };
22
23     AddTagDialog.prototype = $.extend(new $.wiki.cls.GenericDialog(), {
24         cancelAction: function(){
25             $.wiki.enterContext(this.ctx);
26             this.hide();
27         },
28
29         saveAction: function(){
30             var self = this;
31
32             self.$elem.block({
33                 message: "Dodawanie tagu",
34                 fadeIn: 0,
35             });
36
37             CurrentDocument.setTag({
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         }
57     });
58
59     /* make it global */
60     $.wiki.cls.AddTagDialog = AddTagDialog;
61 })(jQuery);