diff app/model/Messwert.js @ 1054:7e801af49eeb

Use exponential notation for messwerte and zusatzwerte.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 02 Mar 2016 12:59:15 +0100
parents 23bfcbdb4527
children 7fa853864d9b
line wrap: on
line diff
--- a/app/model/Messwert.js	Tue Mar 01 14:20:49 2016 +0100
+++ b/app/model/Messwert.js	Wed Mar 02 12:59:15 2016 +0100
@@ -27,7 +27,42 @@
         name: 'messgroesseId'
     }, {
         name: 'messwert',
-        type: 'float'
+        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]);
+                parts[0] = floatPart.toLocaleString();
+            }
+            return parts[0] + 'e' + parts[1];
+        }
     }, {
         name: 'messwertNwg',
         convert: function(v) {
@@ -42,7 +77,42 @@
         type: 'float'
     }, {
         name: 'nwgZuMesswert',
-        type: 'float'
+        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]);
+                parts[0] = floatPart.toLocaleString();
+            }
+            return parts[0] + 'e' + parts[1];
+        }
     }, {
         name: 'mehId'
     }, {

http://lada.wald.intevation.org