From 9872e1c726fb3bcf2c875c26f2abb4a0ce0a5beb Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sun, 9 Aug 2026 23:58:59 +0530 Subject: [PATCH] refactor: show management status as toasts Route User Management and Role Master action results through fixed top-right notifications, including SPA partial responses, validation failures, session actions, and network errors. --- .../Setting/Admin/RoleManagement/form.php | 5 +++-- .../Setting/Admin/RoleManagement/index.php | 10 ++++------ .../Setting/Admin/UserManagement/create.php | 13 ++++--------- .../Setting/Admin/UserManagement/edit.php | 13 ++++--------- .../Setting/Admin/UserManagement/index.php | 17 +++++------------ .../Admin/UserManagement/permissions.php | 17 +++++------------ .../Admin/UserManagement/reset_password.php | 13 ++++--------- .../Setting/Admin/UserManagement/sessions.php | 6 +++--- app/Views/welcome_message.php | 18 ++++++++++++++++++ 9 files changed, 50 insertions(+), 62 deletions(-) diff --git a/app/Views/Setting/Admin/RoleManagement/form.php b/app/Views/Setting/Admin/RoleManagement/form.php index c76d2b5..b6c7af3 100644 --- a/app/Views/Setting/Admin/RoleManagement/form.php +++ b/app/Views/Setting/Admin/RoleManagement/form.php @@ -16,7 +16,7 @@ foreach ($allPermissions as $key => $label) {
-
+
Super Admin permissions are protected against lockout and cannot be changed.
@@ -75,8 +75,9 @@ foreach ($allPermissions as $key => $label) { var form = this; $.post($(form).attr('action'), $(form).serialize()).done(function(html) { $('#maindiv').html(html); + showPageNotifications(document.getElementById('maindiv')); }).fail(function(xhr) { - alert((xhr.responseJSON && xhr.responseJSON.error_text) || 'Unable to save role.'); + notify('error', 'Role Master', (xhr.responseJSON && xhr.responseJSON.error_text) || 'Unable to save role.'); }); }); })(); diff --git a/app/Views/Setting/Admin/RoleManagement/index.php b/app/Views/Setting/Admin/RoleManagement/index.php index 0c55c26..7b8ff35 100644 --- a/app/Views/Setting/Admin/RoleManagement/index.php +++ b/app/Views/Setting/Admin/RoleManagement/index.php @@ -14,11 +14,8 @@
-
- -
- - + +
@@ -59,11 +56,12 @@ data[csrfName] = csrfHash; $.post(url, data, null, 'json').done(function(response) { csrfHash = response.csrf_hash || csrfHash; + notify('success', 'Role Master', response.message || 'Role updated successfully.'); load_form_div('', 'maindiv', 'Role Master'); }).fail(function(xhr) { var response = xhr.responseJSON || {}; csrfHash = response.csrf_hash || csrfHash; - alert(response.error_text || 'Unable to update role.'); + notify('error', 'Role Master', response.error_text || 'Unable to update role.'); }); } diff --git a/app/Views/Setting/Admin/UserManagement/create.php b/app/Views/Setting/Admin/UserManagement/create.php index 73d14dd..728ff72 100644 --- a/app/Views/Setting/Admin/UserManagement/create.php +++ b/app/Views/Setting/Admin/UserManagement/create.php @@ -13,13 +13,7 @@
- -
- -
- -
- +
@@ -84,9 +78,10 @@ $.post($(form).attr('action'), $(form).serialize()) .done(function(html) { $('#maindiv').html(html); + showPageNotifications(document.getElementById('maindiv')); }) - .fail(function() { - alert('Request failed. Please try again.'); + .fail(function(xhr) { + notify('error', 'Create User', (xhr.responseJSON && xhr.responseJSON.error_text) || 'Request failed. Please try again.'); }); }); })(); diff --git a/app/Views/Setting/Admin/UserManagement/edit.php b/app/Views/Setting/Admin/UserManagement/edit.php index 1534ea7..34ae201 100644 --- a/app/Views/Setting/Admin/UserManagement/edit.php +++ b/app/Views/Setting/Admin/UserManagement/edit.php @@ -11,13 +11,7 @@
- -
- -
- -
- + @@ -82,9 +76,10 @@ $.post($(form).attr('action'), $(form).serialize()) .done(function(html) { $('#maindiv').html(html); + showPageNotifications(document.getElementById('maindiv')); }) - .fail(function() { - alert('Request failed. Please try again.'); + .fail(function(xhr) { + notify('error', 'Edit User', (xhr.responseJSON && xhr.responseJSON.error_text) || 'Request failed. Please try again.'); }); }); })(); diff --git a/app/Views/Setting/Admin/UserManagement/index.php b/app/Views/Setting/Admin/UserManagement/index.php index 0189d31..431e912 100644 --- a/app/Views/Setting/Admin/UserManagement/index.php +++ b/app/Views/Setting/Admin/UserManagement/index.php @@ -16,16 +16,8 @@
- -
- - -
- -
- -
- + +
@@ -165,12 +157,13 @@ '': $('input[name=""]').first().val() || '' }, function(data) { if (!data || parseInt(data.update || '0', 10) !== 1) { - window.alert((data && data.error_text) || 'Unable to delete user.'); + notify('error', 'Delete User', (data && data.error_text) || 'Unable to delete user.'); return; } + notify('success', 'Delete User', data.error_text || 'User deleted successfully.'); load_form_div('', 'maindiv', 'User Management'); }, 'json').fail(function(xhr) { - window.alert((xhr.responseJSON && xhr.responseJSON.error_text) || 'Unable to delete user.'); + notify('error', 'Delete User', (xhr.responseJSON && xhr.responseJSON.error_text) || 'Unable to delete user.'); }); }); })(); diff --git a/app/Views/Setting/Admin/UserManagement/permissions.php b/app/Views/Setting/Admin/UserManagement/permissions.php index fa43ee6..f8f4342 100644 --- a/app/Views/Setting/Admin/UserManagement/permissions.php +++ b/app/Views/Setting/Admin/UserManagement/permissions.php @@ -14,16 +14,8 @@
- -
- - -
- -
- -
- + +
- -
- -
- -
- +
Login ID: username ?? '')) ?>
@@ -97,9 +91,10 @@ $.post($(form).attr('action'), $(form).serialize()) .done(function(html) { $('#maindiv').html(html); + showPageNotifications(document.getElementById('maindiv')); }) - .fail(function() { - alert('Request failed. Please try again.'); + .fail(function(xhr) { + notify('error', 'Reset Password', (xhr.responseJSON && xhr.responseJSON.error_text) || 'Request failed. Please try again.'); }); }); })(); diff --git a/app/Views/Setting/Admin/UserManagement/sessions.php b/app/Views/Setting/Admin/UserManagement/sessions.php index 1f4fcd5..9b6f07e 100644 --- a/app/Views/Setting/Admin/UserManagement/sessions.php +++ b/app/Views/Setting/Admin/UserManagement/sessions.php @@ -18,7 +18,6 @@
user currently online. A user can have only one active HMS session.
-
RoleCodePermissionsUsersStatusTypeAction
@@ -88,14 +87,15 @@ '': $('input[name=""]').first().val() || '' }, function(data) { if (!data || parseInt(data.update || '0', 10) !== 1) { - $('#user_session_notice').html('
' + $('
').text((data && data.error_text) || 'Unable to end session.').html() + '
'); + notify('error', 'Force Logout', (data && data.error_text) || 'Unable to end session.'); button.disabled = false; return; } + notify('success', 'Force Logout', data.error_text || 'User session ended.'); load_form_div(listUrl, 'maindiv', 'Active Sessions'); }, 'json').fail(function(xhr) { var message = (xhr.responseJSON && xhr.responseJSON.error_text) || 'Unable to end session.'; - $('#user_session_notice').html('
' + $('
').text(message).html() + '
'); + notify('error', 'Force Logout', message); button.disabled = false; }); }); diff --git a/app/Views/welcome_message.php b/app/Views/welcome_message.php index a7acfff..9a79ee6 100644 --- a/app/Views/welcome_message.php +++ b/app/Views/welcome_message.php @@ -339,6 +339,9 @@ mainEl.innerHTML = html; } executeInjectedScripts('main'); + if (typeof window.showPageNotifications === 'function') { + window.showPageNotifications(mainEl); + } if (typeof initfunc === 'function') { initfunc(); } @@ -388,6 +391,9 @@ targetEl.innerHTML = html; } executeInjectedScripts(xdiv); + if (typeof window.showPageNotifications === 'function') { + window.showPageNotifications(targetEl); + } if (typeof initfunc === 'function') { initfunc(); } @@ -479,6 +485,18 @@ } }; } + + window.showPageNotifications = function(root) { + var scope = root && root.querySelectorAll ? root : document; + scope.querySelectorAll('[data-page-notification]:not([data-notification-shown])').forEach(function(item) { + item.setAttribute('data-notification-shown', '1'); + window.notify( + item.getAttribute('data-notification-type') || 'error', + item.getAttribute('data-notification-title') || 'Notification', + item.getAttribute('data-notification-message') || '' + ); + }); + };