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