fix redirect back roles

This commit is contained in:
arifal
2025-03-12 20:30:16 +07:00
parent b0d4d4c23b
commit 7a82ad5302
9 changed files with 56 additions and 55 deletions

View File

@@ -6,6 +6,7 @@ class CreateRoles {
initCreateRole() {
const toastNotification = document.getElementById("toastNotification");
const toast = new bootstrap.Toast(toastNotification);
let menuId = document.getElementById("menuId").value;
document
.getElementById("btnCreateRole")
.addEventListener("click", async function () {
@@ -41,7 +42,7 @@ class CreateRoles {
result.message;
toast.show();
setTimeout(() => {
window.location.href = "/roles";
window.location.href = `/roles?menu_id=${menuId}`;
}, 2000);
} else {
let error = await response.json();

View File

@@ -31,6 +31,7 @@ class Roles {
tableContainer.innerHTML = "";
let canUpdate = tableContainer.getAttribute("data-updater") === "1";
let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
let menuId = tableContainer.getAttribute("data-menuId");
// Create a new Grid.js instance only if it doesn't exist
this.table = new gridjs.Grid({
columns: [
@@ -38,38 +39,38 @@ class Roles {
"Name",
"Description",
{
name: "Action",
formatter: (cell) => {
let buttons = `<div class="d-flex justify-content-center gap-2">`;
name: "Action",
formatter: (cell) => {
let buttons = `<div class="d-flex justify-content-center gap-2">`;
if (canUpdate) {
buttons += `
<a href="/roles/${cell}/edit" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
if (canUpdate) {
buttons += `
<a href="/roles/${cell}/edit?menu_id=${menuId}" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
<i class='bx bx-edit'></i>
</a>
<a href="/roles/role-menu/${cell}" class="btn btn-primary btn-sm d-inline-flex align-items-center justify-content-center">
<a href="/roles/role-menu/${cell}?menu_id=${menuId}" class="btn btn-primary btn-sm d-inline-flex align-items-center justify-content-center">
Role Menu
</a>
`;
}
}
if (canDelete) {
buttons += `
if (canDelete) {
buttons += `
<button data-id="${cell}" class="btn btn-sm btn-red btn-delete-role d-inline-flex align-items-center justify-content-center">
<i class='bx bxs-trash'></i>
</button>
`;
}
}
if (!canUpdate && !canDelete) {
buttons += `<span class="text-muted">No Privilege</span>`;
}
if (!canUpdate && !canDelete) {
buttons += `<span class="text-muted">No Privilege</span>`;
}
buttons += `</div>`;
buttons += `</div>`;
return gridjs.html(buttons);
return gridjs.html(buttons);
},
},
},
],
pagination: {
limit: 50,

View File

@@ -6,6 +6,7 @@ class UpdateRoles {
initUpdateRole() {
const toastNotification = document.getElementById("toastNotification");
const toast = new bootstrap.Toast(toastNotification);
let menuId = document.getElementById("menuId").value;
document
.getElementById("btnUpdateRole")
.addEventListener("click", async function () {
@@ -41,7 +42,7 @@ class UpdateRoles {
result.message;
toast.show();
setTimeout(() => {
window.location.href = "/roles";
window.location.href = `/roles?menu_id=${menuId}`;
}, 2000);
} else {
let error = await response.json();