add user fonctionnel
This commit is contained in:
parent
ecbc87a061
commit
c1248b0363
@ -148,6 +148,12 @@
|
||||
<span class="input-group-text" id="emailUpdate">Email</span>
|
||||
<input id="emailUpdateInput" type="text" class="form-control" placeholder="Email" aria-label="Email" aria-describedby="emailUpdate">
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text" id="birthUpdate">Date de naissance</span>
|
||||
<input id="birthUpdateInput" type="date" class="form-control" placeholder="Date de naissance" aria-label="Date de naissance" aria-describedby="birthdateUpdate">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="input-group mb-3">
|
||||
@ -160,7 +166,7 @@
|
||||
|
||||
|
||||
<div class="d-grid gap-2 col-6 mx-auto">
|
||||
<button type="button" class="btn btn-success" id="addUser" data-bs-toggle="modal" data-bs-target="#enableUserModal">Activer l'utilisateur</button>
|
||||
<button type="button" class="btn btn-success" id="addUser">Ajouter l'utilisateur</button>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,2 +1,75 @@
|
||||
checkToken();
|
||||
signOut();
|
||||
signOut();
|
||||
|
||||
|
||||
document.getElementById("addUser").addEventListener("click", function(){
|
||||
var updateProfil = ["pseudo", "email", "firstName", "birth", "password"];
|
||||
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": ""};
|
||||
var listSelector = [ "roles"];
|
||||
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": "",
|
||||
"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": 1,
|
||||
"password": document.getElementById("passwordUpdateInput").value,
|
||||
"roles": selector["roles"],
|
||||
"created_at": "",
|
||||
"updated_at": "",
|
||||
"deleted_at": "",
|
||||
"connected_at": ""
|
||||
|
||||
}
|
||||
instance({
|
||||
method : "put",
|
||||
url:"users",
|
||||
withCredentials: true,
|
||||
data: dataPut
|
||||
}).then(function(response){
|
||||
switch(response.status){
|
||||
case 200:
|
||||
location.reload();
|
||||
break;
|
||||
case 204:
|
||||
console.log("Aucun contenu");
|
||||
break;
|
||||
case 401:
|
||||
console.log("non autorisé");
|
||||
break;
|
||||
case 403:
|
||||
console.log("interdit");
|
||||
break;
|
||||
case 500:
|
||||
console.log("erreur interne");
|
||||
break;
|
||||
default:
|
||||
console.log("error inconnue");
|
||||
break
|
||||
}
|
||||
}).catch(function(error){
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
@ -52,10 +52,12 @@ if (pageCurrent.length > 0){
|
||||
}
|
||||
|
||||
instance.get("users", {withCredentials: true, params :{ page:page, nbPages: nbPages}}).then(function(response){
|
||||
var trTag = document.querySelector("#users tbody tr").cloneNode(true);
|
||||
listData = response.data;
|
||||
for (var i=0; i<listData.length; i++){
|
||||
var trTag = document.querySelector("#users tbody tr").cloneNode(true);
|
||||
console.log(listData[i]);
|
||||
if(i != 0){
|
||||
console.log(i);
|
||||
document.querySelector("#users tbody").append(trTag);
|
||||
}
|
||||
var trAll = document.querySelectorAll("#users tbody tr")
|
||||
@ -82,6 +84,7 @@ instance.get("users", {withCredentials: true, params :{ page:page, nbPages: nbPa
|
||||
classTd = ".unknownStatus"
|
||||
break;
|
||||
}
|
||||
td[4].querySelector(".activeStatus").classList.add("hidden");
|
||||
td[4].querySelector(classTd).classList.remove("hidden");
|
||||
|
||||
trAll[i].addEventListener("click", function(e){
|
||||
|
Loading…
x
Reference in New Issue
Block a user