From ce34d2e4d777261370974050e01ec5801bb335fe Mon Sep 17 00:00:00 2001 From: rainbownapkin Date: Tue, 19 Nov 2024 05:15:20 -0500 Subject: [PATCH] Finished up with permissions list in adminPanel --- www/js/adminPanel.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/www/js/adminPanel.js b/www/js/adminPanel.js index 2813ccf..3d0f9e2 100644 --- a/www/js/adminPanel.js +++ b/www/js/adminPanel.js @@ -36,14 +36,14 @@ class canopyAdminUtils{ } } - async setPermission(permObj){ + async setPermission(permMap){ var response = await fetch(`/api/admin/permissions`,{ method: "POST", headers: { "Content-Type": "application/json" }, //Unfortunately JSON doesn't natively handle ES6 maps, and god forbid someone update the standard in a way that's backwards compatible... - body: JSON.stringify({permissionsMap: Object.fromEntries(permObj)}) + body: JSON.stringify({permissionsMap: Object.fromEntries(permMap)}) }); if(response.status == 200){ @@ -82,5 +82,33 @@ class adminUserList{ } +class adminPermissionList{ + constructor(){ + this.permissionSelectors = document.querySelectorAll(".admin-perm-list-rank-select"); + + this.setupInput(); + } + + setupInput(){ + this.permissionSelectors.forEach((permissionSelector)=>{ + permissionSelector.addEventListener("change", this.setPerm.bind(this)) + }); + } + + async setPerm(event){ + const permMap = new Map([[event.target.id.replace("admin-perm-list-rank-select-",""), event.target.value]]); + + this.updateSelect(await adminUtil.setPermission(permMap), event.target); + } + + updateSelect(update, select){ + if(update != null){ + const perm = select.id.replace("admin-perm-list-rank-select-",""); + select.value = update[perm]; + } + } +} + const adminUtil = new canopyAdminUtils(); -const userList = new adminUserList(); \ No newline at end of file +const userList = new adminUserList(); +const permissionList = new adminPermissionList(); \ No newline at end of file