add latitude and longitude

This commit is contained in:
Valentin CZERYBA 2023-11-20 23:16:56 +01:00
parent b1d0eb2994
commit 6149a8683d
4 changed files with 36 additions and 6 deletions

View File

@ -130,12 +130,12 @@
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4"> <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="alert alert-warning alert-dismissible hidden" id="notModifiedAlert" role="alert"> <div class="alert alert-warning alert-dismissible hidden" id="notModifiedAlert" role="alert">
<div>Utilisateur non ajouté, car le pseudo ou l'adresse mail existe déjà</div> <div>Evènement non ajouté, car le pseudo ou l'adresse mail existe déjà</div>
<button type="button" class="btn-close" aria-label="Close"></button> <button type="button" class="btn-close" aria-label="Close"></button>
</div> </div>
<div class="alert alert-success alert-dismissible hidden" id="createUserAlert" role="alert"> <div class="alert alert-success alert-dismissible hidden" id="createUserAlert" role="alert">
<div>Vous avez créée l'utilisateur <span id="displayUser"></span></div> <div>Vous avez créée l'évènement <span id="displayUser"></span></div>
<button type="button" class="btn-close" aria-label="Close"></button> <button type="button" class="btn-close" aria-label="Close"></button>
</div> </div>

View File

@ -62,7 +62,9 @@ document.getElementById("addUser").addEventListener("click", function(){
"place": document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value, "place": document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value,
"start_date": document.getElementById("start_dateUpdateInput").value, "start_date": document.getElementById("start_dateUpdateInput").value,
"end_date": document.getElementById("end_dateUpdateInput").value, "end_date": document.getElementById("end_dateUpdateInput").value,
"organizers":organizers "organizers":organizers,
"latitude": document.getElementById("placeUpdateInput").getAttribute("data-latitude"),
"longitude": document.getElementById("placeUpdateInput").getAttribute("data-longitude")
}; };
break; break;
default: default:
@ -80,7 +82,18 @@ document.getElementById("addUser").addEventListener("click", function(){
switch(response.status){ switch(response.status){
case 201: case 201:
idAlert="createUser" idAlert="createUser"
var user = document.getElementById("usernameUpdateInput").value; switch (pathURL){
case "user":
input = "username";
break;
case "event":
input = "name";
break;
default:
input = "";
break;
}
var user = document.getElementById(input+"UpdateInput").value;
if(user.length > 0){ if(user.length > 0){
document.getElementById("displayUser").textContent=user; document.getElementById("displayUser").textContent=user;
} }
@ -95,7 +108,7 @@ document.getElementById("addUser").addEventListener("click", function(){
document.getElementById(idAlert+"Alert").classList.remove("hidden"); document.getElementById(idAlert+"Alert").classList.remove("hidden");
}).catch(function(error){ }).catch(function(error){
console.log(error); console.log(error);
switch(error.response.status){ switch(error.status){
case 401: case 401:
listExist = [ "username", "email" ]; listExist = [ "username", "email" ];
for(var i=0; i<listExist.length; i++){ for(var i=0; i<listExist.length; i++){

View File

@ -4,4 +4,17 @@ accessToken: mapboxgl.accessToken,
types: 'country,region,place,postcode,locality,neighborhood,poi' types: 'country,region,place,postcode,locality,neighborhood,poi'
}); });
geocoder.addTo('#placeUpdateInput'); geocoder.addTo('#placeUpdateInput');
place = document.getElementById("placeUpdateInput");
geocoder.on("result", (e) => {
place.setAttribute("data-latitude", e.result.center[1]);
place.setAttribute("data-longitude", e.result.center[0]);
});
geocoder.on("clear", () => {
place.setAttribute("data-latitude", "");
place.setAttribute("data-longitude", "");
});

View File

@ -25,6 +25,8 @@ if(id.length > 0){
switch(listValue[i]){ switch(listValue[i]){
case "place": case "place":
document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value = response.data[listValue[i]]; document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value = response.data[listValue[i]];
document.getElementById("placeUpdateInput").setAttribute("data-latitude", response.data["latitude"]);
document.getElementById("placeUpdateInput").setAttribute("data-longitude", response.data["longitude"])
break; break;
case "organizers": case "organizers":
if (response.data[listValue[i]].length > 0 ){ if (response.data[listValue[i]].length > 0 ){
@ -202,6 +204,8 @@ if(id.length > 0){
"id": document.getElementById("idUpdateInput").value, "id": document.getElementById("idUpdateInput").value,
"name": document.getElementById("nameUpdateInput").value, "name": document.getElementById("nameUpdateInput").value,
"place": document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value, "place": document.getElementsByClassName("mapboxgl-ctrl-geocoder--input")[0].value,
"latitude": document.getElementById("placeUpdateInput").getAttribute("data-latitude"),
"longitude": document.getElementById("placeUpdateInput").getAttribute("data-longitude"),
"start_date": document.getElementById("start_dateUpdateInput").value, "start_date": document.getElementById("start_dateUpdateInput").value,
"end_date": document.getElementById("end_dateUpdateInput").value, "end_date": document.getElementById("end_dateUpdateInput").value,
"status": selector["status"], "status": selector["status"],