Mercurial > lada > lada-client
annotate app/view/form/ExpNumberField.js @ 1119:b73f9a976c82
Exponential notation without tampering numbers.
Rounding is done by the server. Thus, the client should not fix the
number of digits, except only for rendering.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 23 May 2016 16:00:50 +0200 |
parents | |
children |
rev | line source |
---|---|
1119
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 * |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 */ |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 /** |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 * Number field for display and editing of exponential numbers |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 */ |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 Ext.define('Lada.view.form.ExpNumberField', { |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 extend: 'Ext.form.field.Number', |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 alias: 'widget.expnumberfield', |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 baseChars: '0123456789eE', |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
18 hideTrigger: true, |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 keyNavEnabled: false, |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 mouseWheelEnabled: false, |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 valueToRaw: function(value) { |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 if (!value || value === '') { |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 return value; |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 } |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 // XXX: this will be applied to any input before being sent to |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 // the server! Thus, toExponential(2) would lead to incorrectly |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 // rounded numbers at this point. |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 value = parseFloat(value).toExponential() |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 .toString().replace('.', this.decimalSeparator); |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 return value; |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 }, |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 rawToValue: function(value) { |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 if (!value || value === '') { |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
38 return value; |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 } |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 value = parseFloat( |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 value.toString().replace(this.decimalSeparator, '.')); |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
43 |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
44 return value; |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
45 } |
b73f9a976c82
Exponential notation without tampering numbers.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
46 }); |