smartxml: minor refactoring to improve clarity
[fnpeditor.git] / src / editor / views / dialog / dialog.js
index 0579464..dff0b6f 100644 (file)
@@ -1,9 +1,9 @@
 define(function(require) {
 
 define(function(require) {
 
-    /* globals gettext */
     '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,8 +27,8 @@ define(function(require) {
         },
         show: function() {
             this.setElement(this.template(_.extend({
         },
         show: function() {
             this.setElement(this.template(_.extend({
-                executeButtonText: gettext('Submit'),
-                cancelButtonText: gettext('Cancel')
+                executeButtonText: null,
+                cancelButtonText: null
             }, this.options)));
 
             var body = this.$('.modal-body');
             }, this.options)));
 
             var body = this.$('.modal-body');
@@ -37,9 +37,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) {
@@ -48,7 +60,7 @@ define(function(require) {
 
             this.$el.modal({backdrop: 'static'});
             this.$el.modal('show');
 
             this.$el.modal({backdrop: 'static'});
             this.$el.modal('show');
-            this.$('textarea').focus();
+            this.$('textarea, input').first().focus();
         },
         onExecute: function(e) {
             e.preventDefault();
         },
         onExecute: function(e) {
             e.preventDefault();