linting
[fnpeditor.git] / src / editor / modules / documentHistory / restoreDialog.js
1 define([
2 'libs/text!./templates/restoreDialog.html',
3 'libs/underscore',
4 'libs/backbone'
5 ], function(restoreDialogTemplate, _, Backbone) {
6
7     'use strict';
8
9
10     var DialogView = Backbone.View.extend({
11         template: _.template(restoreDialogTemplate),
12         events: {
13             'click .restore-btn': 'onSave',
14             'click .cancel-btn': 'close',
15             'click .close': 'close'
16         },
17         initialize: function() {
18             _.bindAll(this);
19             this.actionsDisabled = false;
20         },
21         show: function() {
22             this.setElement(this.template());
23             this.$el.modal({backdrop: 'static'});
24             this.$el.modal('show');
25             this.$('textarea').focus();
26         },
27         onSave: function(e) {
28             e.preventDefault();
29             var view = this;
30             this.trigger('restore', {
31                 data: {description: view.$el.find('textarea').val()},
32                 success: function() { view.actionsDisabled = false; view.close(); },
33                 error: function() { view.actionsDisabled = false; view.close(); },
34             });
35         },
36         close: function(e) {
37             if(e) {
38                 e.preventDefault();
39             }
40             if(!this.actionsDisabled) {
41                 this.$el.modal('hide');
42                 this.$el.remove();
43             }
44         },
45         toggleButtons: function(toggle) {
46             this.$('.btn, button').toggleClass('disabled', !toggle);
47             this.$('textarea').attr('disabled', !toggle);
48             this.actionsDisabled = !toggle;
49         }
50     });
51
52     return {
53         create: function() {
54             return new DialogView();
55         }
56     };
57
58 });