From dcbe6fb3833103cf8d715ec1d5ff1f7a3ff891d9 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 5 Apr 2026 10:40:16 -0400 Subject: [PATCH] Fix double-firing event handlers, non-bubbling keyboard status event, and saved filter status type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate edit-comment/delete-comment cases from TicketView.php inline script — ticket.js already handles them. Double-call of editComment() would immediately open then close the edit form (second call sees .editing → cancels) - Fix keyboard shortcut 1-4 status change: dispatchEvent(new Event('change')) was non-bubbling (default), so the document-level change delegation in TicketView never received it. Now uses { bubbles: true } so updateTicketStatus() fires correctly - Fix saved filter status type: getCurrentFilterCriteria() was saving status as a joined string "Open,Pending" but pill-click handler called .join() expecting an array (TypeError swallowed by try/catch → status filter silently not applied). Now saves as array; applySavedFilterCriteria handles both arrays and legacy strings - Pill-click handler also updated to handle both array and string status formats Co-Authored-By: Claude Sonnet 4.6 --- assets/js/advanced-search.js | 8 +++++--- assets/js/keyboard-shortcuts.js | 2 +- views/DashboardView.php | 2 +- views/TicketView.php | 11 ++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/assets/js/advanced-search.js b/assets/js/advanced-search.js index e64616e..7155fc5 100644 --- a/assets/js/advanced-search.js +++ b/assets/js/advanced-search.js @@ -181,7 +181,7 @@ function getCurrentFilterCriteria() { const statusSelect = document.getElementById('adv-status'); const selectedStatuses = Array.from(statusSelect.selectedOptions).map(opt => opt.value); - if (selectedStatuses.length > 0) criteria.status = selectedStatuses.join(','); + if (selectedStatuses.length > 0) criteria.status = selectedStatuses; // keep as array — pill handler uses .join(',') const priorityMin = document.getElementById('adv-priority-min').value; if (priorityMin) criteria.priority_min = priorityMin; @@ -256,9 +256,11 @@ function applySavedFilterCriteria(criteria) { document.getElementById('adv-updated-from').value = criteria.updated_from || ''; document.getElementById('adv-updated-to').value = criteria.updated_to || ''; - // Status + // Status — criteria.status may be an array (new saves) or a comma-joined string (old saves) const statusSelect = document.getElementById('adv-status'); - const statuses = criteria.status ? criteria.status.split(',') : []; + const statuses = criteria.status + ? (Array.isArray(criteria.status) ? criteria.status : criteria.status.split(',')) + : []; Array.from(statusSelect.options).forEach(option => { option.selected = statuses.includes(option.value); }); diff --git a/assets/js/keyboard-shortcuts.js b/assets/js/keyboard-shortcuts.js index e1d6d34..d09cea6 100644 --- a/assets/js/keyboard-shortcuts.js +++ b/assets/js/keyboard-shortcuts.js @@ -104,7 +104,7 @@ document.addEventListener('DOMContentLoaded', function() { const option = Array.from(statusSelect.options).find(opt => opt.value === targetStatus); if (option && !option.disabled) { statusSelect.value = targetStatus; - statusSelect.dispatchEvent(new Event('change')); + statusSelect.dispatchEvent(new Event('change', { bubbles: true })); } } }); diff --git a/views/DashboardView.php b/views/DashboardView.php index 1e26b71..89314be 100644 --- a/views/DashboardView.php +++ b/views/DashboardView.php @@ -1086,7 +1086,7 @@ if (window.lt) { var c = JSON.parse(btn.dataset.criteria); var params = new URLSearchParams(); if (c.search) params.set('search', c.search); - if (c.status && c.status.length) params.set('status', c.status.join(',')); + if (c.status && c.status.length) params.set('status', Array.isArray(c.status) ? c.status.join(',') : c.status); if (c.priority_min) params.set('priority_min', c.priority_min); if (c.priority_max) params.set('priority_max', c.priority_max); if (c.assigned_to) params.set('assigned_to', c.assigned_to); diff --git a/views/TicketView.php b/views/TicketView.php index c4ca79d..888018f 100644 --- a/views/TicketView.php +++ b/views/TicketView.php @@ -1104,17 +1104,14 @@ document.addEventListener('DOMContentLoaded', function () { } }); - // Click delegation for comment actions + // Click delegation — only handles actions NOT covered by ticket.js + // (edit-comment, delete-comment, remove-dependency, delete-attachment, select-mention, + // save/cancel-edit-comment, reply-comment, close-reply, submit-reply are in ticket.js) document.addEventListener('click', function (e) { var target = e.target.closest('[data-action]'); if (!target) return; var action = target.getAttribute('data-action'); - var commentId = target.getAttribute('data-comment-id'); - if (action === 'edit-comment' && commentId) { - if (typeof editComment === 'function') editComment(parseInt(commentId, 10)); - } else if (action === 'delete-comment' && commentId) { - if (typeof deleteComment === 'function') deleteComment(parseInt(commentId, 10)); - } else if (action === 'dismiss-priority-banner') { + if (action === 'dismiss-priority-banner') { var banner = target.closest('[data-alert-id]'); if (banner) { try { sessionStorage.setItem('lt_dismissed_' + banner.dataset.alertId, '1'); } catch(ex) {}