canvas api: Unwraping the whole content of a DocumentTextElement
[fnpeditor.git] / modules / data / saveDialog.js
1 define([
2 'libs/text!./saveDialog.html',
3 'libs/underscore-min',
4 'libs/backbone-min',
5 'libs/jquery-1.9.1.min'
6 ], function(saveDialogTemplate, _, Backbone, $) {
7
8     var DialogView = Backbone.View.extend({
9         template: _.template(saveDialogTemplate),
10         events: {
11             'click .save-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         },
26         onSave: function(e) {
27             e.preventDefault();
28             var view = this;
29             this.trigger('save', {
30                 data: {description: view.$el.find('textarea').val()},
31                 success: function() { view.actionsDisabled = false; view.close(); },
32                 error: function() { view.actionsDisabled = false; view.close(); },
33             });
34         },
35         close: function(e) {
36             if(e)
37                 e.preventDefault();
38             if(!this.actionsDisabled) {
39                 this.$el.modal('hide');
40                 this.$el.remove();
41             }
42         },
43         toggleButtons: function(toggle) {
44             this.$('.btn, button').toggleClass('disabled', !toggle);
45             this.$('textarea').attr('disabled', !toggle);
46             this.actionsDisabled = !toggle;
47         }
48     });
49
50     return {
51         create: function() {
52             return new DialogView();
53         }
54     };
55
56 });