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 creat a custom Combobox
dustin@892:  */
raimund@548: Ext.define('Lada.view.widget.base.ComboBox', {
raimund@548:     extend: 'Ext.form.Panel',
raimund@548:     alias: 'widget.cbox',
raimund@548: 
raimund@548:     layout: 'hbox',
raimund@548: 
raimund@548:     border: 0,
raimund@548: 
raimund@548:     margin: '0, 0, 5, 0',
raimund@548: 
raimund@548:     initComponent: function() {
raimund@1080:         if (this.editable === undefined) {
raimund@1080:             this.editable = true;
raimund@1080:         }
raimund@548:         this.items = [{
raimund@548:             xtype: 'combobox',
raimund@548:             flex: 1,
raimund@548:             name: this.name,
raimund@548:             maxLength: this.maxLength,
raimund@548:             fieldLabel: this.fieldLabel,
raimund@548:             labelWidth: this.labelWidth,
raimund@548:             listeners: this.listeners,
raimund@548:             store: this.store,
raimund@548:             displayField: this.displayField,
raimund@548:             valueField: this.valueField,
raimund@548:             emptyText: this.emptyText,
dustin@740:             autoSelect: this.autoSelect || true,
raimund@548:             queryMode: this.queryMode,
raimund@548:             triggerAction: this.triggerAction,
raimund@548:             typeAhead: this.typeAhead,
raimund@548:             minChars: this.minChars,
dustin@817:             maxChars: this.maxChars,
raimund@548:             multiSelect: this.multiSelect,
raimund@1080:             editable: this.editable,
dustin@847:             readOnly: this.readOnly,
dustin@817:             forceSelection: this.forceSelection || false,
raimund@548:             msgTarget: 'none',
raimund@1016:             value: this.value,
dustin@738:             tpl: this.tpl,
dustin@738:             displayTpl: this.displayTpl
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@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:         this.down('combobox').invalidCls = 'x-lada-warning';
raimund@548:         this.down('combobox').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 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('combobox').invalidCls = 'x-lada-error';
raimund@548:         this.down('combobox').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@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:     getValue: function() {
raimund@548:         return this.down('combobox').getValue();
raimund@548:     },
raimund@548: 
raimund@1016:     setValue: function(value) {
raimund@1016:         this.down('combobox').setValue(value);
raimund@1016:     },
raimund@1016: 
raimund@733:     clearValue: function() {
raimund@733:         this.down('combobox').clearValue();
raimund@733:     },
raimund@733: 
raimund@548:     getName: function() {
raimund@548:         return this.name;
raimund@548:     },
raimund@548: 
raimund@548:     setReadOnly: function(value) {
raimund@548:         this.down('combobox').setReadOnly(value);
raimund@548:     }
raimund@548: });