[Lada-commits] [PATCH 3 of 3] merged

Wald Commits scm-commit at wald.intevation.org
Mon May 23 17:07:58 CEST 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1464016070 -7200
# Node ID 49189f7b4d2f9e6635dd07890a357b8ff4bbf717
# Parent  0b908138a74048be06ebee4a785065100ca8b1fa
# Parent  b73f9a976c8277f27761b76fe346a31d3cddf89f
merged.

diff -r 0b908138a740 -r 49189f7b4d2f app/model/Messwert.js
--- 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'
     }, {
diff -r 0b908138a740 -r 49189f7b4d2f app/model/Zusatzwert.js
--- 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'
diff -r 0b908138a740 -r 49189f7b4d2f app/view/form/ExpNumberField.js
--- /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;
+    }
+});
diff -r 0b908138a740 -r 49189f7b4d2f app/view/grid/Messwert.js
--- 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',
diff -r 0b908138a740 -r 49189f7b4d2f app/view/grid/Probenzusatzwert.js
--- 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',


More information about the Lada-commits mailing list