raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@548: * Software engineering by Intevation GmbH raimund@548: * raimund@548: * This file is Free Software under the GNU GPL (v>=3) raimund@548: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@548: * the documentation coming with IMIS-Labordaten-Application for details. raimund@548: */ raimund@548: raimund@548: /** raimund@548: * Model class for Messwerte raimund@548: */ raimund@548: Ext.define('Lada.model.Messwert', { raimund@548: extend: 'Ext.data.Model', raimund@548: raimund@548: fields: [{ raimund@548: name: 'id' raimund@548: }, { dustin@691: name: 'owner', dustin@691: type: 'boolean' dustin@691: }, { dustin@702: name: 'readonly', dustin@702: type: 'boolean', dustin@702: persist: false dustin@702: }, { raimund@548: name: 'messungsId' raimund@548: }, { raimund@548: name: 'messgroesseId' raimund@548: }, { raimund@548: name: 'messwert', raimund@1054: serialize: function(v) { raimund@1054: if (!v || v === '') { raimund@1054: return v; raimund@1054: } raimund@1054: if (v.indexOf(',') > 0) { raimund@1054: v = v.replace(',', '.'); raimund@1054: return v; raimund@1054: } raimund@1054: return v; raimund@1054: }, raimund@1054: convert: function(value) { raimund@1054: if (!value || value === '') { raimund@1054: return value; raimund@1054: } raimund@1054: var valueString = value.toString(); tom@1091: if (valueString.indexOf(',') > 0) { tom@1091: valueString.replace(',', '.'); raimund@1054: } tom@1091: return parseFloat(valueString).toExponential(2).toString() tom@1091: .replace('.', ','); raimund@1054: } raimund@548: }, { mstanko@991: name: 'messwertNwg', mstanko@991: convert: function(v) { mstanko@991: if (!v) { mstanko@991: return null; mstanko@991: } mstanko@991: return "<"; mstanko@991: }, mstanko@991: // defaultValue: null raimund@548: }, { raimund@548: name: 'messfehler', raimund@548: type: 'float' raimund@548: }, { raimund@548: name: 'nwgZuMesswert', raimund@1054: serialize: function(v) { raimund@1054: if (!v || v === '') { raimund@1054: return v; raimund@1054: } raimund@1054: if (v.indexOf(',') > 0) { raimund@1054: v = v.replace(',', '.'); raimund@1054: return v; raimund@1054: } raimund@1054: return v; raimund@1054: }, raimund@1054: convert: function(value) { raimund@1054: if (!value || value === '') { raimund@1054: return value; raimund@1054: } raimund@1054: var valueString = value.toString(); raimund@1054: if (valueString.indexOf('E') > 0) { raimund@1054: valueString = valueString.replace('E', 'e'); raimund@1054: } raimund@1054: var tmp; raimund@1054: if (valueString.indexOf('e') > 0) { raimund@1054: tmp = valueString; raimund@1054: } raimund@1054: else { raimund@1054: // Currently not locale friendly... raimund@1054: if (valueString.indexOf(',') > 0) { raimund@1054: valueString = valueString.replace(',', '.'); raimund@1054: } raimund@1054: tmp = parseFloat(valueString).toExponential(); raimund@1054: } raimund@1054: var parts = tmp.split('e'); raimund@1054: if (parts[0].indexOf('.') > 0) { raimund@1054: var floatPart = parseFloat(parts[0]); raimund@1069: var separator = floatPart.toFixed(2).toLocaleString().replace(/[-\d]/g, ''); raimund@1069: parts[0] = floatPart.toFixed(2).replace('.', separator); raimund@1069: } raimund@1069: else if (parts[0].indexOf(',') < 0) { raimund@1069: parts[0] = parts[0] + ',00'; raimund@1069: } raimund@1069: var intPart = parseInt(parts[1]); raimund@1069: if (intPart < 10 && intPart >= 0) { raimund@1069: parts[1] = '+0' + parseInt(parts[1]); raimund@1069: } raimund@1069: else if (intPart < 0 && intPart > -10) { raimund@1069: parts[1] = parts[1].replace('-', '-0'); raimund@1054: } raimund@1054: return parts[0] + 'e' + parts[1]; raimund@1054: } raimund@548: }, { raimund@548: name: 'mehId' raimund@548: }, { raimund@548: name: 'grenzwertueberschreitung', raimund@548: type: 'boolean' raimund@548: }, { raimund@548: name: 'letzteAenderung', raimund@548: type: 'date', raimund@548: convert: function(v) { raimund@548: if (!v) { dustin@564: return new Date(); raimund@548: } dustin@564: return new Date(v); dustin@970: } raimund@689: }, { raimund@711: name: 'treeModified', raimund@711: serialize: function(value) { raimund@711: if (value === '') { raimund@711: return null; raimund@711: } raimund@711: return value; raimund@711: } raimund@711: }, { raimund@711: name: 'parentModified', raimund@711: serialize: function(value) { raimund@711: if (value === '') { raimund@711: return null; raimund@711: } raimund@711: return value; raimund@711: } raimund@548: }], raimund@548: raimund@548: idProperty: 'id', raimund@548: raimund@548: proxy: { raimund@548: type: 'rest', dustin@999: url: 'lada-server/rest/messwert', raimund@548: reader: { raimund@548: type: 'json', raimund@548: root: 'data' raimund@548: } raimund@548: } raimund@548: });