Building js & css for editor with r.js/lessc via grunt tasks
[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             this.$('textarea').focus();\r
24 \r
25         },\r
26         onSave: function(e) {\r
27             e.preventDefault();\r
28             var view = this;\r
29             this.trigger('save', {\r
30                 data: {description: view.$el.find('textarea').val()},\r
31                 success: function() { view.actionsDisabled = false; view.close(); },\r
32                 error: function() { view.actionsDisabled = false; view.close(); },\r
33             })\r
34         },\r
35         close: function(e) {\r
36             if(e)\r
37                 e.preventDefault();\r
38             if(!this.actionsDisabled) {\r
39                 this.$el.modal('hide');\r
40                 this.$el.remove();\r
41             }\r
42         },\r
43         toggleButtons: function(toggle) {\r
44             this.$('.btn, button').toggleClass('disabled', !toggle);\r
45             this.$('textarea').attr('disabled', !toggle);\r
46             this.actionsDisabled = !toggle;\r
47         }\r
48     });\r
49 \r
50     return {\r
51         create: function() {\r
52             return new DialogView();\r
53         }\r
54     }\r
55 \r
56 });