4d550f9de0efc3c84f2527b09f72e7bc2f3ccf1d
[redakcja.git] / src / redakcja / static / js / wiki / dialog_revert.js
1 /*
2  * Dialog for reverting document on the server
3  *
4  */
5 (function($) {
6
7     function RevertDialog(element, options) {
8         this.ctx = $.wiki.exitContext();
9         this.clearForm();
10
11         /* fill out hidden fields */
12         this.$form = $('form', element);
13
14         $("input[name='textrevert-revision']", this.$form).val(options.revision);
15
16         $.wiki.cls.GenericDialog.call(this, element);
17     };
18
19     RevertDialog.prototype = new $.wiki.cls.GenericDialog();
20
21     RevertDialog.prototype.cancelAction = function() {
22         $.wiki.enterContext(this.ctx);
23         this.hide();
24     };
25
26     RevertDialog.prototype.revertAction = function() {
27             var self = this;
28
29             self.$elem.block({
30                 message: "Przywracanie...",
31                 fadeIn: 0,
32             });
33             $.wiki.blocking = self.$elem;
34
35             try {
36
37                 CurrentDocument.revertToVersion({
38                     form: self.$form,
39                     success: function(e, msg) {
40                         self.$elem.block({
41                             message: msg,
42                             timeout: 2000,
43                             fadeOut: 0,
44                             onUnblock: function() {
45                                 self.hide();
46                                 $.wiki.enterContext(self.ctx);
47                             }
48                         });
49                     },
50                     'failure': function(e, info) {
51                         console.log("Failure", info);
52                         self.reportErrors(info);
53                         self.$elem.unblock();
54                     }
55                 });
56
57             } catch(e) {
58                 console.log('Exception:', e)
59                 self.$elem.unblock();
60             }
61     }; /* end of revert dialog */
62
63     /* make it global */
64     $.wiki.cls.RevertDialog = RevertDialog;
65 })(jQuery);