diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/download-report/download-report.js b/src/Bundle/ChillMainBundle/Resources/public/lib/download-report/download-report.js index 8b3429f28..afbbe071a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/download-report/download-report.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/download-report/download-report.js @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -var mime = require('mime'); +import mime from 'mime'; -var download_report = (url, container) => { +export const download_report = (url, container) => { var download_text = container.dataset.downloadText, alias = container.dataset.alias; @@ -43,7 +43,7 @@ var download_report = (url, container) => { content = URL.createObjectURL(blob); } - extension = 'xlsx';//mime.extension(type); + extension = mime.getExtension(type); link.appendChild(document.createTextNode(download_text)); link.classList.add("btn", "btn-action"); @@ -63,5 +63,3 @@ var download_report = (url, container) => { .replaceChild(problem_text, container.firstChild); }); }; - -module.exports = download_report; diff --git a/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js b/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js new file mode 100644 index 000000000..a0559fdad --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/page/export/download-export.js @@ -0,0 +1,16 @@ +import {download_report} from "../../lib/download-report/download-report"; + +window.addEventListener("DOMContentLoaded", function(e) { + const export_generate_url = window.export_generate_url; + + if (typeof export_generate_url === 'undefined') { + console.error('Alias not found!'); + throw new Error('Alias not found!'); + } + + const query = window.location.search, + container = document.querySelector("#download_container") + ; + + download_report(export_generate_url + "?" + query.toString(), container); +}); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig index bd7dbf7e9..13d064691 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Export/download.html.twig @@ -22,15 +22,13 @@ {% block js %} +{{ encore_entry_link_tags('page_download_exports') }} +{% endblock %} + +{% block css %} + {{ encore_entry_script_tags('page_download_exports') }} {% endblock %} {% block content %} diff --git a/src/Bundle/ChillMainBundle/chill.webpack.config.js b/src/Bundle/ChillMainBundle/chill.webpack.config.js index 287e6ae89..6576b2e0b 100644 --- a/src/Bundle/ChillMainBundle/chill.webpack.config.js +++ b/src/Bundle/ChillMainBundle/chill.webpack.config.js @@ -52,12 +52,14 @@ module.exports = function(encore, entries) Tabs: __dirname + '/Resources/public/lib/tabs' }); + // Page entrypoints encore.addEntry('page_login', __dirname + '/Resources/public/page/login/index.js'); encore.addEntry('page_location', __dirname + '/Resources/public/page/location/index.js'); encore.addEntry('page_workflow_show', __dirname + '/Resources/public/page/workflow-show/index.js'); encore.addEntry('page_homepage_widget', __dirname + '/Resources/public/page/homepage_widget/index.js'); encore.addEntry('page_export', __dirname + '/Resources/public/page/export/index.js'); + encore.addEntry('page_download_exports', __dirname + '/Resources/public/page/export/download-export.js'); buildCKEditor(encore);