diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-15 22:40:32 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-15 22:40:32 +1200 |
commit | 4c13d0f9ee6b431c215783070f8a1f410697dc7b (patch) | |
tree | fad4674ff5784e4df071419527c4d588be3fa576 /web/app/Application.js | |
parent | 059e040546df731827a455cefd5b293c3b14694c (diff) | |
download | trackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.tar.gz trackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.tar.bz2 trackermap-server-4c13d0f9ee6b431c215783070f8a1f410697dc7b.zip |
Move value formatting code
Diffstat (limited to 'web/app/Application.js')
-rw-r--r-- | web/app/Application.js | 34 |
1 files changed, 34 insertions, 0 deletions
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; + } + } } }); |