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