X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/58ba604b1c414d5484d8165c38662050809655aa..6515d67111202f746a1a58c66dcf2261636f2a26:/src/editor/views/dialog/dialog.js diff --git a/src/editor/views/dialog/dialog.js b/src/editor/views/dialog/dialog.js index 04d8f74..7d9f775 100644 --- a/src/editor/views/dialog/dialog.js +++ b/src/editor/views/dialog/dialog.js @@ -1,9 +1,9 @@ define(function(require) { - /* globals gettext */ 'use strict'; - var _ = require('libs/underscore'), + var $ = require('libs/jquery'), + _ = require('libs/underscore'), Backbone = require('libs/backbone'), dialogTemplate = require('libs/text!./dialog.html'), fieldTemplates = {}; @@ -27,8 +27,9 @@ define(function(require) { }, show: function() { this.setElement(this.template(_.extend({ - executeButtonText: gettext('Submit'), - cancelButtonText: gettext('Cancel') + executeButtonText: null, + cancelButtonText: null, + cssClass: '' }, this.options))); var body = this.$('.modal-body'); @@ -37,9 +38,21 @@ define(function(require) { 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) { @@ -84,6 +97,10 @@ define(function(require) { 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); } });