covas-bo/web/js/user.js
2022-08-06 22:48:00 +02:00

53 lines
1.7 KiB
JavaScript

checkToken();
signOut();
var id = getQuery("id");
if(id.length > 0){
instance.get("users/"+id, {withCredentials: true})
.then(function(response){
var listValue = [ "id", "pseudo", "name", "firstName", "email", "birth"];
for (var i=0; i<listValue.length; i++){
document.getElementById(listValue[i]+"UpdateInput").value=response.data[listValue[i]];
}
var listSelector = ["roles", "status"];
for (var i=0; i<listSelector.length; i++){
var select = document.getElementById(listSelector[i]+"Selector").querySelectorAll("option");
for (var j=0; j<select.length; j++){
if(select[j].value == response.data[listSelector[i]]){
select[j].setAttribute("selected", true);
}
}
}
var buttonUser = "";
switch(response.data.status){
case 1:
buttonUser = "disableUser";
break;
case 2:
buttonUser = "enableUser";
break;
case -1:
buttonUser = "cancelUser";
document.getElementById("removeUser").classList.add("hidden");
break;
case 0:
buttonUser = "enableUser";
break;
default:
break;
}
if(buttonUser.length > 0){
console.log(disableUser);
document.getElementById(buttonUser).classList.remove("hidden");
}
})
.catch(function(error){
console.log(error);
});
}