aboutsummaryrefslogtreecommitdiff
path: root/web/app/view
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-10-06 19:57:57 +0500
committerAbyss777 <abyss@fox5.ru>2017-10-06 19:57:57 +0500
commit8e4efa28702b6386dcfd20ba98fe8fa42b9682ed (patch)
tree5c743e2772e3e5ade02e4c89d691bd4e69e3f59b /web/app/view
parent8023ed43765dccafebcbb332ab320bc4fc4bb682 (diff)
downloadtrackermap-web-8e4efa28702b6386dcfd20ba98fe8fa42b9682ed.tar.gz
trackermap-web-8e4efa28702b6386dcfd20ba98fe8fa42b9682ed.tar.bz2
trackermap-web-8e4efa28702b6386dcfd20ba98fe8fa42b9682ed.zip
Optimize switch and conditions
Diffstat (limited to 'web/app/view')
-rw-r--r--web/app/view/dialog/ReportConfigController.js87
1 files changed, 44 insertions, 43 deletions
diff --git a/web/app/view/dialog/ReportConfigController.js b/web/app/view/dialog/ReportConfigController.js
index 17699b98..6d029428 100644
--- a/web/app/view/dialog/ReportConfigController.js
+++ b/web/app/view/dialog/ReportConfigController.js
@@ -50,49 +50,50 @@ Ext.define('Traccar.view.dialog.ReportConfigController', {
},
onPeriodChange: function (combobox, newValue) {
- var day, first, from = new Date(), to = new Date();
- switch (newValue) {
- case 'custom':
- this.lookupReference('fromContainer').setHidden(false);
- this.lookupReference('toContainer').setHidden(false);
- return;
- case 'today':
- to.setDate(to.getDate() + 1);
- break;
- case 'yesterday':
- from.setDate(to.getDate() - 1);
- break;
- case 'thisWeek':
- day = from.getDay();
- first = from.getDate() - day + (day === 0 ? -6 : 1);
- from.setDate(first);
- to.setDate(first + 7);
- break;
- case 'previousWeek':
- day = from.getDay();
- first = from.getDate() - day + (day === 0 ? -6 : 1);
- from.setDate(first - 7);
- to.setDate(first);
- break;
- case 'thisMonth':
- from.setDate(1);
- to.setDate(1);
- to.setMonth(from.getMonth() + 1);
- break;
- case 'previousMonth':
- from.setDate(1);
- from.setMonth(from.getMonth() - 1);
- to.setDate(1);
- break;
- default:
+ var day, first, from, to, custom = newValue === 'custom';
+ this.lookupReference('fromContainer').setHidden(!custom);
+ this.lookupReference('toContainer').setHidden(!custom);
+ if (!custom) {
+ from = new Date();
+ to = new Date();
+ switch (newValue) {
+ case 'today':
+ to.setDate(to.getDate() + 1);
+ break;
+ case 'yesterday':
+ from.setDate(to.getDate() - 1);
+ break;
+ case 'thisWeek':
+ day = from.getDay();
+ first = from.getDate() - day + (day === 0 ? -6 : 1);
+ from.setDate(first);
+ to.setDate(first + 7);
+ break;
+ case 'previousWeek':
+ day = from.getDay();
+ first = from.getDate() - day + (day === 0 ? -6 : 1);
+ from.setDate(first - 7);
+ to.setDate(first);
+ break;
+ case 'thisMonth':
+ from.setDate(1);
+ to.setDate(1);
+ to.setMonth(from.getMonth() + 1);
+ break;
+ case 'previousMonth':
+ from.setDate(1);
+ from.setMonth(from.getMonth() - 1);
+ to.setDate(1);
+ break;
+ default:
+ break;
+ }
+ from.setHours(0, 0, 0, 0);
+ to.setHours(0, 0, 0, 0);
+ this.lookupReference('fromDateField').setValue(from);
+ this.lookupReference('fromTimeField').setValue(from);
+ this.lookupReference('toDateField').setValue(to);
+ this.lookupReference('toTimeField').setValue(to);
}
- from.setHours(0, 0, 0, 0);
- to.setHours(0, 0, 0, 0);
- this.lookupReference('fromDateField').setValue(from);
- this.lookupReference('fromTimeField').setValue(from);
- this.lookupReference('toDateField').setValue(to);
- this.lookupReference('toTimeField').setValue(to);
- this.lookupReference('fromContainer').setHidden(true);
- this.lookupReference('toContainer').setHidden(true);
}
});