Add export of json file

This commit is contained in:
Claude Brisson
2024-01-26 09:07:06 +01:00
parent a4c55c82e2
commit 0c378af406
4 changed files with 54 additions and 6 deletions

View File

@@ -100,6 +100,28 @@ onLoad(() => {
});
$('#export').on('click', e => {
modal('export-modal');
});
$('#export-pairgoth').on('click', e => {
close_modal();
let form = $('#tournament-infos')[0];
let shortName = form.val('shortName');
let hdrs = headers();
hdrs['Accept'] = 'application/json';
fetch(`${base}tour/${tour_id}`, {
headers: hdrs
}).then(resp => {
if (resp.ok) return resp.text()
else throw "export error"
}).then(txt => {
let blob = new Blob(['\uFEFF', txt.trim()], {type: 'application/json;charset=utf-8'});
downloadFile(blob, `${shortName}.tour`);
}).catch(err => showError(err));
});
$('#export-opengotha').on('click', e => {
close_modal();
let form = $('#tournament-infos')[0];
let shortName = form.val('shortName');
let hdrs = headers();