Ajout du frontend et branchement sur l'API axione #9

Merged
felix.baylac merged 21 commits from johan/frontend into master 2022-02-13 19:39:12 +01:00
Showing only changes of commit 3fe2a4af9c - Show all commits

View file

@ -35,7 +35,7 @@
<form method="post" action="/test/pto">
<div class="form-group" id="ptoForm">
<label class="form-label" for="pto-number">Numéro PTO</label>
<input required type="text" class="form-control" name="pto" id="pto-number" aria-describedby="ptoHelp"
<input autofocus required type="text" class="form-control" name="pto" id="pto-number" aria-describedby="ptoHelp"
placeholder="OOOO-XXXX-XXXX" oninvalid="this.setCustomValidity('Veuillez renseigner le PTO')"
oninput="setCustomValidity('')">
@ -139,15 +139,21 @@
fetch(api, { signalCommunes })
.then(response => response.json())
.then(data => {
valueMatch=false;
if (JSON.stringify(data) !== JSON.stringify(communes)) {
$("#communes").empty();
communes = data
communes.forEach(commune => {
value=commune.codeZip + ' ' + commune.nom
$("#communes").append("<option codeInsee=" + commune.codeInsee + " value='" +
commune.codeZip + ' ' + commune.nom + "'></option>");
value + "'></option>");
if (value === search) {
valueMatch=true;
}
});
}
if (communes.length == 1) {
if (communes.length == 1 || valueMatch) {
codeInsee = communes[0].codeInsee;
$('#voieForm').collapse('show');
} else {
@ -156,10 +162,6 @@
}
})
.catch(err => {
if (err.name === "AbortError") {
console.log("DEBUG: updateCommunes aborted !")
}
console.error("Error fetching communes:", err)
})
}
@ -173,30 +175,29 @@
fetch(api, { signalVoies })
.then(response => response.json())
.then(data => {
valueMatch=false;
if (JSON.stringify(data) !== JSON.stringify(voies)) {
$("#voies").empty();
voies = Object.entries(data);
console.log(voies)
let voie;
for (i in voies) {
voie = voies[i]
$("#voies").append("<option id=" + voie[1] + " value='" +
voie[0] + "'></option>");
if (voie[0] === search) {
valueMatch=true;
}
}
console.log(voies)
if (voies.length == 1) {
if (voies.length == 1 || valueMatch) {
$('#btnTestAdresse').collapse('show');
voie = voies[0]
$('#btnTestAdresse').focus();
} else {
$('#btnTestAdresse').collapse('hide');
}
}
})
.catch(err => {
if (err.name === "AbortError") {
console.log("DEBUG: updateCommunes aborted !")
}
console.error("Error fetching communes:", err)
})
}
@ -204,10 +205,16 @@
$('#communeInput').trigger('input')
$('#communeInput').trigger('keyup')
});
$('#methodAddress').on('shown.bs.collapse', function () {
$('#communeInput').focus();
});
$('#voieForm').on('show.bs.collapse', function () {
$('#voieInput').trigger('input')
$('#voieInput').trigger('keyup')
});
$('#voieForm').on('shown.bs.collapse', function () {
$('#numeroVoieInput').focus();
});
$('#communeInput').on('keyup', function () {
controllerCommunes.abort();
@ -232,7 +239,6 @@
});
$('#formAddressTest').submit(function(eventObj) {
console.log("SUBMIT",$('#formAddressTest'))
$('#formAddressTest').append(`<input type="hidden" class="form-control" name="codeInsee" value="${codeInsee}" />`);
return true;
});