raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
raimund@548:  * Software engineering by Intevation GmbH
raimund@548:  *
raimund@548:  * This file is Free Software under the GNU GPL (v>=3)
raimund@548:  * and comes with ABSOLUTELY NO WARRANTY! Check out
raimund@548:  * the documentation coming with IMIS-Labordaten-Application for details.
raimund@548:  */
raimund@548: 
dustin@892: /**
dustin@892:  * This Widget extends a Panel to create a Textfield
dustin@892:  */
raimund@548: Ext.define('Lada.view.widget.base.TextField', {
raimund@548:     extend: 'Ext.panel.Panel',
raimund@548:     alias: 'widget.tfield',
raimund@548: 
raimund@548:     layout: 'hbox',
raimund@548: 
raimund@548:     border: 0,
raimund@599:     margin: '0, 0, 5, 0',
raimund@548: 
raimund@548:     initComponent: function() {
raimund@548:         this.items = [{
raimund@548:             xtype: 'textfield',
raimund@548:             flex: 1,
raimund@548:             name: this.name,
raimund@548:             msgTarget: 'none',
dustin@659:             maxLength: this.maxLength || 1000,
dustin@659:             enforceMaxLength: this.enforceMaxLength || true,
raimund@548:             fieldLabel: this.fieldLabel,
raimund@548:             labelWidth: this.labelWidth,
raimund@1144:             readOnly: this.readOnly || false,
raimund@548:             listeners: this.listeners
raimund@548:         }, {
raimund@548:             xtype: 'image',
raimund@548:             name: 'warnImg',
raimund@632:             src: 'resources/img/dialog-warning.png',
raimund@632:             width: 14,
raimund@632:             height: 14,
raimund@548:             hidden: true
raimund@548:         }, {
raimund@548:             xtype: 'image',
raimund@548:             name: 'errorImg',
raimund@632:             src: 'resources/img/emblem-important.png',
raimund@632:             width: 14,
raimund@632:             height: 14,
raimund@548:             hidden: true
raimund@548:         }];
raimund@548:         this.callParent(arguments);
raimund@1144:         if (this.regex) {
raimund@1144:             Ext.apply(this.down('textfield'), {regex: this.regex});
raimund@1144:         }
raimund@1144:         if (this.allowBlank === false) {
raimund@1144:             Ext.apply(this.down('textfield'), {allowBlank: this.allowBlank});
raimund@1144:         }
raimund@548:     },
raimund@548: 
raimund@548:     showWarnings: function(warnings) {
raimund@548:         var img = this.down('image[name=warnImg]');
raimund@548:         Ext.create('Ext.tip.ToolTip', {
raimund@548:             target: img.getEl(),
raimund@548:             html: warnings
raimund@548:         });
raimund@548:         img.show();
raimund@548:         this.down('textfield').invalidCls = 'x-lada-warning';
raimund@548:         this.down('textfield').markInvalid('');
raimund@548:         var fieldset = this.up('fieldset[collapsible=true]');
raimund@548:         if (fieldset) {
raimund@634:             var i18n = Lada.getApplication().bundle;
raimund@634:             var warningText = i18n.getMsg(this.name) + ': ' + warnings;
raimund@634:             fieldset.showWarningOrError(true, warningText);
raimund@548:         }
raimund@548:     },
raimund@548: 
raimund@548:     showErrors: function(errors) {
raimund@548:         var img = this.down('image[name=errorImg]');
raimund@548:         var warnImg = this.down('image[name=warnImg]');
raimund@548:         warnImg.hide();
raimund@548:         Ext.create('Ext.tip.ToolTip', {
raimund@548:             target: img.getEl(),
raimund@548:             html: errors
raimund@548:         });
raimund@548:         this.down('textfield').invalidCls = 'x-lada-error';
raimund@548:         this.down('textfield').markInvalid('');
raimund@548:         img.show();
raimund@548:         var fieldset = this.up('fieldset[collapsible=true]');
raimund@548:         if (fieldset) {
raimund@634:             var i18n = Lada.getApplication().bundle;
raimund@634:             var errorText = i18n.getMsg(this.name) + ': ' + errors;
raimund@634:             fieldset.showWarningOrError(false, '', true, errorText);
raimund@548:         }
raimund@548:     },
raimund@548: 
raimund@1016:     getValue: function() {
raimund@1016:         return this.down('textfield').getValue();
raimund@1016:     },
raimund@1016: 
raimund@1016:     setValue: function(value) {
raimund@1016:         this.down('textfield').setValue(value);
raimund@1016:     },
raimund@1016: 
raimund@548:     clearWarningOrError: function() {
raimund@548:         this.down('image[name=errorImg]').hide();
raimund@548:         this.down('image[name=warnImg]').hide();
raimund@548:     },
raimund@548: 
raimund@548:     setReadOnly: function(value) {
raimund@548:         this.down('textfield').setReadOnly(value);
raimund@548:     }
raimund@548: });