covas-bo/web/js/home.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

checkToken();
2022-08-04 00:03:57 +02:00
signOut();
2022-07-29 23:55:42 +02:00
var nbPages = 20;
2022-07-28 00:15:57 +02:00
2022-07-29 23:55:42 +02:00
instance.get("users/count", { withCredentials: true }).then(function(response){
var count = response.data / nbPages;
var reste = response.data % nbPages;
var total = 0;
2022-07-28 00:15:57 +02:00
if(reste != 0){
2022-07-29 23:55:42 +02:00
total = Number.parseInt(count) + 1;
}
if(total > 1){
document.getElementById("page").classList.remove("hidden");
2022-07-28 00:15:57 +02:00
}
2022-07-26 00:08:33 +02:00
2022-07-28 00:49:23 +02:00
});
2022-07-29 23:55:42 +02:00
instance.get("users", {withCredentials: true, params :{ page:0, 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++){
if(i != 0){
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
2022-08-04 23:19:26 +02:00
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-04 00:03:57 +02:00
td[4].querySelector(classTd).classList.remove("hidden");
2022-08-02 22:44:34 +02:00
trAll[i].addEventListener("click", function(e){
2022-08-05 23:39:15 +02:00
var id = e.currentTarget.querySelector("td").textContent;
location.href="/html/users.html?id="+id;
2022-08-02 22:44:34 +02:00
});
2022-07-29 23:55:42 +02:00
}
});
2022-07-28 00:49:23 +02:00
2022-08-02 22:44:34 +02:00