1 define(function(require) {
5 var _ = require('libs/underscore'),
6 Backbone = require('libs/backbone'),
7 saveDialogTemplate = require('libs/text!./saveDialog.html'),
9 fieldTemplates.checkbox = require('libs/text!./templates/checkbox.html');
10 fieldTemplates.select = require('libs/text!./templates/select.html');
11 fieldTemplates.textarea = require('libs/text!./templates/textarea.html');
12 fieldTemplates.input = require('libs/text!./templates/input.html');
16 var DialogView = Backbone.View.extend({
17 template: _.template(saveDialogTemplate),
19 'click .save-btn': 'onSave',
20 'click .cancel-btn': 'close',
21 'click .close': 'close'
23 initialize: function() {
25 this.actionsDisabled = false;
28 this.setElement(this.template());
30 var body = this.$('.modal-body');
31 this.options.fields.forEach(function(field) {
32 var template = fieldTemplates[field.type];
34 throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
37 _.template(template)(_.extend({description: ''}, field))
41 this.$el.modal({backdrop: 'static'});
42 this.$el.modal('show');
43 this.$('textarea').focus();
50 this.options.fields.forEach(function(field) {
51 var widget = view.$('[name=' + field.name +']');
52 formData[field.name] = widget.val();
55 this.trigger('save', {
57 success: function() { view.actionsDisabled = false; view.close(); },
58 error: function() { view.actionsDisabled = false; view.close(); },
65 if(!this.actionsDisabled) {
66 this.$el.modal('hide');
70 toggleButtons: function(toggle) {
71 this.$('.btn, button').toggleClass('disabled', !toggle);
72 this.$('textarea').attr('disabled', !toggle);
73 this.actionsDisabled = !toggle;
78 create: function(config) {
79 return new DialogView(config);