Remove encoding choice at export, choose encoding automatically

This commit is contained in:
Claude Brisson
2024-05-30 09:18:09 +02:00
parent 3cdc93316c
commit fbd8db08df
2 changed files with 5 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
function publish(format, extension) { function publish(format, extension, encoding) {
let form = $('#tournament-infos')[0]; let form = $('#tournament-infos')[0];
let shortName = form.val('shortName'); let shortName = form.val('shortName');
let encoding = $('#encoding')[0].value;
let hdrs = headers(); let hdrs = headers();
hdrs['Accept'] = `${format};charset=${encoding}` hdrs['Accept'] = `${format};charset=${encoding}`
fetch(`api/tour/${tour_id}/standings/${activeRound}`, { fetch(`api/tour/${tour_id}/standings/${activeRound}`, {
@@ -10,9 +9,7 @@ function publish(format, extension) {
if (resp.ok) return resp.arrayBuffer() if (resp.ok) return resp.arrayBuffer()
else throw "publish error" else throw "publish error"
}).then(bytes => { }).then(bytes => {
let blob = new Blob( let blob = new Blob([bytes], { type: `text/plain;charset=${encoding}` });
encoding === 'utf-8' ? ['\uFEFF', bytes] : [bytes],
{ type: `text/plain;charset=${encoding}` });
downloadFile(blob, `${shortName}.${extension}`); downloadFile(blob, `${shortName}.${extension}`);
close_modal(); close_modal();
}).catch(err => showError(err)); }).catch(err => showError(err));
@@ -77,13 +74,13 @@ onLoad(() => {
}); });
*/ */
$('.publish-ffg').on('click', e => { $('.publish-ffg').on('click', e => {
publish('application/ffg', 'tou'); publish('application/ffg', 'tou', 'iso-8859-1');
}); });
$('.publish-egf').on('click', e => { $('.publish-egf').on('click', e => {
publish('application/egf', 'h' + (typeof(correction) === 'number' && correction > 0 ? correction : 9 )); publish('application/egf', 'h' + (typeof(correction) === 'number' && correction > 0 ? correction : 9 ), 'iso-8859-1');
}); });
$('.publish-csv').on('click', e => { $('.publish-csv').on('click', e => {
publish('text/csv', 'csv'); publish('text/csv', 'csv', 'utf-8');
}); });
$('.publish-html').on('click', e => { $('.publish-html').on('click', e => {
publishHtml(); publishHtml();

View File

@@ -104,13 +104,6 @@
<div class="warning">Warning: publishing partial results at round <span>$round</span> out of <span>$tour.rounds</span>!</div> <div class="warning">Warning: publishing partial results at round <span>$round</span> out of <span>$tour.rounds</span>!</div>
#end #end
<form class="ui edit form"> <form class="ui edit form">
<div class="field">
<label>Encoding</label>
<select id="encoding">
<option value="utf-8">UTF-8</option>
<option value="iso-8859-1">ISO 8859-1</option>
</select>
</div>
<div class="field"> <div class="field">
<label>Choose format</label> <label>Choose format</label>
<div class="inline fields"> <div class="inline fields">