mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add specific page for download
This commit is contained in:
85
Resources/views/Export/download.html.twig
Normal file
85
Resources/views/Export/download.html.twig
Normal file
@@ -0,0 +1,85 @@
|
||||
{#
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
<info@champs-libres.coop> / <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#}
|
||||
|
||||
{% extends "ChillMainBundle::layoutWithVerticalMenu.html.twig" %}
|
||||
|
||||
{% block title "Download export"|trans %}
|
||||
|
||||
{% block js %}
|
||||
<script type="text/javascript">
|
||||
window.addEventListener("DOMContentLoaded", function(e) {
|
||||
var url = "{{ path('chill_main_export_generate', { 'alias' : alias } ) }}",
|
||||
query = window.location.search,
|
||||
container = document.querySelector("#download_container"),
|
||||
header_content_type
|
||||
;
|
||||
|
||||
window.fetch(url+query, { credentials: 'same-origin' })
|
||||
.then(function(response) {
|
||||
if (!response.ok) {
|
||||
throw Error(response.statusText);
|
||||
}
|
||||
header_content_type = response.headers.get("Content-Type");
|
||||
return response.blob();
|
||||
}).then(function(blob) {
|
||||
var content = URL.createObjectURL(blob),
|
||||
link = document.createElement("a"),
|
||||
suffix_file;
|
||||
|
||||
switch (header_content_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);
|
||||
})
|
||||
;
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block layout_wvm_content %}
|
||||
|
||||
<h1>{{ "Download export"|trans }}</h1>
|
||||
|
||||
<div id="download_container"><span id="waiting_text">{{ "Waiting for your report"|trans }}...</span></div>
|
||||
|
||||
{% endblock %}
|
Reference in New Issue
Block a user