Added channel overrides section to admin panel
This commit is contained in:
parent
68f9d5af06
commit
33026a1265
7 changed files with 113 additions and 42 deletions
|
|
@ -52,6 +52,23 @@ class canopyAdminUtils{
|
|||
utils.ux.displayResponseError(await response.json());
|
||||
}
|
||||
}
|
||||
|
||||
async setChannelOverride(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({channelPermissionsMap: Object.fromEntries(permMap)})
|
||||
});
|
||||
|
||||
if(response.status == 200){
|
||||
return await response.json();
|
||||
}else{
|
||||
utils.ux.displayResponseError(await response.json());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class adminUserList{
|
||||
|
|
@ -85,6 +102,7 @@ class adminUserList{
|
|||
class adminPermissionList{
|
||||
constructor(){
|
||||
this.permissionSelectors = document.querySelectorAll(".admin-perm-list-rank-select");
|
||||
this.channelPermissionSelectors = document.querySelectorAll(".admin-chan-perm-list-rank-select");
|
||||
|
||||
this.setupInput();
|
||||
}
|
||||
|
|
@ -93,6 +111,10 @@ class adminPermissionList{
|
|||
this.permissionSelectors.forEach((permissionSelector)=>{
|
||||
permissionSelector.addEventListener("change", this.setPerm.bind(this))
|
||||
});
|
||||
|
||||
this.channelPermissionSelectors.forEach((permissionSelector)=>{
|
||||
permissionSelector.addEventListener("change", this.setChanPerm.bind(this))
|
||||
});
|
||||
}
|
||||
|
||||
async setPerm(event){
|
||||
|
|
@ -101,12 +123,27 @@ class adminPermissionList{
|
|||
this.updateSelect(await adminUtil.setPermission(permMap), event.target);
|
||||
}
|
||||
|
||||
async setChanPerm(event){
|
||||
const permMap = new Map([[event.target.id.replace("admin-chan-perm-list-rank-select-",""), event.target.value]]);
|
||||
|
||||
this.updateChanSelect(await adminUtil.setChannelOverride(permMap), event.target);
|
||||
}
|
||||
|
||||
updateSelect(update, select){
|
||||
if(update != null){
|
||||
const perm = select.id.replace("admin-perm-list-rank-select-","");
|
||||
var perm = select.id.replace("admin-perm-list-rank-select-","");
|
||||
|
||||
select.value = update[perm];
|
||||
}
|
||||
}
|
||||
|
||||
updateChanSelect(update, select){
|
||||
if(update != null){
|
||||
var perm = select.id.replace("admin-chan-perm-list-rank-select-","");
|
||||
|
||||
select.value = update.channelOverrides[perm];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const adminUtil = new canopyAdminUtils();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue