Woblink
[redakcja.git] / src / redakcja / static / js / wiki / dialog_pubmark.js
1 /*
2  * Dialog for marking document for publishing
3  *
4  */
5 (function($){
6
7     class PubmarkDialog extends $.wiki.cls.GenericDialog {
8         constructor(element, options) {
9             if (!options.revision  && options.revision != 0)
10                 throw "PubmarkDialog needs a revision number.";
11
12             let ctx = $.wiki.exitContext();
13             super(element);
14             this.ctx = ctx;
15             this.clearForm();
16
17             /* fill out hidden fields */
18             this.$form = $('form', element);
19
20             $("input[name='pubmark-id']", this.$form).val(CurrentDocument.id);
21             $("input[name='pubmark-revision']", this.$form).val(options.revision);
22
23         }
24
25         cancelAction() {
26             $.wiki.enterContext(this.ctx);
27             this.hide();
28         }
29
30         saveAction() {
31             var self = this;
32
33             self.$elem.block({
34                 message: "Oznaczanie wersji",
35                 fadeIn: 0,
36             });
37
38             CurrentDocument.pubmark({
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         }
58     }
59
60     /* make it global */
61     $.wiki.cls.PubmarkDialog = PubmarkDialog;
62 })(jQuery);