Finished up with permissions list in adminPanel
This commit is contained in:
parent
bd24aae381
commit
ce34d2e4d7
|
|
@ -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();
|
||||
const permissionList = new adminPermissionList();
|
||||
Loading…
Reference in a new issue