comparison app/view/widget/base/NumberField.js @ 1168:40a07eb873bf

Add numberfield with error/warning functionality and use for Messprogramm form.
author Tom Gottfried <tom@intevation.de>
date Fri, 01 Jul 2016 14:01:02 +0200
parents
children e552e82ceb8a
comparison
equal deleted inserted replaced
1167:e9bf88db2bbb 1168:40a07eb873bf
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8
9 /**
10 * This Widget extends a Panel to create a Numberfield
11 */
12 Ext.define('Lada.view.widget.base.NumberField', {
13 extend: 'Ext.panel.Panel',
14 alias: 'widget.numfield',
15
16 layout: 'hbox',
17
18 border: 0,
19 margin: '0, 0, 5, 0',
20
21 initComponent: function() {
22 this.items = [{
23 xtype: 'numberfield',
24 flex: 1,
25 name: this.name,
26 msgTarget: 'none',
27 maxLength: this.maxLength || 1000,
28 enforceMaxLength: this.enforceMaxLength || true,
29 fieldLabel: this.fieldLabel,
30 labelWidth: this.labelWidth,
31 readOnly: this.readOnly || false,
32 listeners: this.listeners
33 }, {
34 xtype: 'image',
35 name: 'warnImg',
36 src: 'resources/img/dialog-warning.png',
37 width: 14,
38 height: 14,
39 hidden: true
40 }, {
41 xtype: 'image',
42 name: 'errorImg',
43 src: 'resources/img/emblem-important.png',
44 width: 14,
45 height: 14,
46 hidden: true
47 }];
48 this.callParent(arguments);
49 if (this.regex) {
50 Ext.apply(this.down('numberfield'), {regex: this.regex});
51 }
52 if (this.allowBlank === false) {
53 Ext.apply(this.down('numberfield'), {allowBlank: this.allowBlank});
54 }
55 },
56
57 showWarnings: function(warnings) {
58 var img = this.down('image[name=warnImg]');
59 Ext.create('Ext.tip.ToolTip', {
60 target: img.getEl(),
61 html: warnings
62 });
63 img.show();
64 this.down('numberfield').invalidCls = 'x-lada-warning';
65 this.down('numberfield').markInvalid('');
66 var fieldset = this.up('fieldset[collapsible=true]');
67 if (fieldset) {
68 var i18n = Lada.getApplication().bundle;
69 var warningText = i18n.getMsg(this.name) + ': ' + warnings;
70 fieldset.showWarningOrError(true, warningText);
71 }
72 },
73
74 showErrors: function(errors) {
75 var img = this.down('image[name=errorImg]');
76 var warnImg = this.down('image[name=warnImg]');
77 warnImg.hide();
78 Ext.create('Ext.tip.ToolTip', {
79 target: img.getEl(),
80 html: errors
81 });
82 this.down('numberfield').invalidCls = 'x-lada-error';
83 this.down('numberfield').markInvalid('');
84 img.show();
85 var fieldset = this.up('fieldset[collapsible=true]');
86 if (fieldset) {
87 var i18n = Lada.getApplication().bundle;
88 var errorText = i18n.getMsg(this.name) + ': ' + errors;
89 fieldset.showWarningOrError(false, '', true, errorText);
90 }
91 },
92
93 getValue: function() {
94 return this.down('numberfield').getValue();
95 },
96
97 setValue: function(value) {
98 this.down('numberfield').setValue(value);
99 },
100
101 clearWarningOrError: function() {
102 this.down('image[name=errorImg]').hide();
103 this.down('image[name=warnImg]').hide();
104 },
105
106 setReadOnly: function(value) {
107 this.down('numberfield').setReadOnly(value);
108 }
109 });

http://lada.wald.intevation.org