Obey length limits for wikidata import.
[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             if (options.approved) {
23                 $("input[name='pubmark-publishable']", this.$form).prop('checked');
24             } else {
25                 $("input[name='pubmark-publishable']", this.$form).removeProp('checked');
26             }
27         }
28
29         cancelAction() {
30             $.wiki.enterContext(this.ctx);
31             this.hide();
32         }
33
34         saveAction() {
35             var self = this;
36
37             self.$elem.block({
38                 message: "Oznaczanie wersji",
39                 fadeIn: 0,
40             });
41
42             CurrentDocument.pubmark({
43                 form: self.$form,
44                 success: function(doc, changed, info){
45                     self.$elem.block({
46                         message: info,
47                         timeout: 2000,
48                         fadeOut: 0,
49                         onUnblock: function(){
50                             self.hide();
51                             $.wiki.enterContext(self.ctx);
52                         }
53                     });
54                 },
55                 failure: function(doc, info){
56                     console.log("Failure", info);
57                     self.reportErrors(info);
58                     self.$elem.unblock();
59                 }
60             });
61         }
62     }
63
64     /* make it global */
65     $.wiki.cls.PubmarkDialog = PubmarkDialog;
66 })(jQuery);