2022-08-04 00:03:57 +02:00
|
|
|
checkToken();
|
2022-08-05 21:20:14 +02:00
|
|
|
signOut();
|
2022-08-25 01:13:17 +02:00
|
|
|
var param = {}
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2023-10-21 21:42:01 +02:00
|
|
|
param["limit"] = 20;
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2022-08-25 22:50:59 +02:00
|
|
|
var listSearch = [ "email", "uuid", "search"];
|
|
|
|
for(var i=0; i<listSearch.length; i++){
|
|
|
|
var search = getQuery(listSearch[i]);
|
|
|
|
if(search.length > 0){
|
|
|
|
document.getElementById("searchUser").value=search;
|
|
|
|
}
|
2022-08-25 14:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var listQuery = [{"query": "roles", "id":"inputRoles"}, {"query":"status", "id":"inputStatus"}]
|
|
|
|
|
|
|
|
for (var i=0; i<listQuery.length; i++){
|
|
|
|
var query = getQuery(listQuery[i]["query"]);
|
|
|
|
if(query.length > 0){
|
|
|
|
|
|
|
|
var listOption = document.querySelectorAll("#"+listQuery[i]["id"]+" option");
|
|
|
|
for(var j=0; j<listOption.length; j++){
|
|
|
|
if(query == listOption[j].value){
|
|
|
|
listOption[j].setAttribute("selected", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-06 21:48:41 +02:00
|
|
|
instance.get("users/count", { withCredentials: true }).then(function(response){
|
|
|
|
|
2023-10-21 21:42:01 +02:00
|
|
|
var count = response.data["count"] / param["limit"];
|
|
|
|
var reste = response.data["count"] % param["limit"];
|
2022-08-06 21:48:41 +02:00
|
|
|
var total = 0;
|
|
|
|
if(reste != 0){
|
|
|
|
total = Number.parseInt(count) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(total > 1){
|
|
|
|
document.getElementById("page").classList.remove("hidden");
|
2023-10-21 21:42:01 +02:00
|
|
|
var pageCurrent = getQuery("skip");
|
2022-08-07 17:21:26 +02:00
|
|
|
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;
|
2022-08-25 22:50:59 +02:00
|
|
|
var newPage = updateParam("page", newpage);
|
|
|
|
aPage.href="/html/users.html?"+newPage;
|
2022-08-07 17:21:26 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-10-21 21:42:01 +02:00
|
|
|
param["skip"] = 0;
|
|
|
|
var pageCurrent = getQuery("skip");
|
2022-08-07 17:27:31 +02:00
|
|
|
if (pageCurrent.length > 0){
|
2023-10-21 21:42:01 +02:00
|
|
|
param["skip"] = Number.parseInt(pageCurrent);
|
|
|
|
param["skip"] = param["skip"] - 1;
|
2022-08-25 01:13:17 +02:00
|
|
|
}
|
|
|
|
|
2023-10-30 23:41:58 +01:00
|
|
|
var listQuery = ["search", "id", "roles", "status", "email"];
|
2022-08-25 01:13:17 +02:00
|
|
|
for (var i=0; i<listQuery.length; i++){
|
|
|
|
var query = getQuery(listQuery[i]);
|
|
|
|
if(query.length > 0){
|
|
|
|
param[listQuery[i]]=query;
|
|
|
|
}
|
2022-08-07 17:27:31 +02:00
|
|
|
}
|
|
|
|
|
2023-10-30 23:41:58 +01:00
|
|
|
instance.get("users", {withCredentials: true, params:param}).then(function(response){
|
2022-08-25 22:08:03 +02:00
|
|
|
var listData = response.data;
|
|
|
|
if(!Array.isArray(listData)){
|
|
|
|
var listData = []
|
|
|
|
listData.push(response.data);
|
|
|
|
}
|
2023-11-02 17:29:12 +01:00
|
|
|
if(listData.length > 0 ){
|
|
|
|
var listModalButton = ["disable", "enable", "remove"];
|
|
|
|
|
|
|
|
for (var i=0; i<listModalButton.length; i++){
|
|
|
|
document.getElementById(listModalButton[i]+"UserButton").addEventListener("click", function(e){
|
|
|
|
var httpMethod = ""
|
|
|
|
var httpUrl = "";
|
|
|
|
param = {};
|
|
|
|
userids= [];
|
|
|
|
checkboxList = document.getElementsByClassName("checkboxList");
|
|
|
|
for (var j=0; j<checkboxList.length; j++){
|
|
|
|
if(checkboxList[j].checked){
|
|
|
|
userid = checkboxList.getAttribute("userid");
|
|
|
|
if (userid.length > 0){
|
|
|
|
userids.push(userid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
param["userids"]=userids;
|
|
|
|
|
|
|
|
switch(e.currentTarget.id){
|
|
|
|
case "disableUserButton":
|
|
|
|
httpMethod = "delete";
|
|
|
|
httpUrl = "users/groups";
|
|
|
|
break;
|
|
|
|
case "removeUserButton":
|
|
|
|
httpMethod = "delete";
|
|
|
|
httpUrl = "users/groups?remove=true";
|
|
|
|
param["remove"]=true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
httpMethod = "patch";
|
|
|
|
httpUrl = "users/groups";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
instance({
|
|
|
|
method: httpMethod,
|
|
|
|
url: httpUrl,
|
|
|
|
params:param,
|
|
|
|
withCredentials: true
|
|
|
|
})
|
|
|
|
.then(function(response){
|
|
|
|
if(response.status == 200){
|
|
|
|
location.href="/html/users.html";
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function(error){
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 21:48:41 +02:00
|
|
|
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);
|
2022-08-06 21:48:41 +02:00
|
|
|
if(i != 0){
|
|
|
|
document.querySelector("#users tbody").append(trTag);
|
|
|
|
}
|
|
|
|
var trAll = document.querySelectorAll("#users tbody tr")
|
|
|
|
td = trAll[i].querySelectorAll("td");
|
2023-10-31 17:26:30 +01:00
|
|
|
td[0].querySelector("input").setAttribute("userid", listData[i].id)
|
2023-10-31 00:25:59 +01:00
|
|
|
td[1].textContent = listData[i].id;
|
|
|
|
td[2].textContent = listData[i].username;
|
|
|
|
td[3].textContent = listData[i].email;
|
|
|
|
td[4].textContent = listData[i].roles;
|
2022-08-06 21:48:41 +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;
|
|
|
|
}
|
2023-10-31 00:25:59 +01:00
|
|
|
td[5].querySelector(".activeStatus").classList.add("hidden");
|
|
|
|
td[5].querySelector(classTd).classList.remove("hidden");
|
2023-10-31 17:06:30 +01:00
|
|
|
|
|
|
|
td[6].querySelector("button").setAttribute("userid", listData[i].id)
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2023-10-31 17:06:30 +01:00
|
|
|
td[6].querySelector("button").addEventListener("click", function(e){
|
|
|
|
var id = e.currentTarget.getAttribute("userid");
|
2022-08-06 21:49:47 +02:00
|
|
|
location.href="/html/user.html?id="+id;
|
2022-08-06 21:48:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2023-10-31 17:26:30 +01:00
|
|
|
document.getElementById("checkboxPrincipal").addEventListener("click", function(e){
|
|
|
|
listCheck = document.getElementsByClassName("checkboxList");
|
|
|
|
var checkPrincipal = e.currentTarget.checked;
|
|
|
|
for (var i=0; i<listCheck.length; i++){
|
|
|
|
listCheck[i].checked = checkPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
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"){
|
2022-08-25 22:50:59 +02:00
|
|
|
var param = buildParam("", "");
|
2022-08-25 14:57:42 +02:00
|
|
|
location.href="/html/users.html?"+param;
|
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-25 14:57:42 +02:00
|
|
|
var param = buildParam(e, "inputRoles");
|
2022-08-25 01:41:06 +02:00
|
|
|
location.href="/html/users.html?"+param;
|
2022-08-16 19:21:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("inputRoles").addEventListener("change", function(e){
|
2022-08-25 14:57:42 +02:00
|
|
|
var param = buildParam(e, "inputStatus");
|
2022-08-25 01:41:06 +02:00
|
|
|
location.href="/html/users.html?"+param;
|
2022-08-25 01:13:17 +02:00
|
|
|
});
|
2022-08-12 21:40:29 +02:00
|
|
|
|
|
|
|
|
2022-08-06 21:48:41 +02:00
|
|
|
|
2022-08-16 19:21:13 +02:00
|
|
|
|