covas-bo/web/js/library.js

128 lines
3.6 KiB
JavaScript
Raw Normal View History

2022-07-25 20:35:54 +02:00
function checkToken(){
instance.get("token", { withCredentials: true})
.then(function(response) {
2022-07-28 00:15:57 +02:00
if(location.pathname == "/")
{
2022-08-06 21:48:41 +02:00
location.href="/html/users.html";
}
})
2022-07-25 20:35:54 +02:00
.catch(function(error){
2022-07-28 00:15:57 +02:00
if(location.pathname != "/"){
location.href="/";
}
2022-08-14 19:32:40 +02:00
if(error.response.status == 406){
instance.delete("token" , {withCredentials:true}).then(function(response){
location.reload();
});
}
2022-07-25 20:35:54 +02:00
});
2022-08-04 00:03:57 +02:00
}
2022-08-25 14:57:42 +02:00
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"){
2023-10-28 13:05:29 +02:00
param = param + "key=status&value="+status+"&";
2022-08-25 14:57:42 +02:00
}
if(getId != "All"){
2023-10-28 13:05:29 +02:00
param = param + "key=roles&value="+getId;
2022-08-25 14:57:42 +02:00
}
}
if(id == "inputStatus"){
var roles = e.target.value;
if(getId != "-2"){
2023-10-28 13:05:29 +02:00
param = param + "key=status&value="+getId+"&";
2022-08-25 14:57:42 +02:00
}
if(roles != "All"){
2023-10-28 13:05:29 +02:00
param = param + "key=roles&value="+roles+"&";
2022-08-25 14:57:42 +02:00
}
}
} 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;
}
2022-08-04 00:03:57 +02:00
function signOut(){
document.getElementById("signout").addEventListener("click", function(){
instance.delete("token" , {withCredentials:true}).then(function(response){
2022-08-14 19:32:40 +02:00
if(response.status == 200) {
location.href="/";
2022-08-04 00:03:57 +02:00
}
});
2022-08-14 19:32:40 +02:00
});
2022-08-05 21:20:14 +02:00
}
2022-08-11 00:12:52 +02:00
function closeButton(){
var btnclose = document.getElementsByClassName("btn-close");
for (var i = 0; i<btnclose.length; i++){
btnclose[i].addEventListener("click", function(e){
var parent = e.currentTarget.parentElement;
if(!parent.classList.contains("hidden")){
parent.classList.add("hidden");
}
});
}
}
2022-08-05 21:20:14 +02:00
function getQuery(param){
var result = "";
2022-08-25 22:21:02 +02:00
if(location.search.length > 0){
2022-08-05 23:39:15 +02:00
query = location.search.split("?")[1];
var variables = query.split("&")
for (var i=0; i<variables.length; i++){
if(variables[i].split("=")[0] == param){
result = variables[i].split("=")[1];
}
2022-08-05 21:20:14 +02:00
}
}
return result;
2022-08-25 22:21:02 +02:00
}
function updateParam(param, value){
var result = "";
if(location.search.length > 0){
query = location.search.split("?")[1];
var variables = query.split("&");
for (var i=0; i<variables.length; i++){
var data = variabes[i];
if(variables[i].split("=")[0] == param){
data = param+"="+value;
}
result = result + "&" + data;
}
}
return result;
2022-07-25 20:35:54 +02:00
}