2022-08-04 00:03:57 +02:00
|
|
|
checkToken();
|
2022-08-05 21:20:14 +02:00
|
|
|
signOut();
|
2022-08-06 21:48:41 +02:00
|
|
|
|
|
|
|
var nbPages = 20;
|
|
|
|
|
|
|
|
instance.get("users/count", { withCredentials: true }).then(function(response){
|
|
|
|
|
|
|
|
var count = response.data / nbPages;
|
|
|
|
var reste = response.data % nbPages;
|
|
|
|
var total = 0;
|
|
|
|
if(reste != 0){
|
|
|
|
total = Number.parseInt(count) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(total > 1){
|
|
|
|
document.getElementById("page").classList.remove("hidden");
|
2022-08-07 17:21:26 +02:00
|
|
|
var pageCurrent = getQuery("page");
|
|
|
|
var page = 1;
|
|
|
|
if(pageCurrent.length > 0){
|
|
|
|
page = Number.parseInt(pageCurrent);
|
|
|
|
}
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2022-08-07 17:21:26 +02:00
|
|
|
|
|
|
|
for (var i=0; i<total; i++){
|
|
|
|
var liPage = document.querySelectorAll(".page-item")[i+1];
|
|
|
|
var cloneLi = liPage.cloneNode(true);
|
|
|
|
liPage.after(cloneLi);
|
|
|
|
var newPage = i + 2;
|
|
|
|
var aPage = document.querySelectorAll(".page-item")[newPage].querySelector("a");
|
|
|
|
aPage.text=newPage;
|
|
|
|
aPage.href="/html/users.html?page="+newPage;
|
|
|
|
}
|
|
|
|
document.querySelectorAll(".page-item")[page].classList.add("active");
|
|
|
|
if(page != 1){
|
|
|
|
document.querySelectorAll(".page-item")[0].classList.remove("disabled");
|
|
|
|
}
|
|
|
|
if(page == total){
|
|
|
|
document.querySelectorAll(".page-item")[page].classList.add("disabled");
|
|
|
|
}
|
2022-08-06 21:48:41 +02:00
|
|
|
}
|
2022-08-07 17:21:26 +02:00
|
|
|
|
2022-08-06 21:48:41 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-08-07 17:27:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
var page = 0;
|
|
|
|
var pageCurrent = getQuery("page");
|
|
|
|
if (pageCurrent.length > 0){
|
|
|
|
page = Number.parseInt(pageCurrent);
|
|
|
|
page = page - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance.get("users", {withCredentials: true, params :{ page:page, nbPages: nbPages}}).then(function(response){
|
2022-08-06 21:48:41 +02:00
|
|
|
listData = response.data;
|
|
|
|
for (var i=0; i<listData.length; i++){
|
2022-08-12 22:17:39 +02:00
|
|
|
var trTag = document.querySelector("#users tbody tr").cloneNode(true);
|
|
|
|
console.log(listData[i]);
|
2022-08-06 21:48:41 +02:00
|
|
|
if(i != 0){
|
2022-08-12 22:17:39 +02:00
|
|
|
console.log(i);
|
2022-08-06 21:48:41 +02:00
|
|
|
document.querySelector("#users tbody").append(trTag);
|
|
|
|
}
|
|
|
|
var trAll = document.querySelectorAll("#users tbody tr")
|
|
|
|
td = trAll[i].querySelectorAll("td");
|
|
|
|
td[0].textContent = listData[i].id;
|
|
|
|
td[1].textContent = listData[i].pseudo
|
|
|
|
td[2].textContent = listData[i].email
|
|
|
|
td[3].textContent = listData[i].roles
|
|
|
|
var classTd = "";
|
|
|
|
switch(listData[i].status){
|
|
|
|
case 1:
|
|
|
|
classTd = ".activeStatus";
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
classTd = ".disableStatus";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
classTd = ".confirmStatus";
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
classTd = ".removeStatus";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
classTd = ".unknownStatus"
|
|
|
|
break;
|
|
|
|
}
|
2022-08-12 22:17:39 +02:00
|
|
|
td[4].querySelector(".activeStatus").classList.add("hidden");
|
2022-08-06 21:48:41 +02:00
|
|
|
td[4].querySelector(classTd).classList.remove("hidden");
|
|
|
|
|
|
|
|
trAll[i].addEventListener("click", function(e){
|
|
|
|
var id = e.currentTarget.querySelector("td").textContent;
|
2022-08-06 21:49:47 +02:00
|
|
|
location.href="/html/user.html?id="+id;
|
2022-08-06 21:48:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-08-12 21:40:29 +02:00
|
|
|
document.getElementById("addUser").addEventListener("click", function(){
|
|
|
|
location.href="/html/adduser.html";
|
2022-08-15 18:24:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("searchUser").addEventListener("keydown", function(ev){
|
|
|
|
if(ev.key === "Enter"){
|
|
|
|
var search = document.getElementById("searchUser").value;
|
|
|
|
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(search)){
|
2022-08-15 23:41:10 +02:00
|
|
|
alert("mail");
|
|
|
|
} else if(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(search)){
|
|
|
|
alert("uuid");
|
|
|
|
} else {
|
|
|
|
alert("other");
|
2022-08-15 18:24:15 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 19:21:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("inputStatus").addEventListener("change", function(e){
|
2022-08-23 00:33:37 +02:00
|
|
|
var search = document.getElementById("searchUser").value;
|
|
|
|
var select = document.getElementById("inputRoles");
|
|
|
|
var roles = select.options[select.selectedIndex].value;
|
|
|
|
alert(e.target.value+" "+roles+" "+search);
|
2022-08-16 19:21:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("inputRoles").addEventListener("change", function(e){
|
2022-08-23 00:33:37 +02:00
|
|
|
var search = document.getElementById("searchUser").value;
|
|
|
|
var select = document.getElementById("inputStatus");
|
|
|
|
var status = select.options[select.selectedIndex].value;
|
|
|
|
alert(e.target.value+" "+status+" "+search);
|
2022-08-12 21:40:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2022-08-16 19:21:13 +02:00
|
|
|
|