Skip to content

Commit

Permalink
Fixed issue #18101: Spinning hexagon continues to spin although file …
Browse files Browse the repository at this point in the history
…is correctly downloaded (#2454)

Dev Use FileSaver
  • Loading branch information
gabrieljenik committed Jun 27, 2022
1 parent 73cf534 commit a48a4c0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion assets/scripts/admin/statistics.js
Expand Up @@ -277,14 +277,19 @@ LS.Statistics2 = function () {
});

$('#generate-statistics').submit(function () {

hideSection($('#generalfilters-chevron'), $('#statisticsgeneralfilters'));
hideSection($('#responsefilters-chevron'), $('#filterchoices'))
$('#statisticsoutput').show();
$('#statistics-render-chevron').removeClass('fa-chevron-up');
$('#statistics-render-chevron').addClass('fa-chevron-down');
$('#view-stats-alert-info').hide();
$('#statsContainerLoading').show();
if ($('input[name=outputtype]:checked').val() != 'html') {
var data = new FormData($(this).get(0));
var url = $(this).attr('action');
ajaxDownloadStats(url, data);
return false;
}
//alert('ok');
});

Expand Down Expand Up @@ -590,6 +595,28 @@ LS.Statistics2 = function () {
$(".stats-showpie").click(function () {
changeGraphType('showpie', this.parentNode);
});

var ajaxDownloadStats = function (url, data) {
const xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
const contentDisposition = xhr.getResponseHeader('Content-Disposition');
const fileName = contentDisposition ? contentDisposition.match(/filename[^;=\n]*=['"](.*?|[^;\n]*)['"]/)[1] : '';
if (fileName.length > 0) {
// saveAs is implemented by jszip/fileSaver.js
saveAs(xhr.response, fileName);
} else {
ajaxError();
}
$('#statsContainerLoading').hide();
};
xhr.onerror = () => {
ajaxError();
$('#statsContainerLoading').hide();
};
xhr.send(data);
};
};

var isWaiting = {};
Expand All @@ -615,6 +642,7 @@ function graphQuery(id, cmd, success) {
}

function ajaxError() {
// TODO: Use NotifyFader?
alert("An error occured! Please reload the page!");
}

Expand Down

0 comments on commit a48a4c0

Please sign in to comment.