From 3bec1b2c52114c1a26faeb868c4642d3c6f53862 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Thu, 6 Mar 2025 17:31:52 +0530 Subject: [PATCH] FIX_ROW_DBCLICK_IN_TABLES_SRI --- app/Views/client_list.php | 1 + app/Views/employee_list.php | 20 ++++++- app/Views/insurer_list.php | 1 + app/Views/insurer_statement_list.php | 54 ++++++++----------- app/Views/kyc_list.php | 1 + .../policy_transaction_endorsement_list.php | 54 ++++++++----------- app/Views/policy_type_list.php | 1 + app/Views/test_members_list.php | 53 ++++++++---------- app/Views/tpa_list.php | 1 + 9 files changed, 92 insertions(+), 94 deletions(-) diff --git a/app/Views/client_list.php b/app/Views/client_list.php index ce079c60..592031dc 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -202,6 +202,7 @@ table.dataTable thead th { customDropdown.querySelectorAll('.dropdown-item').forEach(item => { item.addEventListener('click', function(e) { + e.preventDefault(); const onclickAttr = this.getAttribute('onclick'); if (onclickAttr) { eval(onclickAttr); diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index 976e2f69..292d5c21 100755 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -232,7 +232,6 @@ table.dataTable tbody td { document.addEventListener("DOMContentLoaded", init); function init() { - const table = document.getElementById("tickets-table"); let activeDropdown = null; @@ -264,8 +263,21 @@ function init() { const customDropdown = document.createElement('div'); customDropdown.className = 'custom-dropdown-menu'; + + // Clone original dropdown items while moving onclick handlers to data attributes + const originalItems = originalDropdown.querySelectorAll('.dropdown-item'); customDropdown.innerHTML = originalDropdown.innerHTML; + // Transfer onclick handlers to data attributes + customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => { + const originalItem = originalItems[index]; + const originalOnclick = originalItem.getAttribute('onclick'); + if (originalOnclick) { + item.setAttribute('data-onclick', originalOnclick); + item.removeAttribute('onclick'); // Remove original handler + } + }); + return customDropdown; } @@ -287,11 +299,15 @@ function init() { } function handleItemClick(e, item) { - const onclickAttr = item.getAttribute('onclick'); + e.preventDefault(); + + // Execute the stored onclick handler + const onclickAttr = item.getAttribute('data-onclick'); if (onclickAttr) { eval(onclickAttr); } + // Handle href navigation const href = item.getAttribute('href'); if (href && href !== '#') { window.location.href = href; diff --git a/app/Views/insurer_list.php b/app/Views/insurer_list.php index 150f9be2..5168ba4f 100755 --- a/app/Views/insurer_list.php +++ b/app/Views/insurer_list.php @@ -133,6 +133,7 @@ document.addEventListener("DOMContentLoaded", function () { // Preserve click handlers and add auto-close customDropdown.querySelectorAll('.dropdown-item').forEach(item => { item.addEventListener('click', function(e) { + event.preventDefault(e); const onclickAttr = this.getAttribute('onclick'); if (onclickAttr) { eval(onclickAttr); diff --git a/app/Views/insurer_statement_list.php b/app/Views/insurer_statement_list.php index ff994fad..be2954d7 100644 --- a/app/Views/insurer_statement_list.php +++ b/app/Views/insurer_statement_list.php @@ -470,17 +470,21 @@ document.addEventListener("DOMContentLoaded", function () { // Create custom dropdown function createCustomDropdown(row) { - // Get the original dropdown items const originalDropdown = row.querySelector('.dropdown-menu'); if (!originalDropdown) return null; - // Create new dropdown with proper background and spacing const customDropdown = document.createElement('div'); customDropdown.className = 'custom-dropdown-menu'; - - // Copy inner content while maintaining icon alignment customDropdown.innerHTML = originalDropdown.innerHTML; - + + // Remove inline onclick handlers and store them in data attributes + const originalItems = originalDropdown.querySelectorAll('.dropdown-item'); + customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => { + const originalOnclick = originalItems[index].getAttribute('onclick'); + item.removeAttribute('onclick'); // Remove the inline handler + item.setAttribute('data-onclick', originalOnclick); // Store in data attribute + }); + return customDropdown; } @@ -494,45 +498,33 @@ document.addEventListener("DOMContentLoaded", function () { document.body.appendChild(customDropdown); row.addEventListener("click", function(event) { - // Ignore clicks on the action column - if (event.target.closest('td:last-child')) { - return; - } + // Ignore clicks on the first column + if (event.target.closest('td:first-child')) return; - // Hide any active dropdown - if (activeDropdown) { - activeDropdown.style.display = 'none'; - } + if (activeDropdown) activeDropdown.style.display = 'none'; - // Get click position const rect = event.target.getBoundingClientRect(); - - // Position the dropdown with some offset customDropdown.style.display = 'block'; customDropdown.style.position = 'fixed'; customDropdown.style.left = `${rect.left}px`; - customDropdown.style.top = `${rect.bottom + 5}px`; // Add 5px gap - - // Set as active dropdown + customDropdown.style.top = `${rect.bottom + 5}px`; activeDropdown = customDropdown; event.stopPropagation(); }); - - // Preserve click handlers and add auto-close + // Handle custom dropdown clicks customDropdown.querySelectorAll('.dropdown-item').forEach(item => { item.addEventListener('click', function(e) { - const onclickAttr = this.getAttribute('onclick'); - if (onclickAttr) { - eval(onclickAttr); - } + e.preventDefault(); - const href = this.getAttribute('href'); - if (href && href !== '#') { - window.location.href = href; - } + // Execute the original onclick from data attribute + const onclickAttr = this.getAttribute('data-onclick'); + if (onclickAttr) eval(onclickAttr); + + // Handle href navigation + const href = this.getAttribute('href'); + if (href && href !== '#') window.location.href = href; - // Close the dropdown after handling the click if (activeDropdown) { activeDropdown.style.display = 'none'; activeDropdown = null; @@ -543,7 +535,7 @@ document.addEventListener("DOMContentLoaded", function () { }); }); - // Close dropdown when clicking outside + // Close dropdown on outside click document.addEventListener("click", function() { if (activeDropdown) { activeDropdown.style.display = 'none'; diff --git a/app/Views/kyc_list.php b/app/Views/kyc_list.php index e6c0870f..c1a72d31 100755 --- a/app/Views/kyc_list.php +++ b/app/Views/kyc_list.php @@ -129,6 +129,7 @@ // Preserve click handlers and add auto-close customDropdown.querySelectorAll('.dropdown-item').forEach(item => { item.addEventListener('click', function(e) { + e.preventDefault(); const onclickAttr = this.getAttribute('onclick'); if (onclickAttr) { eval(onclickAttr); diff --git a/app/Views/policy_transaction_endorsement_list.php b/app/Views/policy_transaction_endorsement_list.php index f1f00d52..9259dc90 100644 --- a/app/Views/policy_transaction_endorsement_list.php +++ b/app/Views/policy_transaction_endorsement_list.php @@ -362,23 +362,26 @@ custom-dropdown-menu {