2020-08-07 12:23:59 +02:00
|
|
|
// -- GESTION DU FORMULAIRE PERMETTANT DE SAISIR / ÉDITER LES INFOS DES UTILISATEURS ET DE LEUR ABONNEMENT
|
|
|
|
|
|
|
|
/// Vérifie que l'utilisateur est bien connecté, a le bon statut et le redirige vers le formulaire d'inscription si ce n'est pas le cas.
|
|
|
|
/// Si c'est ok, propose un moteur de recherche permettant de chercher un utilisateur
|
|
|
|
/// Si un id est passé par l'url on affiche les informations de l'utilisateur dans un formulaire permettant de l'éditer/supprimer.
|
|
|
|
/// Si pas d'id passé par l'url, on affiche un formulaire vide permettant d'en saisir un nouvel utilisateur
|
|
|
|
|
|
|
|
/// À ajouter :
|
|
|
|
/// - importation liste de comptes utilisateur à créer
|
2020-09-24 17:09:17 +02:00
|
|
|
/// - attribution d'un parrain à un utilisateur (via un moteur de recherche). Déjà prévu par le contrôleur.
|
2020-08-07 12:23:59 +02:00
|
|
|
|
|
|
|
// Fichier de configuration côté client :
|
|
|
|
import { apiUrl, availableLangs, theme } from "../../config/instance.js";
|
|
|
|
const lang=availableLangs[0];
|
2020-09-24 17:09:17 +02:00
|
|
|
const configUsers = require("../../config/users.js");
|
|
|
|
const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");
|
2020-08-07 12:23:59 +02:00
|
|
|
|
2020-09-24 17:09:17 +02:00
|
|
|
// Fonctions utiles au script :
|
|
|
|
import { getLocaly, removeLocaly } from "./tools/clientstorage.js";
|
2020-08-07 12:23:59 +02:00
|
|
|
import { addElement } from "./tools/dom.js";
|
|
|
|
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
|
|
|
|
import { empyForm, getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
|
2020-10-20 16:41:34 +02:00
|
|
|
import { dateFormat, getPassword, isEmpty, replaceAll } from "../../tools/main";
|
2020-08-07 12:23:59 +02:00
|
|
|
import { getUrlParams } from "./tools/url.js";
|
2020-10-20 16:41:34 +02:00
|
|
|
import { checkSession } from "./tools/users.js";
|
2020-08-07 12:23:59 +02:00
|
|
|
|
|
|
|
// Dictionnaires :
|
2020-10-06 16:34:17 +02:00
|
|
|
const { addOkMessage, serverError } = require("../../lang/"+lang+"/general");
|
|
|
|
const { infosAdminGodfather, infosAdminNbGodChilds, infosUserForAdmin, needBeConnected, searchUsersWithoutResult } = require("../../lang/"+lang+"/user");
|
|
|
|
const { infosExpiratedAdmin, infosNbDaysAdmin, infosPaymentsAdmin, isNotValided } = require("../../lang/"+lang+"/subscription");
|
2020-08-07 12:23:59 +02:00
|
|
|
|
|
|
|
// Principaux éléments du DOM manipulés :
|
|
|
|
const divMain = document.getElementById("main-content");
|
|
|
|
const divMessage = document.getElementById("message");
|
|
|
|
const divResponse = document.getElementById("response");
|
2020-09-24 17:09:17 +02:00
|
|
|
const divCrash = document.getElementById("crash");
|
2020-08-07 12:23:59 +02:00
|
|
|
const divSubscribeIntro = document.getElementById("subscribeIntro");
|
|
|
|
const divPaymentsInfos = document.getElementById("infosPayments");
|
|
|
|
const divGodchildsInfos = document.getElementById("infosGodchilds");
|
|
|
|
const formUser = document.getElementById("users");
|
|
|
|
const deleteCheckBox = document.getElementById("deleteOkLabel");
|
|
|
|
const validationCheckBox = document.getElementById("validationOkLabel");
|
|
|
|
const btnNewUser = document.getElementById("wantNewUser");
|
|
|
|
const newPassword = document.getElementById("newPassword");
|
|
|
|
const timeDifference = document.getElementById("timeDifference");
|
2020-09-24 17:09:17 +02:00
|
|
|
const formSearch = document.getElementById("searchUsers");
|
2020-08-07 12:23:59 +02:00
|
|
|
const divSearchResult = document.getElementById("searchResult");
|
|
|
|
|
2020-09-24 17:09:17 +02:00
|
|
|
helloDev();
|
|
|
|
|
2020-08-07 12:23:59 +02:00
|
|
|
const initialise = async () =>
|
|
|
|
{
|
|
|
|
try
|
2020-09-24 17:09:17 +02:00
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
const isConnected=await checkSession(["manager", "admin"], "/"+configTemplate.connectionPage, { message: needBeConnected, color:"error" }, window.location);
|
2020-09-24 17:09:17 +02:00
|
|
|
if(isConnected)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
const user=getLocaly("user", true);
|
|
|
|
updateAccountLink(user.status, configTemplate);
|
|
|
|
divMain.style.display="block";
|
|
|
|
if(!isEmpty(getLocaly("message")))
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
addElement(divMessage, "p", getLocaly("message", true).message, "", [getLocaly("message", true).color], "", false);
|
|
|
|
removeLocaly("message");
|
|
|
|
}
|
|
|
|
// Initialisation du formulaire de recherche :
|
|
|
|
setAttributesToInputs(configUsers, formSearch);
|
|
|
|
|
|
|
|
// Fonction utile pour vider le formulaire, y compris les champs hidden, etc.
|
|
|
|
// Cache aussi certains champs en mode création
|
|
|
|
const emptyUserForm = () =>
|
|
|
|
{
|
|
|
|
empyForm(formUser);
|
|
|
|
// Case de suppression cachée par défaut, car inutile pour formulaire de création
|
|
|
|
deleteCheckBox.style.display="none";
|
|
|
|
// Case de validation cachée par défaut, car utile que dans certains cas
|
|
|
|
validationCheckBox.style.display="none";
|
|
|
|
divSubscribeIntro.innerHTML="";
|
|
|
|
divPaymentsInfos.innerHTML="";
|
|
|
|
divGodchildsInfos.innerHTML="";
|
|
|
|
// Certains navigateurs ont tendance à remplir tout seul les champs configUsers.password
|
|
|
|
newPassword.value="";
|
|
|
|
// En mode création, pas de champ pour changer le mot de passe
|
|
|
|
newPassword.parentNode.style.display="none";
|
|
|
|
// Inutile en mode création
|
|
|
|
timeDifference.parentNode.style.display="none";
|
|
|
|
}
|
|
|
|
emptyUserForm();
|
|
|
|
// Initialise les contraintes du formulaire :
|
|
|
|
setAttributesToInputs(configUsers, formUser);
|
|
|
|
|
|
|
|
// Fonction affichant les infos connues concernant un utilisateur et son abonnement
|
|
|
|
const showFormUserInfos = (id) =>
|
|
|
|
{
|
|
|
|
// on commence par tout vider, des fois que... :
|
2020-08-07 12:23:59 +02:00
|
|
|
emptyUserForm();
|
2020-09-24 17:09:17 +02:00
|
|
|
const xhrGetInfos = new XMLHttpRequest();
|
|
|
|
xhrGetInfos.open("GET", apiUrl+configUsers.userRoutes+configUsers.getUserInfos+id);
|
|
|
|
xhrGetInfos.onreadystatechange = function()
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let response=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 200 && response.User != undefined)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
newPassword.parentNode.style.display="block";
|
|
|
|
timeDifference.parentNode.style.display="block";
|
|
|
|
const mapText =
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
ID_USER : response.User.id,
|
|
|
|
DATE_CREA : dateFormat(response.User.createdAt),
|
|
|
|
DATE_UPDATE : dateFormat(response.User.updatedAt),
|
|
|
|
DATE_CONNECTION : dateFormat(response.User.connectedAt)
|
|
|
|
};
|
2020-10-06 16:34:17 +02:00
|
|
|
let subscribeIntro=replaceAll(infosUserForAdmin, mapText);
|
2020-09-24 17:09:17 +02:00
|
|
|
for(let data in response.User)
|
|
|
|
{
|
|
|
|
if(formUser.elements[data]!==undefined)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(response.User[data]!==true && response.User[data]!==false)// booléen = case à cocher !
|
|
|
|
formUser.elements[data].value=response.User[data];
|
|
|
|
else if (response.User[data]==true) // si false, on ne fait rien
|
|
|
|
formUser.elements[""+data].checked="checked";
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
}
|
|
|
|
if(response.Subscription != undefined)
|
|
|
|
{
|
|
|
|
// nombre de jours de l'abonnement
|
|
|
|
formUser.elements["numberOfDays"].value=response.Subscription["numberOfDays"];
|
|
|
|
// jours de réception
|
|
|
|
for(let i in response.Subscription.receiptDays)
|
|
|
|
formUser.elements["d"+response.Subscription.receiptDays[i]].checked="checked";
|
|
|
|
const beginSubTS=new Date(response.Subscription.createdAt).getTime();
|
2020-12-07 16:42:39 +01:00
|
|
|
if(response.Subscription.numberOfDays !== 0)
|
|
|
|
{
|
|
|
|
const nbDaysOk=response.Subscription.numberOfDays-Math.round((Date.now()-beginSubTS)/1000/3600/24);
|
|
|
|
if(nbDaysOk > 0)
|
|
|
|
subscribeIntro+="<br>"+infosNbDaysAdmin.replace("NB_DAYS", nbDaysOk);
|
|
|
|
else
|
|
|
|
subscribeIntro+="<br>dd"+infosExpiratedAdmin;
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
addElement(divSubscribeIntro, "p", subscribeIntro, "", ["info"], "", false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divSubscribeIntro, "p", isNotValided, "", ["error"]);
|
2020-09-24 17:09:17 +02:00
|
|
|
validationCheckBox.style.display="block";
|
|
|
|
}
|
|
|
|
deleteCheckBox.style.display="block";
|
|
|
|
// Infos de paiements via API WP
|
|
|
|
const xhrGetPaymentsInfos = new XMLHttpRequest();
|
|
|
|
xhrGetPaymentsInfos.open("GET", apiUrl+configUsers.getPayments+response.User.id);
|
|
|
|
xhrGetPaymentsInfos.onreadystatechange = function()
|
|
|
|
{
|
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let responsePay=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 200)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(responsePay.length!==0)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let txtPayments="";
|
|
|
|
for(let i in responsePay)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
const mapText =
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
DATE_PAYMENT : dateFormat(responsePay[i].createdAt, "fr"),
|
|
|
|
AMOUNT : responsePay[i].amount,
|
|
|
|
CLIENT_NAME : responsePay[i].clientName
|
|
|
|
};
|
2020-10-06 16:34:17 +02:00
|
|
|
txtPayments+="<li>"+replaceAll(infosNbDaysAdmin, mapText)+"</li>";
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
addElement(divPaymentsInfos, "ul", txtPayments, "", ["info"], "", false);
|
|
|
|
divPaymentsInfos.style.display="block"
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
}
|
|
|
|
xhrGetPaymentsInfos.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
xhrGetPaymentsInfos.send();
|
|
|
|
|
|
|
|
// Un parrain ou deux par deux ?
|
|
|
|
if(!isEmpty(response.User.GodfatherId))
|
|
|
|
{
|
|
|
|
const xhrGetGodFatherInfos = new XMLHttpRequest();
|
|
|
|
xhrGetGodFatherInfos.open("GET", apiUrl+configUsers.userRoutes+configUsers.getUserInfos+response.User.GodfatherId);
|
|
|
|
xhrGetGodFatherInfos.onreadystatechange = function()
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let responseGF=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 200 && responseGF.User != undefined)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divGodchildsInfos, "p", infosAdminGodfather+"<a href='/"+configTemplate.usersManagementPage+"?id="+responseGF.User.id+"'>"+responseGF.User.name+"</a>"+".<br>", "", ["info"], "", false);
|
2020-09-24 17:09:17 +02:00
|
|
|
divGodchildsInfos.style.display="block";
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
xhrGetGodFatherInfos.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
xhrGetGodFatherInfos.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Des filleuls ?
|
|
|
|
let txtGodchilds="";
|
|
|
|
const xhrGetGodchilds = new XMLHttpRequest();
|
|
|
|
xhrGetGodchilds.open("GET", apiUrl+configUsers.userRoutes+configUsers.getGodChilds+id);
|
|
|
|
xhrGetGodchilds.onreadystatechange = function()
|
|
|
|
{
|
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let responseGS=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 200)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(responseGS.length!==0)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
txtGodchilds+=infosAdminGodfather.replace("#NB", responseGS.length);
|
2020-09-24 17:09:17 +02:00
|
|
|
for(let i in responseGS)
|
|
|
|
txtGodchilds+="<a href='/"+configTemplate.usersManagementPage+"?id="+responseGS[i].id+"'>"+responseGS[i].name+"</a>";
|
|
|
|
addElement(divGodchildsInfos, "p", txtGodchilds+".", "", ["info"], "", false);
|
|
|
|
divGodchildsInfos.style.display="block";
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
xhrGetGodchilds.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
xhrGetGodchilds.send();
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
xhrGetInfos.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
xhrGetInfos.send();
|
|
|
|
}
|
2020-08-07 12:23:59 +02:00
|
|
|
|
2020-09-24 17:09:17 +02:00
|
|
|
// Si un id est passé par l'url, on essaye d'afficher l'utilisateur :
|
|
|
|
let urlDatas=getUrlParams();
|
|
|
|
if(urlDatas && urlDatas.id!==undefined)
|
|
|
|
showFormUserInfos(urlDatas.id);
|
2020-08-07 12:23:59 +02:00
|
|
|
|
2020-09-24 17:09:17 +02:00
|
|
|
// Besoin d'un coup de Kärcher ?
|
|
|
|
btnNewUser.addEventListener("click", function(e)
|
|
|
|
{
|
|
|
|
emptyUserForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Envoi du formulaire des infos de l'utilisateur
|
|
|
|
formUser.addEventListener("submit", function(e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
divResponse.innerHTML="";
|
|
|
|
let datas=getDatasFromInputs(formUser);
|
|
|
|
// recomposition des jours valables pour l'abonnement :
|
|
|
|
datas.receiptDays="";
|
|
|
|
for(let i=1; i<=7; i++)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(datas["d"+i]!==undefined)
|
|
|
|
datas.receiptDays+=""+i;
|
|
|
|
}
|
|
|
|
const xhrUserDatas = new XMLHttpRequest();
|
|
|
|
if(!isEmpty(datas.id) && (datas.deleteOk!==undefined))
|
|
|
|
xhrUserDatas.open("DELETE", apiUrl+configUsers.userRoutes+"/"+datas.id);
|
|
|
|
else if(!isEmpty(datas.id) && (datas.validationOk!==undefined))
|
|
|
|
xhrUserDatas.open("POST", apiUrl+configUsers.userRoutes+configUsers.validateUserRoute+datas.id);
|
|
|
|
else if(!isEmpty(datas.id))
|
|
|
|
xhrUserDatas.open("PUT", apiUrl+configUsers.userRoutes+configUsers.updateUserInfos+datas.id);
|
|
|
|
else
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
datas.password=getPassword(configUsers.password.minlength, configUsers.password.minlength+2);// mot de passe temporaire
|
|
|
|
xhrUserDatas.open("POST", apiUrl+configUsers.userRoutes+configUsers.createUserRoute);
|
|
|
|
}
|
|
|
|
xhrUserDatas.onreadystatechange = function()
|
|
|
|
{
|
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let response=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 201 && response.id!=undefined)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divResponse, "p", addOkMessage, "", ["success"]);
|
2020-09-24 17:09:17 +02:00
|
|
|
datas.id=response.id;
|
|
|
|
}
|
|
|
|
else if (this.status === 200 && response.message!=undefined)
|
|
|
|
{
|
|
|
|
if(Array.isArray(response.message))
|
|
|
|
response.message = response.message.join("<br>");
|
2020-08-07 12:23:59 +02:00
|
|
|
else
|
2020-09-24 17:09:17 +02:00
|
|
|
response.message = response.message;
|
|
|
|
addElement(divResponse, "p", response.message, "", ["success"]);
|
|
|
|
}
|
|
|
|
else if (response.errors)
|
|
|
|
{
|
|
|
|
if(Array.isArray(response.errors))
|
|
|
|
response.errors = response.errors.join("<br>");
|
|
|
|
else
|
2020-10-06 16:34:17 +02:00
|
|
|
response.errors = serverError;
|
2020-09-24 17:09:17 +02:00
|
|
|
addElement(divResponse, "p", response.errors, "", ["error"]);
|
|
|
|
}
|
|
|
|
else
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divResponse, "p", serverError, "", ["error"]);
|
2020-09-24 17:09:17 +02:00
|
|
|
if(isEmpty(response.errors))
|
|
|
|
{
|
|
|
|
if(datas.deleteOk===undefined)
|
|
|
|
showFormUserInfos(datas.id);
|
|
|
|
else
|
|
|
|
emptyUserForm();
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
}
|
|
|
|
xhrUserDatas.setRequestHeader("Content-Type", "application/json");
|
|
|
|
xhrUserDatas.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
if(datas)
|
|
|
|
xhrUserDatas.send(JSON.stringify(datas));
|
|
|
|
});
|
2020-08-07 12:23:59 +02:00
|
|
|
|
2020-09-24 17:09:17 +02:00
|
|
|
// Traitement du lancement d'une recherche
|
|
|
|
formSearch.addEventListener("submit", function(e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
let datas=getDatasFromInputs(formSearch);
|
|
|
|
const xhrSearch = new XMLHttpRequest();
|
|
|
|
xhrSearch.open("POST", apiUrl+configUsers.userRoutes+configUsers.searchUserRoute);
|
|
|
|
xhrSearch.onreadystatechange = function()
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if (this.readyState == XMLHttpRequest.DONE)
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let response=JSON.parse(this.responseText);
|
|
|
|
if (this.status === 200 && Array.isArray(response))
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(response.length===0)
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divSearchResult, "p", searchUsersWithoutResult, "", ["info"]);
|
2020-09-24 17:09:17 +02:00
|
|
|
else
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
let selectHTML="<option value=''></option>";
|
|
|
|
for(let i in response)
|
|
|
|
selectHTML+="<option value='"+response[i].id+"'>"+response[i].name+" ("+response[i].email+")</option>";
|
|
|
|
addElement(divSearchResult, "select", selectHTML, "selectSearch");
|
|
|
|
const searchSelect=document.getElementById("selectSearch");
|
|
|
|
searchSelect.addEventListener("change", function()
|
2020-08-07 12:23:59 +02:00
|
|
|
{
|
2020-09-24 17:09:17 +02:00
|
|
|
if(searchSelect.value!=="")
|
|
|
|
showFormUserInfos(searchSelect.value);
|
|
|
|
});
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
else
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divSearchResult, "p", serverError, "", ["error"]);
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
2020-09-24 17:09:17 +02:00
|
|
|
}
|
|
|
|
xhrSearch.setRequestHeader("Content-Type", "application/json");
|
|
|
|
xhrSearch.setRequestHeader("Authorization", "Bearer "+user.token);
|
|
|
|
if(datas)
|
|
|
|
xhrSearch.send(JSON.stringify(datas));
|
|
|
|
});
|
2020-08-07 12:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
2020-10-06 16:34:17 +02:00
|
|
|
addElement(divCrash, "p", serverError, "", ["error"]);
|
2020-08-07 12:23:59 +02:00
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initialise();
|