diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-20 16:56:04 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-20 16:56:04 +1300 |
commit | 524c64e5bac499a27b2ae9551e579f22b5dadb53 (patch) | |
tree | 0138d2087d867479e7e395d5e57c0bfe00e02d1f /web/app/view | |
parent | 6bc12c491c3546ba85c7792411d050de0f9deeaf (diff) | |
parent | 34dff47c42358769268510ad6c2ac176b45b45e3 (diff) | |
download | trackermap-web-524c64e5bac499a27b2ae9551e579f22b5dadb53.tar.gz trackermap-web-524c64e5bac499a27b2ae9551e579f22b5dadb53.tar.bz2 trackermap-web-524c64e5bac499a27b2ae9551e579f22b5dadb53.zip |
Merge pull request #300 from Abyss777/export_excel
Export reports to excel
Diffstat (limited to 'web/app/view')
-rw-r--r-- | web/app/view/Report.js | 4 | ||||
-rw-r--r-- | web/app/view/ReportController.js | 25 |
2 files changed, 15 insertions, 14 deletions
diff --git a/web/app/view/Report.js b/web/app/view/Report.js index 18debc63..a1fbd1b2 100644 --- a/web/app/view/Report.js +++ b/web/app/view/Report.js @@ -49,8 +49,8 @@ Ext.define('Traccar.view.Report', { disabled: true, handler: 'onReportClick' }, { - text: Strings.reportCsv, - reference: 'csvButton', + text: Strings.reportExport, + reference: 'exportButton', disabled: true, handler: 'onReportClick' }, { diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 50f4251e..e8198b36 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -74,7 +74,7 @@ Ext.define('Traccar.view.ReportController', { time = this.fromDate && this.fromTime && this.toDate && this.toTime; disabled = !reportType || !devices || !time; this.lookupReference('showButton').setDisabled(disabled); - this.lookupReference('csvButton').setDisabled(disabled); + this.lookupReference('exportButton').setDisabled(disabled); }, onReportClick: function (button) { @@ -102,9 +102,9 @@ Ext.define('Traccar.view.ReportController', { to: to.toISOString() } }); - } else if (button.reference === 'csvButton') { + } else if (button.reference === 'exportButton') { url = this.getView().getStore().getProxy().url; - this.downloadCsv(url, { + this.downloadFile(url, { deviceId: this.deviceId, groupId: this.groupId, type: this.eventType, @@ -166,20 +166,21 @@ Ext.define('Traccar.view.ReportController', { }); }, - downloadCsv: function (requestUrl, requestParams) { + downloadFile: function (requestUrl, requestParams) { Ext.Ajax.request({ url: requestUrl, method: 'GET', params: requestParams, headers: { - Accept: 'text/csv' + Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }, + binary: true, success: function (response) { - var disposition, filename, type, blob, url, downloadUrl, elementA; + var disposition, filename, type, blob, url, downloadUrl; disposition = response.getResponseHeader('Content-Disposition'); filename = disposition.slice(disposition.indexOf('=') + 1, disposition.length); type = response.getResponseHeader('Content-Type'); - blob = new Blob([response.responseText], {type: type}); + blob = new Blob([response.responseBytes], {type: type}); if (typeof window.navigator.msSaveBlob !== 'undefined') { // IE workaround window.navigator.msSaveBlob(blob, filename); @@ -187,11 +188,11 @@ Ext.define('Traccar.view.ReportController', { url = window.URL || window.webkitURL; downloadUrl = url.createObjectURL(blob); if (filename) { - elementA = document.createElement('a'); - elementA.href = downloadUrl; - elementA.download = filename; - document.body.appendChild(elementA); - elementA.click(); + Ext.dom.Helper.append(Ext.getBody(), { + tag: 'a', + href: downloadUrl, + download: filename + }).click(); } setTimeout(function () { url.revokeObjectURL(downloadUrl); |