/** * ImageFromUrlDialog.js * * Created by Alexander Yuzhin on 2/18/14 * Copyright (c) 2014 Ascensio System SIA. All rights reserved. * */ define([ 'common/main/lib/component/Window' ], function () { 'use strict'; Common.Views.ImageFromUrlDialog = Common.UI.Window.extend(_.extend({ options: { width: 330, header: false, cls: 'modal-dlg' }, initialize : function(options) { _.extend(this.options, options || {}); this.template = [ '
', '
', '', '
', '
', '
', '' ].join(''); this.options.tpl = _.template(this.template, this.options); Common.UI.Window.prototype.initialize.call(this, this.options); }, render: function() { Common.UI.Window.prototype.render.call(this); var me = this; me.inputUrl = new Common.UI.InputField({ el : $('#id-dlg-url'), allowBlank : false, blankError : me.txtEmpty, style : 'width: 100%;', validateOnBlur: false, validation : function(value) { return (/((^https?)|(^ftp)):\/\/.+/i.test(value)) ? true : me.txtNotUrl; } }); var $window = this.getChild(); $window.find('.btn').on('click', _.bind(this.onBtnClick, this)); $window.find('input').on('keypress', _.bind(this.onKeyPress, this)); }, show: function() { Common.UI.Window.prototype.show.apply(this, arguments); var me = this; _.delay(function(){ me.getChild('input').focus(); },500); }, onKeyPress: function(event) { if (event.keyCode == Common.UI.Keys.RETURN) { this._handleInput('ok'); } }, onBtnClick: function(event) { this._handleInput(event.currentTarget.attributes['result'].value); }, _handleInput: function(state) { if (this.options.handler) { if (state == 'ok') { if (this.inputUrl.checkValidate() !== true) { this.inputUrl.cmpEl.find('input').focus(); return; } } this.options.handler.call(this, state, this.inputUrl.getValue()); } this.close(); }, textUrl : 'Paste an image URL:', cancelButtonText: 'Cancel', okButtonText : 'Ok', txtEmpty : 'This field is required', txtNotUrl : 'This field should be a URL in the format \"http://www.example.com\"' }, Common.Views.ImageFromUrlDialog || {})); });