diff options
Diffstat (limited to 'web/app/view/ReportController.js')
-rw-r--r-- | web/app/view/ReportController.js | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index aeaa1849e..3a3345d83 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -19,6 +19,12 @@ Ext.define('Traccar.view.ReportController', { extend: 'Ext.app.ViewController', alias: 'controller.report', + requires: [ + 'Traccar.AttributeFormatter', + 'Traccar.view.ReportConfigDialog', + 'Traccar.store.ReportEventTypes' + ], + config: { listen: { controller: { @@ -30,43 +36,73 @@ Ext.define('Traccar.view.ReportController', { } }, - onReportClick: function (button) { - var reportType, deviceId, fromDate, fromTime, from, toDate, toTime, to, store, url; + onConfigureClick: function () { + var dialog = Ext.create('Traccar.view.ReportConfigDialog'); + dialog.lookupReference('eventTypeField').setHidden(this.lookupReference('reportTypeField').getValue() !== 'events'); + dialog.callingPanel = this; + dialog.lookupReference('deviceField').setValue(this.deviceId); + dialog.lookupReference('groupField').setValue(this.groupId); + if (this.eventType !== undefined) { + dialog.lookupReference('eventTypeField').setValue(this.eventType); + } else { + dialog.lookupReference('eventTypeField').setValue([Traccar.store.ReportEventTypes.allEvents]); + } + if (this.fromDate !== undefined) { + dialog.lookupReference('fromDateField').setValue(this.fromDate); + } + if (this.fromTime !== undefined) { + dialog.lookupReference('fromTimeField').setValue(this.fromTime); + } + if (this.toDate !== undefined) { + dialog.lookupReference('toDateField').setValue(this.toDate); + } + if (this.toTime !== undefined) { + dialog.lookupReference('toTimeField').setValue(this.toTime); + } + dialog.show(); + }, + updateButtons: function () { + var reportType, disabled, devices, time; reportType = this.lookupReference('reportTypeField').getValue(); + devices = (this.deviceId && this.deviceId.length !== 0) || (this.groupId && this.groupId.length !== 0); + time = this.fromDate && this.fromTime && this.toDate && this.toTime; + disabled = !reportType || !devices || !time; + this.lookupReference('showButton').setDisabled(disabled); + this.lookupReference('csvButton').setDisabled(disabled); + }, - deviceId = this.lookupReference('deviceField').getValue(); + onReportClick: function (button) { + var reportType, from, to, store, url; - fromDate = this.lookupReference('fromDateField').getValue(); - fromTime = this.lookupReference('fromTimeField').getValue(); + reportType = this.lookupReference('reportTypeField').getValue(); - if (reportType && deviceId) { + if (reportType && (this.deviceId || this.groupId)) { from = new Date( - fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate(), - fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds(), fromTime.getMilliseconds()); - - toDate = this.lookupReference('toDateField').getValue(); - toTime = this.lookupReference('toTimeField').getValue(); + this.fromDate.getFullYear(), this.fromDate.getMonth(), this.fromDate.getDate(), + this.fromTime.getHours(), this.fromTime.getMinutes(), this.fromTime.getSeconds(), this.fromTime.getMilliseconds()); to = new Date( - toDate.getFullYear(), toDate.getMonth(), toDate.getDate(), - toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds()); + this.toDate.getFullYear(), this.toDate.getMonth(), this.toDate.getDate(), + this.toTime.getHours(), this.toTime.getMinutes(), this.toTime.getSeconds(), this.toTime.getMilliseconds()); - if (button.reference === "showButton") { + if (button.reference === 'showButton') { store = this.getView().getStore(); store.load({ params: { - deviceId: deviceId, - type: '%', + deviceId: this.deviceId, + groupId: this.groupId, + type: this.eventType, from: from.toISOString(), to: to.toISOString() } }); - } else if (button.reference === "csvButton") { + } else if (button.reference === 'csvButton') { url = this.getView().getStore().getProxy().url; this.downloadCsv(url, { - deviceId: deviceId, - type: '%', + deviceId: this.deviceId, + groupId: this.groupId, + type: this.eventType, from: from.toISOString(), to: to.toISOString() }); @@ -107,9 +143,9 @@ Ext.define('Traccar.view.ReportController', { success: function (response) { var disposition, filename, type, blob, url, downloadUrl, elementA; disposition = response.getResponseHeader('Content-Disposition'); - filename = disposition.slice(disposition.indexOf("=") + 1, disposition.length); + filename = disposition.slice(disposition.indexOf('=') + 1, disposition.length); type = response.getResponseHeader('Content-Type'); - blob = new Blob([response.responseText], { type: type }); + blob = new Blob([response.responseText], {type: type}); if (typeof window.navigator.msSaveBlob !== 'undefined') { // IE workaround window.navigator.msSaveBlob(blob, filename); @@ -117,7 +153,7 @@ Ext.define('Traccar.view.ReportController', { url = window.URL || window.webkitURL; downloadUrl = url.createObjectURL(blob); if (filename) { - elementA = document.createElement("a"); + elementA = document.createElement('a'); elementA.href = downloadUrl; elementA.download = filename; document.body.appendChild(elementA); @@ -300,6 +336,8 @@ Ext.define('Traccar.view.ReportController', { } else if (newValue === 'trips') { this.getView().reconfigure('ReportTrips', tripsColumns); } + + this.updateButtons(); } }); |