Files
pairgoth/view-webapp/src/main/webapp/index.html
2024-03-07 05:43:45 +01:00

154 lines
4.2 KiB
HTML

<div class="actions section">
<a href="tour" class="ui blue icon floating button">
<i class="fa fa-plus-square-o"></i>
New tournament
</a>
<a id="import-tournament" class="ui orange icon floating button">
<i class="fa fa-upload"></i>
Import tournament
</a>
<a id="example-tournament" class="ui green icon floating button">
<i class="fa fa-copy"></i>
Clone example tournament
</a>
</div>
<div class="tournaments section">
#set($files = $api.get('tour'))
#if($files.containsKey('error'))
#set($error = $files.error)
#elseif($files.containsKey('message'))
#set($error = $files.message)
#end
#if($error)
<script type="text/javascript">
onLoad(()=>{
showError("$esc.html($error)");
});
</script>
#else
#foreach($tour in $files.entrySet())
<a href="tour?id=${tour.key}" class="ui open basic secondary white icon floating button" title="id $tour.key, last modified $tour.value.lastModified">
<i class="fa fa-folder-open-o"></i>
$tour.value.name
</a>
#end
#end
</div>
<div id="import-popup" class="popup">
<div class="popup-body">
<form id="import-form" class="ui form">
<div class="popup-content">
<div class="field">
<label>OpenGotha / Pairgoth file</label>
<input type="file" name="file" accept=".tour,.xml"/>
</div>
</div>
<div class="popup-footer">
<button id="cancel-import" type="button" class="ui gray right labeled icon floating close button">
<i class="times icon"></i>
Cancel
</button>
<button id="import" type="button" class="ui green right labeled icon floating button">
<i class="plus icon"></i>
Import
</button>
</div>
</form>
</div>
</div>
<div id="clone-popup" class="popup">
<div class="popup-body">
<form id="clone-form" class="ui form">
<div class="popup-content">
<div class="field">
<label>Example tournament</label>
<select id="exampleTournamentName">
<option value=""></option>
#foreach($tour in $utils.exampleTournaments)
<option value="$tour">$tour</option>
#end
</select>
</div>
</div>
<div class="popup-footer">
<button id="cancel-clone" type="button" class="ui gray right labeled icon floating close button">
<i class="times icon"></i>
Cancel
</button>
<button id="clone" type="button" class="ui green right labeled icon floating button">
<i class="plus icon"></i>
Clone
</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
// #[[
function doImport() {
let form = $('#import-form')[0];
let formData = new FormData(form);
fetch('/api/import', {
method: 'POST',
body: formData
}).then(resp => {
if (resp.ok) return resp.json();
else throw resp;
}).then(json => {
if (json.success) {
console.log(`/tour?id=${json.id}`)
document.location.href = `/tour?id=${json.id}`
} else {
showError(json.error || 'unknown error')
}
}).catch(err => {
error(err);
});
}
function doClone(name) {
fetch(`/api/import?example=${name}`, {
method: 'POST',
body: {}
}).then(resp => {
if (resp.ok) return resp.json();
else throw resp;
}).then(json => {
if (json.success) {
console.log(`/tour?id=${json.id}`)
document.location.href = `/tour?id=${json.id}`
} else {
showError(json.error || 'unknown error')
}
}).catch(err => {
error(err);
});
}
onLoad(()=>{
$('#import-tournament').on('click', e => {
modal('import-popup');
e.preventDefault();
return false;
});
$('#import').on('click', e => {
let files = $('#import-form input')[0].files;
if (files.length > 0) {
doImport();
} else showError('no file choosen');
close_modal();
});
$('#example-tournament').on('click', e => {
modal('clone-popup');
e.preventDefault();
return false;
});
$('#clone').on('click', e => {
let example = $('#exampleTournamentName')[0].value;
doClone(example);
});
});
// ]]#
</script>