101 lines
3.3 KiB
JavaScript
101 lines
3.3 KiB
JavaScript
|
/**
|
||
|
* 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 = [
|
||
|
'<div class="box">',
|
||
|
'<div class="input-row">',
|
||
|
'<label>' + this.textUrl + '</label>',
|
||
|
'</div>',
|
||
|
'<div id="id-dlg-url" class="input-row"></div>',
|
||
|
'</div>',
|
||
|
'<div class="footer right">',
|
||
|
'<button class="btn normal dlg-btn primary" result="ok" style="margin-right: 10px;">' + this.okButtonText + '</button>',
|
||
|
'<button class="btn normal dlg-btn" result="cancel">' + this.cancelButtonText + '</button>',
|
||
|
'</div>'
|
||
|
].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 || {}));
|
||
|
});
|