From 519d73fefef9ee6e91d940c93cc4382028c5ae4d Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Wed, 27 Dec 2023 11:39:50 +0100 Subject: [PATCH] Export in progress --- .../src/main/webapp/WEB-INF/translations/fr | 1 + view-webapp/src/main/webapp/js/main.js | 34 +++++-------------- .../main/webapp/js/tour-information.inc.js | 16 +++++++++ .../src/main/webapp/tour-information.inc.html | 4 +++ 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/view-webapp/src/main/webapp/WEB-INF/translations/fr b/view-webapp/src/main/webapp/WEB-INF/translations/fr index 18e600a..bef15cd 100644 --- a/view-webapp/src/main/webapp/WEB-INF/translations/fr +++ b/view-webapp/src/main/webapp/WEB-INF/translations/fr @@ -32,6 +32,7 @@ Download Télécharger Download the standalone web interface module which suits your need, then follow Télécharger le module d’interface web qui correspond à vos besoins, puis suivez Edit Éditer Enter the magic word Entrer le mot magique +Export Exporter Family name Nom de famille First name Prénom Fischer timing Cadence Fisher diff --git a/view-webapp/src/main/webapp/js/main.js b/view-webapp/src/main/webapp/js/main.js index 6059fd3..de56bc4 100644 --- a/view-webapp/src/main/webapp/js/main.js +++ b/view-webapp/src/main/webapp/js/main.js @@ -163,34 +163,16 @@ function close_modal() { $(`.popup`).removeClass('shown'); } -function screenshot() { - const bodyContent = document.body.innerHTML; - - // Create an SVG element - const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - svg.setAttribute('width', window.innerWidth); - svg.setAttribute('height', window.innerHeight); - - // Create a foreignObject element - const foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject'); - foreignObject.setAttribute('width', '100%'); - foreignObject.setAttribute('height', '100%'); - - // Append the body content to foreignObject - foreignObject.innerHTML = bodyContent; - - // Append foreignObject to the SVG - svg.appendChild(foreignObject); - - // Create a data URL from the SVG - const dataUrl = 'data:image/svg+xml,' + encodeURIComponent(new XMLSerializer().serializeToString(svg)); - - // Open the screenshot in a new window/tab (optional) - const screenshotWindow = window.open(); - screenshotWindow.document.write('Screenshot'); +function downloadFile(blob, filename) { + let url = URL.createObjectURL(blob); + link.setAttribute("href", url); + link.setAttribute("download", filename); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } - onLoad(() => { $('button.close').on('click', e => { let modal = e.target.closest('.popup'); diff --git a/view-webapp/src/main/webapp/js/tour-information.inc.js b/view-webapp/src/main/webapp/js/tour-information.inc.js index e4b6347..0dca709 100644 --- a/view-webapp/src/main/webapp/js/tour-information.inc.js +++ b/view-webapp/src/main/webapp/js/tour-information.inc.js @@ -99,6 +99,22 @@ onLoad(() => { overwrite: true }); + $('#export').on('click', e => { + let form = $('#tournament-infos')[0]; + let shortName = form.val('shortName'); + let headers = headers(); + headers['Accept'] = 'application/xml'; + fetch(`${base}tour/${tour_id}`, { + headers: headers + }).then(resp => { + if (resp.ok) return resp.text() + else throw "export error" + }).then(txt => { + let blob = new Blob(['\uFEFF', txt], {type: 'application/xml;charset=utf-8'}); + downloadFile(blob, `${shortName}.xml`); + }).catch(err => showError(err)); + }); + $('#tournament-infos').on('submit', e => { e.preventDefault(); let form = e.target; diff --git a/view-webapp/src/main/webapp/tour-information.inc.html b/view-webapp/src/main/webapp/tour-information.inc.html index e1e6f58..4078372 100644 --- a/view-webapp/src/main/webapp/tour-information.inc.html +++ b/view-webapp/src/main/webapp/tour-information.inc.html @@ -215,6 +215,10 @@ Close +