+define([\r
+'libs/text!./templates/restoreDialog.html',\r
+'libs/underscore-min',\r
+'libs/backbone-min',\r
+'libs/jquery-1.9.1.min'\r
+], function(restoreDialogTemplate, _, Backbone, $) {\r
+\r
+ var DialogView = Backbone.View.extend({\r
+ template: _.template(restoreDialogTemplate),\r
+ events: {\r
+ 'click .restore-btn': 'onSave',\r
+ 'click .cancel-btn': 'close',\r
+ 'click .close': 'close'\r
+ },\r
+ initialize: function() {\r
+ _.bindAll(this);\r
+ this.actionsDisabled = false;\r
+ },\r
+ show: function() { \r
+ this.setElement(this.template());\r
+ this.$el.modal({backdrop: 'static'});\r
+ this.$el.modal('show');\r
+\r
+ },\r
+ onSave: function(e) {\r
+ e.preventDefault();\r
+ var view = this;\r
+ this.trigger('restore', {\r
+ data: {description: view.$el.find('textarea').val()},\r
+ success: function() { view.actionsDisabled = false; view.close(); },\r
+ error: function() { view.actionsDisabled = false; view.close(); },\r
+ })\r
+ },\r
+ close: function(e) {\r
+ if(e)\r
+ e.preventDefault();\r
+ if(!this.actionsDisabled) {\r
+ this.$el.modal('hide');\r
+ this.$el.remove();\r
+ }\r
+ },\r
+ toggleButtons: function(toggle) {\r
+ this.$('.btn, button').toggleClass('disabled', !toggle);\r
+ this.$('textarea').attr('disabled', !toggle);\r
+ this.actionsDisabled = !toggle;\r
+ }\r
+ });\r
+\r
+ return {\r
+ create: function() {\r
+ return new DialogView();\r
+ }\r
+ }\r
+\r
+});
\ No newline at end of file