Update writeBadge JS script

This commit is contained in:
jarjar 2023-05-31 09:08:50 +00:00
parent e2c3392ff9
commit e6ca31fbec

View File

@ -25,28 +25,23 @@
</html>
<script>
if ({{nbBadge}} >= 1) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/copyBadge/{{uid}}', true);
xhr.onload = function() {
var jsonreponse = JSON.parse(xhr.response);
if (jsonreponse.status == "OK") {
//console.log("Badge cloné")
fetch(`/copyBadge/{{uid}}`)
.then(response => response.json())
.then(jsonresponse => {
if (jsonresponse.status == "OK") {
if ({{nbBadge-1}} == 0) {
window.location.href = "/wait?raison=Tous%20les%20badges%20sont%20copi%C3%A9s%20%21&redirect=/";
}
else{
window.location.href = "/wait?raison=Badge%20clon%C3%A9%20%21%20Appuyer%20sur%20le%20bouton%20pour%20passer%20au%20badge%20suivant.&redirect=/writeBadge/{{nbBadge-1}}/{{uid}}";
} else {
window.location.href = `/wait?raison=Badge%20clon%C3%A9%20%21%20Appuyer%20sur%20le%20bouton%20pour%20passer%20au%20badge%20suivant.&redirect=/writeBadge/{{nbBadge-1}}/{{uid}}`;
}
} else {
window.location.href = "/writeBadge/{{nbBadge}}/{{uid}}" + "?error=" + jsonreponse.message;
throw new Error(jsonresponse.message);
}
};
xhr.send(null);
})
.catch(error => {
window.location.href = `/writeBadge/{{nbBadge}}/{{uid}}?error=${error.message}`;
});
} else {
window.location.href = "/"
window.location.href = "/";
}
</script>