correction change select

This commit is contained in:
Valentin CZERYBA 2022-08-25 14:57:42 +02:00
parent 8405947254
commit 4012655671
2 changed files with 76 additions and 57 deletions

View File

@ -21,6 +21,57 @@ function checkToken(){
}
function buildParam(e, id){
var search = document.getElementById("searchUser").value;
var param = "";
var listParam = ["page", "nbPages"];
if(id.length > 0){
var select = document.getElementById(id);
var getId = select.options[select.selectedIndex].value;
if(id == "inputRoles"){
var status = e.target.value;
if(status != "-2"){
param = param + "status="+status+"&";
}
if(getId != "All"){
param = param + "roles="+getId;
}
}
if(id == "inputStatus"){
var roles = e.target.value;
if(getId != "-2"){
param = param + "status="+getId+"&";
}
if(roles != "All"){
param = param + "roles="+roles+"&";
}
}
} else {
listParam.push("roles");
listParam.push("status");
}
if(search.length > 0){
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(search)){
param = param + "email="+search+"&";
} else if(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(search)){
param = param + "uuid="+search+"&";
} else {
param = param + "search="+search+"&";
}
} else {
listParam.push("email"); listParam.push("uuid"); listParam.push("search");
}
for (var i=0; i<listParam.length; i++){
var query = getQuery(listParam[i]);
if(query.length > 0){
param = param + listParam[i]+"="+query+"&";
}
}
return param;
}
function signOut(){
document.getElementById("signout").addEventListener("click", function(){

View File

@ -4,6 +4,27 @@ var param = {}
param["nbPages"] = 20;
var search = getQuery("search");
if(search.length > 0){
document.getElementById("searchUser").value=search;
}
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);
}
}
}
}
instance.get("users/count", { withCredentials: true }).then(function(response){
var count = response.data / param["nbPages"];
@ -107,71 +128,18 @@ document.getElementById("addUser").addEventListener("click", function(){
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)){
location.href="/html/users.html?email="+search;
} else if(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(search)){
location.href="/html/users.html?uuid="+search;
} else {
location.href="/html/users.html?search="+search;
}
var param = buildParam(e, "");
location.href="/html/users.html?"+param;
}
});
document.getElementById("inputStatus").addEventListener("change", function(e){
var search = document.getElementById("searchUser").value;
var select = document.getElementById("inputRoles");
var roles = select.options[select.selectedIndex].value;
var param = "";
var page = getQuery("page");
if(page.length > 0){
param = param + "page="+page+"&";
}
var nbPages = getQuery("nbPages");
if(nbPages.length > 0 ){
param = param+ "nbPages="+nbPages+"&";
}
if(search.length > 0){
param = param + "search="+search+"&";
}
var status = e.target.value;
if(status != "-2"){
param = param + "status="+status+"&";
}
if(roles != "All"){
param = param + "roles="+roles;
}
var param = buildParam(e, "inputRoles");
location.href="/html/users.html?"+param;
});
document.getElementById("inputRoles").addEventListener("change", function(e){
var search = document.getElementById("searchUser").value;
var select = document.getElementById("inputStatus");
var status = select.options[select.selectedIndex].value;
var param = "";
var page = getQuery("page");
if(page.length > 0){
param = param + "page="+page+"&";
}
var nbPages = getQuery("nbPages");
if(nbPages.length > 0 ){
param = param + "nbPages="+nbPages+"&";
}
if(search.length > 0){
param = param + "search="+search+"&";
}
if(status != "-2"){
param = param + "status="+status+"&";
}
var roles = e.target.value;
if(roles != "All"){
param = param + "roles="+roles;
}
console.log(param);
var param = buildParam(e, "inputStatus");
location.href="/html/users.html?"+param;
});