changeset 1122:49189f7b4d2f

merged.
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 23 May 2016 17:07:50 +0200
parents 0b908138a740 (current diff) b73f9a976c82 (diff)
children 4f68511ce7a4 a4944b52176e
files
diffstat 5 files changed, 77 insertions(+), 201 deletions(-) [+]
line wrap: on
line diff
--- a/app/model/Messwert.js	Mon May 23 17:07:15 2016 +0200
+++ b/app/model/Messwert.js	Mon May 23 17:07:50 2016 +0200
@@ -26,54 +26,7 @@
     }, {
         name: 'messgroesseId'
     }, {
-        name: 'messwert',
-        serialize: function(v) {
-            if (!v || v === '') {
-                return v;
-            }
-            if (v.indexOf(',') > 0) {
-                v = v.replace(',', '.');
-                return v;
-            }
-            return v;
-        },
-        convert: function(value) {
-            if (!value || value === '') {
-                return value;
-            }
-            var valueString = value.toString();
-            if (valueString.indexOf('E') > 0) {
-                valueString = valueString.replace('E', 'e');
-            }
-            var tmp;
-            if (valueString.indexOf('e') > 0) {
-                tmp = valueString;
-            }
-            else {
-                // Currently not locale friendly...
-                if (valueString.indexOf(',') > 0) {
-                    valueString = valueString.replace(',', '.');
-                }
-                tmp = parseFloat(valueString).toExponential();
-            }
-            var parts = tmp.split('e');
-            if (parts[0].indexOf('.') > 0) {
-                var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(2).replace('.', separator);
-            }
-            else if (parts[0].indexOf(',') < 0) {
-                parts[0] = parts[0] + ',00';
-            }
-            var intPart = parseInt(parts[1]);
-            if (intPart < 10 && intPart >= 0) {
-                parts[1] = '+0' + parseInt(parts[1]);
-            }
-            else if (intPart < 0 && intPart > -10) {
-                parts[1] = parts[1].replace('-', '-0');
-            }
-            return parts[0] + 'e' + parts[1];
-        }
+        name: 'messwert'
     }, {
         name: 'messwertNwg',
         convert: function(v) {
@@ -87,54 +40,7 @@
         name: 'messfehler',
         type: 'float'
     }, {
-        name: 'nwgZuMesswert',
-        serialize: function(v) {
-            if (!v || v === '') {
-                return v;
-            }
-            if (v.indexOf(',') > 0) {
-                v = v.replace(',', '.');
-                return v;
-            }
-            return v;
-        },
-        convert: function(value) {
-            if (!value || value === '') {
-                return value;
-            }
-            var valueString = value.toString();
-            if (valueString.indexOf('E') > 0) {
-                valueString = valueString.replace('E', 'e');
-            }
-            var tmp;
-            if (valueString.indexOf('e') > 0) {
-                tmp = valueString;
-            }
-            else {
-                // Currently not locale friendly...
-                if (valueString.indexOf(',') > 0) {
-                    valueString = valueString.replace(',', '.');
-                }
-                tmp = parseFloat(valueString).toExponential();
-            }
-            var parts = tmp.split('e');
-            if (parts[0].indexOf('.') > 0) {
-                var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(2).replace('.', separator);
-            }
-            else if (parts[0].indexOf(',') < 0) {
-                parts[0] = parts[0] + ',00';
-            }
-            var intPart = parseInt(parts[1]);
-            if (intPart < 10 && intPart >= 0) {
-                parts[1] = '+0' + parseInt(parts[1]);
-            }
-            else if (intPart < 0 && intPart > -10) {
-                parts[1] = parts[1].replace('-', '-0');
-            }
-            return parts[0] + 'e' + parts[1];
-        }
+        name: 'nwgZuMesswert'
     }, {
         name: 'mehId'
     }, {
--- a/app/model/Zusatzwert.js	Mon May 23 17:07:15 2016 +0200
+++ b/app/model/Zusatzwert.js	Mon May 23 17:07:50 2016 +0200
@@ -26,97 +26,9 @@
     }, {
         name: 'pzsId'
     }, {
-        name: 'nwgZuMesswert',
-        serialize: function(v) {
-            if (v.indexOf(',') > 0) {
-                v = v.replace(',', '.');
-                return v;
-            }
-            return v;
-        },
-        convert: function(value) {
-            if (!value || value === '') {
-                return value;
-            }
-            var valueString = value.toString();
-            if (valueString.indexOf('E') > 0) {
-                valueString = valueString.replace('E', 'e');
-            }
-            var tmp;
-            if (valueString.indexOf('e') > 0) {
-                tmp = valueString;
-            }
-            else {
-                // Currently not locale friendly...
-                if (valueString.indexOf(',') > 0) {
-                    valueString = valueString.replace(',', '.');
-                }
-                tmp = parseFloat(valueString).toExponential();
-            }
-            var parts = tmp.split('e');
-            if (parts[0].indexOf('.') > 0) {
-                var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(2).replace('.', separator);
-            }
-            else if (parts[0].indexOf(',') < 0) {
-                parts[0] = parts[0] + ',00';
-            }
-            var intPart = parseInt(parts[1]);
-            if (intPart < 10 && intPart >= 0) {
-                parts[1] = '+0' + parseInt(parts[1]);
-            }
-            else if (intPart < 0 && intPart > -10) {
-                parts[1] = parts[1].replace('-', '-0');
-            }
-            return parts[0] + 'e' + parts[1];
-        }
+        name: 'nwgZuMesswert'
     }, {
-        name: 'messwertPzs',
-        serialize: function(v) {
-            if (v.indexOf(',') > 0) {
-                v = v.replace(',', '.');
-                return v;
-            }
-            return v;
-        },
-        convert: function(value) {
-            if (!value || value === '') {
-                return value;
-            }
-            var valueString = value.toString();
-            if (valueString.indexOf('E') > 0) {
-                valueString = valueString.replace('E', 'e');
-            }
-            var tmp;
-            if (valueString.indexOf('e') > 0) {
-                tmp = valueString;
-            }
-            else {
-                // Currently not locale friendly...
-                if (valueString.indexOf(',') > 0) {
-                    valueString = valueString.replace(',', '.');
-                }
-                tmp = parseFloat(valueString).toExponential();
-            }
-            var parts = tmp.split('e');
-            if (parts[0].indexOf('.') > 0) {
-                var floatPart = parseFloat(parts[0]);
-                var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, '');
-                parts[0] = floatPart.toFixed(2).replace('.', separator);
-            }
-            else if (parts[0].indexOf(',') < 0) {
-                parts[0] = parts[0] + ',00';
-            }
-            var intPart = parseInt(parts[1]);
-            if (intPart < 10 && intPart >= 0) {
-                parts[1] = '+0' + parseInt(parts[1]);
-            }
-            else if (intPart < 0 && intPart > -10) {
-                parts[1] = parts[1].replace('-', '-0');
-            }
-            return parts[0] + 'e' + parts[1];
-        }
+        name: 'messwertPzs'
     }, {
         name: 'messfehler',
         type: 'float'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/form/ExpNumberField.js	Mon May 23 17:07:50 2016 +0200
@@ -0,0 +1,46 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+/**
+ * Number field for display and editing of exponential numbers
+ */
+Ext.define('Lada.view.form.ExpNumberField', {
+    extend: 'Ext.form.field.Number',
+    alias: 'widget.expnumberfield',
+
+    baseChars: '0123456789eE',
+
+    hideTrigger: true,
+    keyNavEnabled: false,
+    mouseWheelEnabled: false,
+
+    valueToRaw: function(value) {
+        if (!value || value === '') {
+            return value;
+        }
+
+        // XXX: this will be applied to any input before being sent to
+        // the server! Thus, toExponential(2) would lead to incorrectly
+        // rounded numbers at this point.
+        value = parseFloat(value).toExponential()
+            .toString().replace('.', this.decimalSeparator);
+
+        return value;
+    },
+
+    rawToValue: function(value) {
+        if (!value || value === '') {
+            return value;
+        }
+
+        value = parseFloat(
+            value.toString().replace(this.decimalSeparator, '.'));
+
+        return value;
+    }
+});
--- a/app/view/grid/Messwert.js	Mon May 23 17:07:15 2016 +0200
+++ b/app/view/grid/Messwert.js	Mon May 23 17:07:50 2016 +0200
@@ -14,6 +14,7 @@
     alias: 'widget.messwertgrid',
 
     requires: [
+        'Lada.view.form.ExpNumberField',
         'Lada.view.widget.Messgroesse',
         'Lada.view.widget.Messeinheit'
     ],
@@ -114,10 +115,11 @@
             dataIndex: 'messwert',
             width: 80,
             editor: {
-                xtype: 'textfield',
+                xtype: 'expnumberfield',
                 allowBlank: false,
-                regex: /^[+\-]?(?:(?:0|[1-9]\d*)(?:[\.\,][0-9]\d*)?(?:[eE][+\-]?\d+)|(\d+[\.\,]?\d*)?)$/,
-                regexText: 'Keine Zahl'
+            },
+            renderer: function(value) {
+                return value.toExponential(2).toString().replace('.', ',');
             }
         }, {
             header: 'Messeinheit',
@@ -161,10 +163,13 @@
             dataIndex: 'nwgZuMesswert',
             width: 80,
             editor: {
-                xtype: 'textfield',
-                allowBlank: true,
-                regex: /^[+\-]?(?:(?:0|[1-9]\d*)(?:[\.\,][0-9]\d*)?(?:[eE][+\-]?\d+)|(\d+[\.\,]?\d*)?)$/,
-                regexText: 'Keine Zahl'
+                xtype: 'expnumberfield'
+            },
+            renderer: function(value) {
+                if (!value || value === '') {
+                    return value;
+                }
+                return value.toExponential(2).toString().replace('.', ',');
             }
         }, {
             header: 'Grenzwertüberschreitung',
--- a/app/view/grid/Probenzusatzwert.js	Mon May 23 17:07:15 2016 +0200
+++ b/app/view/grid/Probenzusatzwert.js	Mon May 23 17:07:50 2016 +0200
@@ -13,6 +13,7 @@
     extend: 'Ext.grid.Panel',
     alias: 'widget.probenzusatzwertgrid',
     requires: [
+        'Lada.view.form.ExpNumberField',
         'Lada.view.widget.Probenzusatzwert'
     ],
 
@@ -92,10 +93,13 @@
             dataIndex: 'messwertPzs',
             flex: 1,
             editor: {
-                xtype: 'textfield',
-                allowBlank: false,
-                regex: /^[+\-]?(?:(?:0|[1-9]\d*)(?:[\.\,][0-9]\d*)?(?:[eE][+\-]?\d+)|(\d+[\.\,]?\d*)?)$/,
-                regexText: 'Keine Zahl'
+                xtype: 'expnumberfield',
+            },
+            renderer: function(value) {
+                if (!value || value === '') {
+                    return value;
+                }
+                return value.toExponential(2).toString().replace('.', ',');
             }
         }, {
             header: '< NWG',
@@ -114,10 +118,13 @@
             xtype: 'numbercolumn',
             flex: 1,
             editor: {
-                xtype: 'textfield',
-                allowBlank: false,
-                regex: /^[+\-]?(?:(?:0|[1-9]\d*)(?:[\.\,][0-9]\d*)?(?:[eE][+\-]?\d+)|(\d+[\.\,]?\d*)?)$/,
-                regexText: 'Keine Zahl'
+                xtype: 'expnumberfield',
+            },
+            renderer: function(value) {
+                if (!value || value === '') {
+                    return value;
+                }
+                return value.toExponential(2).toString().replace('.', ',');
             }
         }, {
             header: 'Maßeinheit',

http://lada.wald.intevation.org