users.createWindow(async () => { const usersComponent = users const View = new ViewWindow({ title: ` Gestion des utilisateurs`, width: "500px", height: "700px" }) loadUsers() function loadUsers() { View.setContent(`

Utilisateurs : Calcul en cours

Chargement en cours ...

`) const usersList = new Array() const users = get("US_ALL") const usersDiv = document.getElementById(`${View.getViewTitle()}_users`) const usersNumber = document.getElementById(`${View.getViewTitle()}_number`) const addButton = document.getElementById(`${View.getViewTitle()}_add`) addButton.addEventListener("click", () => { View.createPopup({ title: "Ajouter un utilisateur", content: `

Nom d'utilisateur

Nom d'affichage

Mot de passe

Permissions

Photo de profil

` }) const addCButton = document.getElementById("us-add-button") const username = document.getElementById("us-add-username") const displayname = document.getElementById("us-add-displayname") const password = document.getElementById("us-add-password") const picture = document.getElementById("us-add-picture") const permissions = document.getElementsByClassName("permissions")[0].children const returnInfo = new TextResponse("user-addreturn-info") addCButton.addEventListener("click", () => { var permissionsList = new Array() for(var permission of permissions) { console.log(permission.children[0].checked) if(permission.children[0].checked) { permissionsList.push(permission.children[0].id.replace("perm_", "")) } } post("US_ADD", { username: username.value, display_name: displayname.value, password: password.value, picture: picture.files[0], permissions: permissionsList }).then((answer) => { if(answer == "ALREADY_EXIST") { returnInfo.err("L'utilisateur existe déjà !") } else if(answer == "USERNAME_MISSING") { returnInfo.err("Le nom d'utilisateur est manquant !") } else if(answer == "DISPLAY_NAME_MISSING") { returnInfo.err("Le nom d'affichage est manquant !") } else if(answer == "PASSWORD_MISSING") { returnInfo.err("Le mot de passe est manquant !") } else { View.destroyPopup() loadUsers() } }) }) }) users.then(users => { users = new Map(JSON.parse(users)) for(var user of users) { user = user[1] console.log(user) const userComponent = new User({ username: user.username, display_name: user.display_name, picture: user.picture, permission: user.permission, window: View, component: usersComponent }) usersList.push(userComponent) } usersNumber.innerHTML = usersList.length const usersContent = new Array() for(var user of usersList) { usersContent.push(user.generateHTML()) } usersDiv.innerHTML = usersContent.join("") for(var user of usersList) { user.loadScript() } }) } })