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