rename file and remove console.log

This commit is contained in:
2022-08-06 21:48:41 +02:00
parent a327443c37
commit 106ff00ce3
7 changed files with 206 additions and 206 deletions

View File

@@ -1,65 +0,0 @@
checkToken();
signOut();
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");
}
});
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
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;
}
td[4].querySelector(classTd).classList.remove("hidden");
trAll[i].addEventListener("click", function(e){
var id = e.currentTarget.querySelector("td").textContent;
location.href="/html/users.html?id="+id;
});
}
});

View File

@@ -4,7 +4,7 @@ function checkToken(){
.then(function(response) {
if(location.pathname == "/")
{
location.href="/html/home.html";
location.href="/html/users.html";
}
})
.catch(function(error){

View File

@@ -7,7 +7,7 @@ document.getElementById("signin").addEventListener("submit", function(evt){
var password = document.getElementById("floatingPassword");
if((password.value.length > 0) || (pseudo.value.length > 0)){
instance.get("token", { auth : {username: pseudo.value, password: password.value}, withCredentials: true})
.then(function(response) { location.href="html/home.html"; })
.then(function(response) { location.href="html/users.html"; })
.catch(function(error){
switch (error.response.status){

29
web/js/user.js Normal file
View File

@@ -0,0 +1,29 @@
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);
}
}
}
})
.catch(function(error){
console.log(error);
});
}

View File

@@ -1,29 +1,65 @@
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 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");
}
});
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
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;
}
td[4].querySelector(classTd).classList.remove("hidden");
trAll[i].addEventListener("click", function(e){
var id = e.currentTarget.querySelector("td").textContent;
location.href="/html/users.html?id="+id;
});
}
});
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);
}
}
}
})
.catch(function(error){
console.log(error);
});
}