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