diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index 3a779fb..f31b298 100755 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -302,14 +302,51 @@ function init() { function handleItemClick(e, item) { e.preventDefault(); - // Execute the stored onclick handler 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]; + + 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; }