update profile wip

This commit is contained in:
Valentin CZERYBA 2022-08-11 00:12:52 +02:00
parent 10e5747e22
commit e52ed75ea3
4 changed files with 96 additions and 13 deletions

View File

@ -117,6 +117,28 @@
</nav>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="alert alert-danger alert-dismissible hidden" id="pseudoAlert" role="alert">
<div>Champ pseudo vide</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="emailAlert" role="alert">
<div>Champ email vide</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="firstNameAlert" role="alert">
<div>Champ prenom vide</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="nameAlert" role="alert">
<div>Champ nom vide</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Utilisateur</h1>
</div>
@ -128,7 +150,12 @@
<div class="input-group mb-3">
<span class="input-group-text" id="pseudoUpdate">Pseudo</span>
<input id="pseudoUpdateInput" type="text" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="pseudoUpdate">
<input id="pseudoUpdateInput" type="text" class="form-control" placeholder="Mot de passe" aria-label="Mot de passe" aria-describedby="pseudoUpdate">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="passwordUpdate">Mot de passe</span>
<input id="passwordUpdateInput" type="password" class="form-control" placeholder="Pseudo" aria-label="Pseudo" aria-describedby="passwordUpdate">
</div>
<div class="input-group mb-3">

View File

@ -27,6 +27,19 @@ function signOut(){
});
}
function closeButton(){
var btnclose = document.getElementsByClassName("btn-close");
for (var i = 0; i<btnclose.length; i++){
btnclose[i].addEventListener("click", function(e){
var parent = e.currentTarget.parentElement;
if(!parent.classList.contains("hidden")){
parent.classList.add("hidden");
}
});
}
}
function getQuery(param){
var result = "";

View File

@ -1,4 +1,5 @@
checkToken();
closeButton();
document.getElementById("signin").addEventListener("submit", function(evt){
evt.preventDefault();
@ -38,14 +39,4 @@ document.getElementById("signin").addEventListener("submit", function(evt){
}
});
var btnclose = document.getElementsByClassName("btn-close");
for (var i = 0; i<btnclose.length; i++){
btnclose[i].addEventListener("click", function(){
var alertt = document.getElementsByClassName("alert");
for (var j=0; j<alertt.length; j++){
if(!alertt[j].classList.contains("hidden")){
alertt[j].classList.add("hidden");
}
}
});
}

View File

@ -1,5 +1,6 @@
checkToken();
signOut();
closeButton();
var id = getQuery("id");
if(id.length > 0){
@ -98,7 +99,58 @@ if(id.length > 0){
});
document.getElementById("updateUserButton").addEventListener("click", function(){
var updateProfil = ["id", "pseudo", "email", "firstName", "birth"];
var updateOk = true;
for (var i=0; i<updateProfil.length; i++){
if(document.getElementById(updateProfil[i]+"UpdateInput").value.length == 0){
updateOk = false;
document.getElementById(updateProfil[i]+"Alert").classList.remove("hidden");
}
}
if(updateOk){
var selector = { "roles": "", "status": 0};
var listSelector = [ "roles", "status"];
for (var i=0; i<listSelector.length; i++){
var options = document.querySelectorAll("#"+listSelector[i]+"Selector option");
for (var j=0; j<options.length; j++){
if(options[j].selected){
selector[listSelector[i]] = options[j].value;
}
}
}
dataPut = {
"id": id,
"pseudo": document.getElementById("pseudoUpdateInput").value,
"email": document.getElementById("emailUpdateInput").value,
"name": document.getElementById("nameUpdateInput").value,
"firstName": document.getElementById("firstNameUpdateInput").value,
"birth": document.getElementById("birthUpdateInput").value,
"status": selector["status"],
"password": document.getElementById("passwordUpdateInput").value,
"roles": selector["roles"],
"created_at": "",
"updated_at": "",
"deleted_at": "",
"connected_at": ""
}
instance({
method : "put",
url:"users/"+id,
withCredentials: true,
data: dataPut
}).then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
});
}
});
}