Let user specify encoding for export

This commit is contained in:
Claude Brisson
2024-03-01 12:58:27 +01:00
parent d991d28116
commit 4780953ff5
5 changed files with 48 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ Dates Dates
Download Télécharger
Download the standalone web interface module which suits your need, then follow Télécharger le module dinterface web qui correspond à vos besoins, puis suivez
Edit Éditer
Encoding Encodage
Enter the magic word Entrer le mot magique
Export Exporter
Export tournament Exporter le tournoi

View File

@@ -1,15 +1,18 @@
function publish(format, extension) {
let form = $('#tournament-infos')[0];
let shortName = form.val('shortName');
let encoding = $('#encoding')[0].value;
let hdrs = headers();
hdrs['Accept'] = `application/${format}`
hdrs['Accept'] = `application/${format};charset=${encoding}`
fetch(`api/tour/${tour_id}/standings/${activeRound}`, {
headers: hdrs
}).then(resp => {
if (resp.ok) return resp.text()
if (resp.ok) return resp.arrayBuffer()
else throw "publish error"
}).then(txt => {
let blob = new Blob(['\uFEFF', txt.trim()], {type: 'text/plain;charset=utf-8'});
}).then(bytes => {
let blob = new Blob(
encoding === 'utf-8' ? ['\uFEFF', bytes] : [bytes],
{ type: `text/plain;charset=${encoding}` });
downloadFile(blob, `${shortName}.${extension}`);
close_modal();
}).catch(err => showError(err));

View File

@@ -88,7 +88,10 @@
</table>
</div>
<div class="right form-actions">
<button id="publish" class="ui yellow floating button">Publish</button>
<button id="publish" class="ui yellow floating right labeled icon button">
<i class="paper plane outline icon"></i>
Publish
</button>
</div>
</div>
<div id="publish-modal" class="popup">
@@ -97,12 +100,23 @@
Publish standings
</div>
<div class="popup-content">
<div class="horz">
<span>Choose format</span>
<button type="button" class="ui blue floating publish-html button">HTML</button>
<button type="button" class="ui blue floating publish-egf button">EGF</button>
<button type="button" class="ui blue floating publish-ffg button">FFG</button>
</div>
<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">
<label>Choose format</label>
<div class="inline fields">
<button type="button" class="ui blue floating publish-html button">HTML</button>
<button type="button" class="ui blue floating publish-egf button">EGF</button>
<button type="button" class="ui blue floating publish-ffg button">FFG</button>
</div>
</div>
</form>
</div>
<div class="popup-footer">
<div class="form-actions">