dustin@610: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
dustin@610:  * Software engineering by Intevation GmbH
dustin@610:  *
dustin@610:  * This file is Free Software under the GNU GPL (v>=3)
dustin@610:  * and comes with ABSOLUTELY NO WARRANTY! Check out
dustin@610:  * the documentation coming with IMIS-Labordaten-Application for details.
dustin@610:  */
dustin@610: 
dustin@610: Ext.define('Lada.view.widget.base.CheckBox', {
dustin@610:     extend: 'Ext.form.Panel',
dustin@610:     alias: 'widget.chkbox',
dustin@610: 
dustin@610:     layout: 'hbox',
dustin@610: 
dustin@610:     border: 0,
dustin@610: 
dustin@610:     margin: '0, 0, 5, 0',
dustin@610: 
dustin@610:     initComponent: function() {
dustin@610:         this.items = [{
dustin@610:             xtype: 'checkbox',
dustin@610:             flex: 1,
dustin@610:             name: this.name,
dustin@610:             fieldLabel: this.fieldLabel,
dustin@610:             labelWidth: this.labelWidth,
dustin@610:             listeners: this.listeners,
dustin@610:             triggerAction: this.triggerAction,
dustin@610:             msgTarget: 'none',
dustin@610:             tpl: this.tpl
dustin@610:         }, {
dustin@610:             xtype: 'image',
dustin@610:             name: 'warnImg',
raimund@632:             src: 'resources/img/dialog-warning.png',
raimund@632:             width: 14,
raimund@632:             height: 14,
dustin@610:             hidden: true
dustin@610:         }, {
dustin@610:             xtype: 'image',
dustin@610:             name: 'errorImg',
raimund@632:             src: 'resources/img/emblem-important.png',
raimund@632:             width: 14,
raimund@632:             height: 14,
dustin@610:             hidden: true
dustin@610:         }];
dustin@610:         this.callParent(arguments);
dustin@610:     },
dustin@610: 
dustin@610:     showWarnings: function(warnings) {
dustin@610:         var img = this.down('image[name=warnImg]');
dustin@610:         Ext.create('Ext.tip.ToolTip', {
dustin@610:             target: img.getEl(),
dustin@610:             html: warnings
dustin@610:         });
dustin@610:         this.down('checkbox').invalidCls = 'x-lada-warning';
dustin@610:         this.down('checkbox').markInvalid('');
dustin@610:         img.show();
dustin@610:         var fieldset = this.up('fieldset[collapsible=true]');
dustin@610:         if (fieldset) {
raimund@634:             var i18n = Lada.getApplication().bundle;
raimund@634:             var warningText = i18n.getMsg(this.name) + ': ' + warnings;
raimund@634:             fieldset.showWarningOrError(true, warningText);
dustin@610:         }
dustin@610:     },
dustin@610: 
dustin@610:     showErrors: function(errors) {
dustin@610:         var img = this.down('image[name=errorImg]');
dustin@610:         var warnImg = this.down('image[name=warnImg]');
dustin@610:         warnImg.hide();
dustin@610:         Ext.create('Ext.tip.ToolTip', {
dustin@610:             target: img.getEl(),
dustin@610:             html: errors
dustin@610:         });
dustin@610:         this.down('checkbox').invalidCls = 'x-lada-error';
dustin@610:         this.down('checkbox').markInvalid('');
dustin@610:         img.show();
dustin@610:         var fieldset = this.up('fieldset[collapsible=true]');
dustin@610:         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);
dustin@610:         }
dustin@610:     },
dustin@610: 
dustin@610:     clearWarningOrError: function() {
dustin@610:         this.down('image[name=errorImg]').hide();
dustin@610:         this.down('image[name=warnImg]').hide();
dustin@610:     },
dustin@610: 
dustin@610:     getValue: function() {
dustin@610:         return this.down('checkbox').getValue();
dustin@610:     },
dustin@610: 
dustin@610:     getName: function() {
dustin@610:         return this.name;
dustin@610:     },
dustin@610: 
dustin@610:     setReadOnly: function(value) {
dustin@610:         this.down('checkbox').setReadOnly(value);
dustin@610:     }
dustin@610: });