From d2139af877194952e3d49ca882188bcebbbd927e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 15 Sep 2015 12:24:13 +1200 Subject: Update and format store classes --- web/app/store/SpeedUnits.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'web/app/store/SpeedUnits.js') diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js index 15c52625f..037670c8d 100644 --- a/web/app/store/SpeedUnits.js +++ b/web/app/store/SpeedUnits.js @@ -16,27 +16,25 @@ Ext.define('Traccar.store.SpeedUnits', { extend: 'Ext.data.Store', - fields: ['key', 'name'], - data: [ - {'key': 'kmh', 'name': strings.sharedKmh}, - {'key': 'mph', 'name': strings.sharedMph} - ], + fields: ['key', 'name', 'factor'], - convert: function(value, unit) { - switch (unit) { - case 'kmh': - return Math.round(value * 1.852 * 10) / 10; - case 'mph': - return Math.round(value * 1.15078 * 10) / 10; - } - return value; - }, + data: [{ + key: 'kmh', + name: strings.sharedKmh, + factor: 1.852 + }, { + key: 'mph', + name: strings.sharedMph, + factor: 1.15078 + }], - getUnitName: function(unit) { + formatValue: function(value, unit) { + var model; if (unit) { - return this.findRecord('key', unit).get('name'); + model = this.findRecord('key', unit); + return Math.round(value * model.get('factor') * 10) / 10 + ' ' + model.get('name'); } else { - return ''; + return value; } } }); -- cgit v1.2.3