fix weird selection after delete
[fnpeditor.git] / src / editor / views / dialog / dialog.js
index bad349d..0e45dd7 100644 (file)
@@ -2,7 +2,8 @@ define(function(require) {
 
     'use strict';
 
 
     'use strict';
 
-    var _ = require('libs/underscore'),
+    var $ = require('libs/jquery'),
+        _ = require('libs/underscore'),
         Backbone = require('libs/backbone'),
         dialogTemplate = require('libs/text!./dialog.html'),
         fieldTemplates = {};
         Backbone = require('libs/backbone'),
         dialogTemplate = require('libs/text!./dialog.html'),
         fieldTemplates = {};
@@ -27,7 +28,8 @@ define(function(require) {
         show: function() {
             this.setElement(this.template(_.extend({
                 executeButtonText: null,
         show: function() {
             this.setElement(this.template(_.extend({
                 executeButtonText: null,
-                cancelButtonText: null
+                cancelButtonText: null,
+                cssClass: ''
             }, this.options)));
 
             var body = this.$('.modal-body');
             }, this.options)));
 
             var body = this.$('.modal-body');
@@ -36,9 +38,21 @@ define(function(require) {
                 if(!template) {
                     throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
                 }
                 if(!template) {
                     throw new Error('Field type {type} not recognized.'.replace('{type}', field.type));
                 }
-                body.append(
-                    _.template(template)(_.extend({description: '', initialValue: ''}, field))
-                );
+                var widget = $(_.template(template)(_.extend({description: '', initialValue: ''}, field)));
+
+                body.append(widget);
+
+                if(_.isFunction(field.prePasteHandler) && field.type === 'input') { // TODO: extract this out to widget specific impl.
+                    widget.find('input').on('paste', function(e) {
+                        var clipboardData = e.originalEvent.clipboardData;
+                        if(!clipboardData || !clipboardData.getData) {
+                            return;
+                        }
+                        e.preventDefault();
+                        var text = clipboardData.getData('text/plain').replace(/\r?\n|\r/g, ' ');
+                        $(e.target).val(field.prePasteHandler(text));
+                    });
+                }
             });
 
             if(this.options.text) {
             });
 
             if(this.options.text) {
@@ -56,7 +70,10 @@ define(function(require) {
 
             (this.options.fields || []).forEach(function(field) {
                 var widget = view.$('[name=' + field.name +']');
 
             (this.options.fields || []).forEach(function(field) {
                 var widget = view.$('[name=' + field.name +']');
-                formData[field.name] = widget.val();
+                var widget_type = widget.attr('type');
+                if (!(widget_type == 'checkbox' || widget_type == 'radio') || widget.is(':checked')) {
+                    formData[field.name] = widget.val();
+                }
             });
 
             this.trigger('execute', {
             });
 
             this.trigger('execute', {
@@ -83,6 +100,10 @@ define(function(require) {
             this.$('.btn, button').toggleClass('disabled', !toggle);
             this.$('textarea').attr('disabled', !toggle);
             this.actionsDisabled = !toggle;
             this.$('.btn, button').toggleClass('disabled', !toggle);
             this.$('textarea').attr('disabled', !toggle);
             this.actionsDisabled = !toggle;
+        },
+        setContentView: function(view) {
+            var body = this.$('.modal-body');
+            body.append(view);
         }
     });
 
         }
     });