From 4012655671552bb0c3a8533bc86e7945e74b0b67 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Aug 2022 14:57:42 +0200 Subject: [PATCH] correction change select --- web/js/library.js | 51 +++++++++++++++++++++++++++++ web/js/users.js | 82 +++++++++++++++-------------------------------- 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/web/js/library.js b/web/js/library.js index ec96ccd..970812f 100644 --- a/web/js/library.js +++ b/web/js/library.js @@ -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 0){ + param = param + listParam[i]+"="+query+"&"; + } + } + return param; +} + function signOut(){ document.getElementById("signout").addEventListener("click", function(){ diff --git a/web/js/users.js b/web/js/users.js index a943c7a..0eec69f 100644 --- a/web/js/users.js +++ b/web/js/users.js @@ -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 0){ + + var listOption = document.querySelectorAll("#"+listQuery[i]["id"]+" option"); + for(var j=0; j 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; });