mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
improve script for downloading exports
This commit is contained in:
@@ -27,50 +27,8 @@ window.addEventListener("DOMContentLoaded", function(e) {
|
||||
query = window.location.search,
|
||||
container = document.querySelector("#download_container")
|
||||
;
|
||||
|
||||
window.fetch(url+query, { credentials: 'same-origin' })
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw Error(response.statusText);
|
||||
}
|
||||
|
||||
return response.blob();
|
||||
}).then(function(blob) {
|
||||
var content = URL.createObjectURL(blob),
|
||||
link = document.createElement("a"),
|
||||
suffix_file;
|
||||
|
||||
switch (blob.type) {
|
||||
case 'application/vnd.oasis.opendocument.spreadsheet':
|
||||
suffix_file = '.ods';
|
||||
break;
|
||||
case 'text/csv':
|
||||
suffix_file = '.csv';
|
||||
break;
|
||||
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||
suffix_file = '.xlsx';
|
||||
break;
|
||||
default:
|
||||
suffix_file = '';
|
||||
}
|
||||
|
||||
link.appendChild(document.createTextNode("{{ "Download your report"|trans }}"));
|
||||
link.classList.add("sc-button", "btn-action");
|
||||
link.href = content;
|
||||
link.download = "{{ alias }}"+suffix_file;
|
||||
let waiting_text = container.querySelector("#waiting_text");
|
||||
container.removeChild(waiting_text);
|
||||
container.appendChild(link);
|
||||
}).catch(function(error) {
|
||||
var problem_text =
|
||||
document.createTextNode("{{ "Problem during download"|trans }}");
|
||||
|
||||
container
|
||||
.replaceChild(problem_text, container.firstChild);
|
||||
})
|
||||
;
|
||||
|
||||
|
||||
chill.download_report(url+query, container);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -79,6 +37,6 @@ window.addEventListener("DOMContentLoaded", function(e) {
|
||||
|
||||
<h1>{{ "Download export"|trans }}</h1>
|
||||
|
||||
<div id="download_container"><span id="waiting_text">{{ "Waiting for your report"|trans }}...</span></div>
|
||||
<div id="download_container" data-alias="{{ alias|escape('html_attr') }}" {% if mime_type is defined %}data-mime-type="{{ mime_type|escape('html_attr') }}"{% endif %} data-download-text="{{ "Download your report"|trans|escape('html_attr') }}"><span id="waiting_text">{{ "Waiting for your report"|trans }}...</span></div>
|
||||
|
||||
{% endblock %}
|
Reference in New Issue
Block a user