diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index 42ee6b08..a03e40e4 100755 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -306,17 +306,53 @@ } function handleItemClick(e, item) { - e.preventDefault(); - - // Execute the stored onclick handler + e.preventDefault(); + const onclickAttr = item.getAttribute('data-onclick'); if (onclickAttr) { - eval(onclickAttr); - } + // Regex to separate function name from the inside of the parentheses + // Example: myFunc(this, '123') -> match[1]="myFunc", match[2]="this, '123'" + const match = onclickAttr.match(/^(\w+)\((.*)\)$/); + + if (match) { + const funcName = match[1]; + const argsRaw = match[2]; - // Handle href navigation + if (typeof window[funcName] === 'function') { + // Parse the arguments string into a real array + const args = argsRaw.split(',').map(arg => { + let cleaned = arg.trim(); + + // 1. Handle the 'this' keyword + if (cleaned === 'this') return item; + + // 2. Handle 'event' keyword + if (cleaned === 'event') return e; + + // 3. Handle strings (remove single or double quotes) + if ((cleaned.startsWith("'") && cleaned.endsWith("'")) || + (cleaned.startsWith('"') && cleaned.endsWith('"'))) { + return cleaned.substring(1, cleaned.length - 1); + } + + // 4. Handle numbers + if (!isNaN(cleaned) && cleaned !== "") { + return Number(cleaned); + } + + return cleaned; + }); + + // Execute function: + // .apply(item, args) sets the 'this' inside the function to the clicked element + window[funcName].apply(item, args); + } + } + } + + // Handle standard navigation if it's a link const href = item.getAttribute('href'); - if (href && href !== '#') { + if (href && href !== '#' && !href.includes('javascript:void(0)')) { window.location.href = href; } @@ -324,7 +360,7 @@ activeDropdown.style.display = 'none'; activeDropdown = null; } - + e.stopPropagation(); }