mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
feat: adds FastEndpoints endpoints, views and resources to the web project
This commit is contained in:
1 parent
733e174cac
commit
d3b1c681dc
341 files changed
+44018
-113
No files matched your search
@@ -0,0 +1,232 @@
|
||||
@*
|
||||
/admin/manage-permissions/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.DTO.Authorization
|
||||
@using Lumina.Presentation.Web.Common.DTO.UsersManagement
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
var roles = ViewData["roles"] as RoleDto[];
|
||||
var users = ViewData["users"] as UserDto[];
|
||||
var permissions = ViewData["permissions"] as PermissionDto[];
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
<form id="authorization-permissions-form" method="post" class="w-100 h-100 mx-auto pl-10 pr-10 pt-10 pb-10">
|
||||
<div id="authorization-permissions-container">
|
||||
<input type="hidden" name="authorization-users-selected-id" id="authorization-users-selected-id" value="" />
|
||||
<input type="hidden" name="authorization-roles-selected-id" id="authorization-roles-selected-id" value="" />
|
||||
<!-- Users dropdown row -->
|
||||
<div class="h-30px w-100 text-end mb-5">
|
||||
<label for="authorization-users-combobox" class="text-light-one">@_localizer["Users"]</label>
|
||||
|
||||
<div class="enlightenment-combobox w-250px inline-block" id="authorization-users-combobox">
|
||||
<div class="shine-effect" style="top: 1px;"></div>
|
||||
<input type="checkbox" id="authorization-users-combobox-toggle" class="enlightenment-toggle-checkbox" />
|
||||
<label class="enlightenment-toggle" for="authorization-users-combobox-toggle">
|
||||
<span class="enlightenment-selected-text">@_localizer["SelectAUser"]</span>
|
||||
</label>
|
||||
<div class="enlightenment-dropdown" id="authorization-users-combobox-dropdown">
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<div class="enlightenment-option first-option disabled">@_localizer["SelectAUser"]</div>
|
||||
@if (users is not null)
|
||||
{
|
||||
@for (int i = 0; i < users.Length; i++)
|
||||
{
|
||||
<div class="enlightenment-option @(i == users.Length - 1 ? "last-option" : "")" data-value="@users[i].Id">@users[i].Username</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Roles dropdown row -->
|
||||
<div class="h-30px w-100 text-end mb-5">
|
||||
<label for="authorization-roles-combobox" class="text-light-one">@_localizer["Roles"]</label>
|
||||
|
||||
<div class="enlightenment-combobox w-250px inline-block" id="authorization-roles-combobox">
|
||||
<div class="shine-effect" style="top: 1px;"></div>
|
||||
<input type="checkbox" id="authorization-roles-combobox-toggle" class="enlightenment-toggle-checkbox" />
|
||||
<label class="enlightenment-toggle" for="authorization-roles-combobox-toggle">
|
||||
<span class="enlightenment-selected-text">@_localizer["SelectARole"]</span>
|
||||
</label>
|
||||
<div class="enlightenment-dropdown" id="authorization-roles-combobox-dropdown">
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<div class="enlightenment-option first-option disabled">@_localizer["SelectARole"]</div>
|
||||
@if (roles is not null)
|
||||
{
|
||||
@for (int i = 0; i < roles.Length; i++)
|
||||
{
|
||||
<div class="enlightenment-option @(i == roles.Length - 1 ? "last-option" : "")" data-value="@roles[i].Id">@roles[i].RoleName</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Permissions row -->
|
||||
<div id="authorization-permissions-permissions-container" class="">
|
||||
<div id="authorization-permissions-permissions">
|
||||
<div id="authorization-permissions-permissions-scroll" class="scroll-horizontal">
|
||||
<div id="authorization-permissions-permissions-list" class="list" style="flex-direction: column;">
|
||||
@if (permissions is not null)
|
||||
{
|
||||
@foreach (var permission in permissions)
|
||||
{
|
||||
<div class="e no-border transparent mt-5 mb-5">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" class="enlightenment-checkbox-hidden" name="authorization-permissions-permissions" value="@permission.Id">
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
@_localizer[permission.PermissionName.ToString()]
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button Row -->
|
||||
<div class="w-100 h-25px mt-5 text-end">
|
||||
<button id="btn-update-user" type="submit" class="confirm-button f-14 h-24px v-align-t" disabled>@_localizer["Update"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const btnUpdateUser = document.getElementById('btn-update-user');
|
||||
const form = document.getElementById('authorization-permissions-form');
|
||||
const rolesDropdown = document.getElementById('authorization-roles-combobox-dropdown');
|
||||
const usersDropdown = document.getElementById('authorization-users-combobox-dropdown');
|
||||
const roleIdInput = document.getElementById('authorization-roles-selected-id');
|
||||
const userIdInput = document.getElementById('authorization-users-selected-id');
|
||||
|
||||
// update user permissions and role
|
||||
async function handleUserAuthorizationSubmitAsync() {
|
||||
const formData = {
|
||||
userId: userIdInput.value,
|
||||
roleId: roleIdInput.value !== '' ? roleIdInput.value : null,
|
||||
permissions: Array.from(form.querySelectorAll("input[name='authorization-permissions-permissions']:checked"))
|
||||
.map(checkbox => checkbox.value)
|
||||
};
|
||||
|
||||
const result = await callApiPutAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Admin.UPDATE_USER_AUTHORIZATION)', formData);
|
||||
if (result.success)
|
||||
notificationService.show('@_localizer["UserAuthorizationUpdated"]', NotificationType.SUCCESS);
|
||||
}
|
||||
|
||||
async function fetchUserRoleAsync(userId) {
|
||||
const url = '@_urlService.GetAbsoluteUrl(WebRoutes.Admin.GET_ROLE_BY_USER_ID, new { userId = default(Guid) })';
|
||||
const data = await callApiGetAsync(url.replace('/@(default(Guid))', `/${userId}`)); // userId needs to be replaced here, because GetAbsoluteUrl is server side, userId is client side
|
||||
if (data) {
|
||||
var roleElement = document.querySelector('#authorization-roles-combobox .enlightenment-option[data-value="' + data.id + '"]');
|
||||
var roleName = roleElement.textContent;
|
||||
document.querySelector('#authorization-roles-combobox .enlightenment-selected-text').textContent = roleName;
|
||||
document.querySelector('#authorization-roles-combobox .enlightenment-toggle').dataset.value = data.id;
|
||||
roleIdInput.value = data.id;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUserPermissionsAsync(userId) {
|
||||
const url = '@_urlService.GetAbsoluteUrl(WebRoutes.Admin.GET_PERMISSIONS_BY_USER_ID, new { userId = default(Guid) })';
|
||||
const data = await callApiGetAsync(url.replace('/@(default(Guid))', `/${userId}`)); // userId needs to be replaced here, because GetAbsoluteUrl is server side, userId is client side
|
||||
if (data) {
|
||||
// clear all checkboxes
|
||||
document.querySelectorAll("input[name='authorization-permissions-permissions']")
|
||||
.forEach(input => input.checked = false);
|
||||
|
||||
// check the checkboxes for which permissions are assigned
|
||||
data.forEach(p => {
|
||||
const checkbox = document.querySelector(`input[name='authorization-permissions-permissions'][value='${p.id}']`);
|
||||
if (checkbox)
|
||||
checkbox.checked = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleUserAuthorizationSubmitAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleUserAuthorizationSubmitAsync();
|
||||
};
|
||||
|
||||
// on document click
|
||||
const handleDocumentClick = async function(e) {
|
||||
// users dropdown change
|
||||
if (e.target.closest('#authorization-users-combobox .enlightenment-option')) {
|
||||
var selectedUserId = e.target.dataset.value;
|
||||
document.querySelector('#authorization-roles-combobox .enlightenment-selected-text').textContent = '@_localizer["SelectARole"]';
|
||||
document.querySelectorAll("input[name='authorization-permissions-permissions']").forEach(input => input.checked = false);
|
||||
roleIdInput.value = '';
|
||||
userIdInput.value = '';
|
||||
if (selectedUserId) {
|
||||
userIdInput.value = selectedUserId;
|
||||
btnUpdateUser.disabled = false;
|
||||
await fetchUserRoleAsync(selectedUserId);
|
||||
await fetchUserPermissionsAsync(selectedUserId);
|
||||
}
|
||||
else
|
||||
btnUpdateUser.disabled = true;
|
||||
}
|
||||
// roles dropdown change
|
||||
else if (e.target.closest('#authorization-roles-combobox .enlightenment-option')) {
|
||||
const roleId = e.target.dataset.value;
|
||||
roleIdInput.value = roleId || '';
|
||||
}
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
document.addEventListener('click', handleDocumentClick);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
document.removeEventListener('click', handleDocumentClick);
|
||||
});
|
||||
|
||||
// when form's height changes, adjust the roles combobox dropdown maximum height accordingly, so it doesn't cause an <article> section overflow
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
const formHeight = form.getBoundingClientRect().height;
|
||||
usersDropdown.style.maxHeight = `calc(${formHeight}px - 50px)`;
|
||||
rolesDropdown.style.maxHeight = `calc(${formHeight}px - 90px)`;
|
||||
usersDropdown.style.overflowY = `auto`;
|
||||
rolesDropdown.style.overflowY = `auto`;
|
||||
});
|
||||
resizeObserver.observe(form);
|
||||
|
||||
// register cleanup for observer
|
||||
cleanupFunctions.push(() => {
|
||||
resizeObserver.disconnect();
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#authorization-permissions-container {
|
||||
display: flex;
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
#authorization-permissions-permissions-container {
|
||||
flex-grow: 1;
|
||||
min-width: 135px;
|
||||
min-height: 0px;
|
||||
}
|
||||
|
||||
#authorization-permissions-permissions {
|
||||
border: 1px solid var(--border-color-light-high);
|
||||
border-top: 1px solid var(--border-color-dark);
|
||||
border-left: 1px solid var(--border-color-dark);
|
||||
margin: auto;
|
||||
padding-left: 5px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: left;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
#authorization-permissions-permissions-scroll {
|
||||
background-color: #232323;
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#authorization-permissions-permissions-list {
|
||||
margin: 1px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
border: 0px solid black;
|
||||
padding: 0px;
|
||||
gap: 0px 10px;
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
@*
|
||||
/admin/manage-roles/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.DTO.Authorization
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
var roles = ViewData["roles"] as RoleDto[];
|
||||
var permissions = ViewData["permissions"] as PermissionDto[];
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
<form id="authorization-roles-form" method="post" class="w-100 h-100 mx-auto pl-10 pr-10 pt-10 pb-10">
|
||||
<div id="authorization-roles-container">
|
||||
<input type="hidden" name="authorization-roles-selected-id" id="authorization-roles-selected-id" value="" />
|
||||
<!-- Roles dropdown row -->
|
||||
<div class="h-30px w-100 text-end mb-5">
|
||||
<label for="authorization-roles-combobox" class="text-light-one">@_localizer["Roles"]</label>
|
||||
|
||||
<div class="enlightenment-combobox w-250px inline-block" id="authorization-roles-combobox">
|
||||
<div class="shine-effect" style="top: 1px;"></div>
|
||||
<input type="checkbox" id="authorization-roles-combobox-toggle" class="enlightenment-toggle-checkbox" />
|
||||
<label class="enlightenment-toggle" for="authorization-roles-combobox-toggle">
|
||||
<span class="enlightenment-selected-text">@_localizer["SelectARole"]</span>
|
||||
</label>
|
||||
<div class="enlightenment-dropdown" id="authorization-roles-combobox-dropdown">
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<div class="enlightenment-option first-option disabled">@_localizer["SelectARole"]</div>
|
||||
@if (roles is not null)
|
||||
{
|
||||
@for (int i = 0; i < roles.Length; i++)
|
||||
{
|
||||
<div class="enlightenment-option @(i == roles.Length - 1 ? "last-option" : "")" data-value="@roles[i].Id">@roles[i].RoleName</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Role name input row -->
|
||||
<div class="h-30px w-100 text-end mb-5">
|
||||
<label for="txt-role-name" class="text-light-one">@_localizer["RoleName"]</label>
|
||||
<input type="text" id="txt-role-name" name="authorization-role-name" class="enlightenment-input w-250px" />
|
||||
</div>
|
||||
|
||||
<!-- Permissions row -->
|
||||
<div id="authorization-roles-permissions-container" class="">
|
||||
<div id="authorization-roles-permissions">
|
||||
<div id="authorization-roles-permissions-scroll" class="scroll-horizontal">
|
||||
<div id="authorization-roles-permissions-list" class="list" style="flex-direction: column;">
|
||||
@if (permissions is not null)
|
||||
{
|
||||
@foreach (var permission in permissions)
|
||||
{
|
||||
<div class="e no-border transparent mt-5 mb-5">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" class="enlightenment-checkbox-hidden" name="authorization-role-permissions" value="@permission.Id">
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
@_localizer[permission.PermissionName.ToString()]
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button Row -->
|
||||
<div class="w-100 h-25px mt-5 text-end">
|
||||
<button id="btn-delete-role" type="button" class="abort-button f-14 h-24px v-align-t hidden">@_localizer["DeleteRole"]</button>
|
||||
<button id="btn-confirm-role" type="submit" class="confirm-button f-14 h-24px v-align-t">@_localizer["CreateRole"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const btnDeleteRole = document.getElementById('btn-delete-role');
|
||||
const btnConfirmRole = document.getElementById('btn-confirm-role');
|
||||
const txtRoleName = document.getElementById('txt-role-name');
|
||||
const form = document.getElementById('authorization-roles-form');
|
||||
const dropdown = document.getElementById('authorization-roles-combobox-dropdown');
|
||||
const roleIdInput = document.getElementById('authorization-roles-selected-id');
|
||||
|
||||
// create new or update existing role
|
||||
async function handleRoleSubmitAsync() {
|
||||
const formData = {
|
||||
roleId: roleIdInput.value,
|
||||
roleName: txtRoleName.value,
|
||||
permissions: Array.from(form.querySelectorAll("input[name='authorization-role-permissions']:checked"))
|
||||
.map(checkbox => checkbox.value)
|
||||
};
|
||||
|
||||
const isRoleSelected = formData.roleId !== '';
|
||||
|
||||
const result = isRoleSelected ?
|
||||
await callApiPutAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Admin.UPDATE_ROLE)', formData) :
|
||||
{ success: (await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Admin.CREATE_ROLE)', formData)) !== undefined };
|
||||
if (result.success) {
|
||||
await fetchRolesAsync();
|
||||
notificationService.show(isRoleSelected ? '@_localizer["RoleUpdated"]' : '@_localizer["RoleCreated"]', NotificationType.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchRolesAsync() {
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Admin.GET_ROLES)');
|
||||
if (data) {
|
||||
// clear the roles drop down list
|
||||
const rolesDropdown = document.querySelector("#authorization-roles-combobox .enlightenment-dropdown");
|
||||
rolesDropdown.innerHTML = `
|
||||
<div class="shine-effect" style="top: -4px;"></div>
|
||||
<div class="enlightenment-option first-option disabled">'@_localizer["SelectARole"]'</div>
|
||||
`;
|
||||
|
||||
// populate the roles drop down
|
||||
data.forEach((role, index) => {
|
||||
const option = document.createElement('div');
|
||||
option.className = `enlightenment-option ${index === data.length - 1 ? 'last-option' : ''}`;
|
||||
option.dataset.value = role.id;
|
||||
option.textContent = role.roleName;
|
||||
rolesDropdown.appendChild(option);
|
||||
});
|
||||
|
||||
// update the text of the toggle button of the combobox
|
||||
document.querySelector('.enlightenment-selected-text').textContent = '@_localizer["SelectARole"]';
|
||||
|
||||
// all permissions should be "unchecked"
|
||||
document.querySelectorAll("input[name='authorization-role-permissions']")
|
||||
.forEach(input => input.checked = false);
|
||||
|
||||
// the delete button should be hidden
|
||||
btnDeleteRole.classList.remove('inline');
|
||||
btnDeleteRole.classList.add('hidden');
|
||||
|
||||
// the "update" button should be "create"
|
||||
btnConfirmRole.textContent = '@_localizer["CreateRole"]';
|
||||
|
||||
// the input for the role name should also have its text emptied
|
||||
txtRoleName.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchRolePermissionsAsync(roleId) {
|
||||
if (roleId) {
|
||||
const url = '@_urlService.GetAbsoluteUrl(WebRoutes.Admin.GET_PERMISSIONS_BY_ROLE_ID, new { roleId = default(Guid) })';
|
||||
const data = await callApiGetAsync(url.replace('/@(default(Guid))', `/${roleId}`)); // roleId needs to be replaced here, because GetAbsoluteUrl is server side, roleId is client side
|
||||
if (data) {
|
||||
// clear all checkboxes
|
||||
document.querySelectorAll("input[name='authorization-role-permissions']")
|
||||
.forEach(input => input.checked = false);
|
||||
|
||||
// check the checkboxes for which permissions are assigned
|
||||
data.permissions.forEach(p => {
|
||||
const checkbox = document.querySelector(
|
||||
`input[name='authorization-role-permissions'][value='${p.id}']`
|
||||
);
|
||||
if (checkbox) checkbox.checked = true;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// if no role is selected, clear checkboxes
|
||||
document.querySelectorAll("input[name='authorization-role-permissions']")
|
||||
.forEach(input => input.checked = false);
|
||||
}
|
||||
}
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
await handleRoleSubmitAsync();
|
||||
}
|
||||
};
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleRoleSubmitAsync();
|
||||
};
|
||||
|
||||
// on delete role button click
|
||||
const handleBtnDeleteRoleClick = async function(e) {
|
||||
// ask the user for confirmation before deleting the role
|
||||
if (await dialogService.show('@_localizer["DeleteRoleConfirm"]', jsLocalizedDialogs.confirmation, DialogButtons.YES_NO, DialogIcon.QUESTION) === DialogButton.YES) {
|
||||
const url = '@_urlService.GetAbsoluteUrl(WebRoutes.Admin.DELETE_ROLE, new { roleId = default(Guid) })';
|
||||
const success = await callApiDeleteAsync(url.replace('/@(default(Guid))', `/${roleIdInput.value}`)); // roleId needs to be replaced here, because GetAbsoluteUrl is server side, roleId is client side
|
||||
if (success) {
|
||||
await fetchRolesAsync();
|
||||
notificationService.show('@_localizer["RoleDeleted"]', NotificationType.SUCCESS);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// on document click
|
||||
const handleDocumentClick = async function(e) {
|
||||
// roles dropdown change
|
||||
if (e.target.closest('#authorization-roles-combobox .enlightenment-option')) {
|
||||
const roleId = e.target.dataset.value;
|
||||
const selectedText = e.target.textContent;
|
||||
txtRoleName.value = roleId ? selectedText : '';
|
||||
|
||||
await fetchRolePermissionsAsync(roleId);
|
||||
|
||||
if (roleId) {
|
||||
btnDeleteRole.classList.remove('hidden');
|
||||
btnDeleteRole.classList.add('inline');
|
||||
btnConfirmRole.textContent = '@_localizer["UpdateRole"]';
|
||||
roleIdInput.value = roleId;
|
||||
} else {
|
||||
roleIdInput.value = '';
|
||||
btnDeleteRole.classList.remove('inline');
|
||||
btnDeleteRole.classList.add('hidden');
|
||||
btnConfirmRole.textContent = '@_localizer["CreateRole"]';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('keypress', handleEnterKey);
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
btnDeleteRole.addEventListener('click', handleBtnDeleteRoleClick);
|
||||
document.addEventListener('click', handleDocumentClick);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('keypress', handleEnterKey);
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
btnDeleteRole.removeEventListener('click', handleBtnDeleteRoleClick);
|
||||
document.removeEventListener('click', handleDocumentClick);
|
||||
});
|
||||
|
||||
// when form's height changes, adjust the roles combobox dropdown maximum height accordingly, so it doesn't cause an <article> section overflow
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
const formHeight = form.getBoundingClientRect().height;
|
||||
dropdown.style.maxHeight = `calc(${formHeight}px - 50px)`;
|
||||
dropdown.style.overflowY = `auto`;
|
||||
});
|
||||
resizeObserver.observe(form);
|
||||
|
||||
// register cleanup for observer
|
||||
cleanupFunctions.push(() => {
|
||||
resizeObserver.disconnect();
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#authorization-roles-container {
|
||||
display: flex;
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
#authorization-roles-permissions-container {
|
||||
flex-grow: 1;
|
||||
min-width: 135px;
|
||||
min-height: 0px;
|
||||
}
|
||||
|
||||
#authorization-roles-permissions {
|
||||
border: 1px solid var(--border-color-light-high);
|
||||
border-top: 1px solid var(--border-color-dark);
|
||||
border-left: 1px solid var(--border-color-dark);
|
||||
margin: auto;
|
||||
padding-left: 5px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: left;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
#authorization-roles-permissions-scroll {
|
||||
background-color: #232323;
|
||||
margin: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#authorization-roles-permissions-list {
|
||||
margin: 1px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
border: 0px solid black;
|
||||
padding: 0px;
|
||||
gap: 0px 10px;
|
||||
}
|
||||
Reference in new issue
Block a user