From 4c13d0f9ee6b431c215783070f8a1f410697dc7b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 15 Sep 2015 22:40:32 +1200 Subject: Move value formatting code --- web/app/Application.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'web/app/Application.js') diff --git a/web/app/Application.js b/web/app/Application.js index 0ed509686..93f197fb1 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -64,6 +64,40 @@ Ext.define('Traccar.Application', { getServer: function() { return this.server; + }, + + getPreference: function(key, defaultValue) { + return this.getUser().get('distanceUnit') | this.getServer().get('distanceUnit') | defaultValue; + }, + + getRenderer: function(key) { + if (key === 'latitude' || key === 'longitude') { + return function(value) { + return value.toFixed(5); + } + } else if (key === 'speed') { + return function(value) { + return Ext.getStore('SpeedUnits').formatValue(value, this.getPreference('speedUnit')); + } + } else if (key === 'course') { + return function(value) { + var directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; + return directions[Math.floor(value / 45)]; + } + } else if (key === 'distance' || key === 'odometer') { + return function(value) { + return Ext.getStore('DistanceUnits').formatValue(value, this.getPreference('distanceUnit')); + } + } else { + return function(value) { + if (value instanceof Number) { + return value.toFixed(2); + } else if (value instanceof Date) { + return Ext.Date.format(value, styles.dateTimeFormat); + } + return value; + } + } } }); -- cgit v1.2.3