aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-06-07 13:37:51 +0500
committerAbyss777 <abyss@fox5.ru>2017-06-07 13:37:51 +0500
commite04a02921ea015d4f4fe69c1c3f1813a07be9cf4 (patch)
tree26478c08fc6f7136ec8355d13af2a1bbf97207dc /web/app
parente0030185daa54eda46157cd35b989d1a63c79656 (diff)
downloadtrackermap-web-e04a02921ea015d4f4fe69c1c3f1813a07be9cf4.tar.gz
trackermap-web-e04a02921ea015d4f4fe69c1c3f1813a07be9cf4.tar.bz2
trackermap-web-e04a02921ea015d4f4fe69c1c3f1813a07be9cf4.zip
Combine simple formatters in one factory
Diffstat (limited to 'web/app')
-rw-r--r--web/app/AttributeFormatter.js48
1 files changed, 13 insertions, 35 deletions
diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js
index 423492dd..3f7c1276 100644
--- a/web/app/AttributeFormatter.js
+++ b/web/app/AttributeFormatter.js
@@ -18,6 +18,14 @@
Ext.define('Traccar.AttributeFormatter', {
singleton: true,
+ numberFormatterFactory: function (precision, suffix) {
+ return function (value) {
+ if (value !== undefined) {
+ return Number(value.toFixed(precision)) + ' ' + suffix;
+ }
+ };
+ },
+
coordinateFormatter: function (key, value) {
return Ext.getStore('CoordinateFormats').formatValue(key, value, Traccar.app.getPreference('coordinateFormat'));
},
@@ -43,36 +51,6 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit'));
},
- voltageFormatter: function (value) {
- if (value !== undefined) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedVoltAbbreviation;
- }
- },
-
- percentageFormatter: function (value) {
- if (value !== undefined) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &#37;';
- }
- },
-
- temperatureFormatter: function (value) {
- if (value !== undefined) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &deg;C';
- }
- },
-
- volumeFormatter: function (value) {
- if (value !== undefined) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterAbbreviation;
- }
- },
-
- consumptionFormatter: function (value) {
- if (value !== undefined) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterPerHourAbbreviation;
- }
- },
-
hoursFormatter: function (value) {
var hours = Math.round(value / 3600000);
return (hours + ' ' + Strings.sharedHourAbbreviation);
@@ -171,15 +149,15 @@ Ext.define('Traccar.AttributeFormatter', {
} else if (dataType === 'speed') {
return this.speedFormatter;
} else if (dataType === 'voltage') {
- return this.voltageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedVoltAbbreviation);
} else if (dataType === 'percentage') {
- return this.percentageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&#37;');
} else if (dataType === 'temperature') {
- return this.temperatureFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&deg;C');
} else if (dataType === 'volume') {
- return this.volumeFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation);
} else if (dataType === 'consumption') {
- return this.consumptionFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation);
} else {
return this.defaultFormatter;
}