From 06b7a8f59bc6640d478af454652da550f0c5e559 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Fri, 20 Mar 2026 21:44:46 -0400 Subject: [PATCH] Consolidate showConfirmModal into utils.js, remove duplicate from dashboard.js utils.js is loaded on all pages (dashboard, ticket, admin views) before dashboard.js. Moving the canonical definition there and removing the guard + the copy in dashboard.js eliminates the redundant redefinition on every page load. Co-Authored-By: Claude Sonnet 4.6 --- assets/js/dashboard.js | 65 ------------------------------------------ assets/js/utils.js | 61 +++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 97 deletions(-) diff --git a/assets/js/dashboard.js b/assets/js/dashboard.js index 7711ab1..4ad6a0a 100644 --- a/assets/js/dashboard.js +++ b/assets/js/dashboard.js @@ -1079,71 +1079,6 @@ function performBulkDelete() { // TERMINAL-STYLE MODAL UTILITIES // ============================================ -/** - * Show a terminal-style confirmation modal - * @param {string} title - Modal title - * @param {string} message - Message body - * @param {string} type - 'warning', 'error', 'info' (affects color) - * @param {function} onConfirm - Callback when user confirms - * @param {function} onCancel - Optional callback when user cancels - */ -function showConfirmModal(title, message, type = 'warning', onConfirm, onCancel = null) { - const modalId = 'confirmModal' + Date.now(); - - // Color scheme based on type - const colors = { - warning: 'var(--terminal-amber)', - error: 'var(--status-closed)', - info: 'var(--terminal-cyan)' - }; - const color = colors[type] || colors.warning; - - // Icon based on type - const icons = { - warning: '[ ! ]', - error: '[ X ]', - info: '[ i ]', - }; - const icon = icons[type] || icons.warning; - - // Escape user-provided content to prevent XSS - const safeTitle = lt.escHtml(title); - const safeMessage = lt.escHtml(message); - - const modalHtml = ` - - `; - - document.body.insertAdjacentHTML('beforeend', modalHtml); - - const modal = document.getElementById(modalId); - lt.modal.open(modalId); - - const cleanup = (cb) => { - lt.modal.close(modalId); - setTimeout(() => modal.remove(), 300); - if (cb) cb(); - }; - - document.getElementById(`${modalId}_confirm`).addEventListener('click', () => cleanup(onConfirm)); - document.getElementById(`${modalId}_cancel`).addEventListener('click', () => cleanup(onCancel)); - modal.querySelector('[data-modal-close]').addEventListener('click', () => cleanup(onCancel)); -} - /** * Show a terminal-style input modal * @param {string} title - Modal title diff --git a/assets/js/utils.js b/assets/js/utils.js index 40d9246..ac44f30 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -13,46 +13,43 @@ function getTicketIdFromUrl() { /** * Show a terminal-style confirmation modal using the lt.modal system. - * Falls back gracefully if dashboard.js has already defined this function. * @param {string} title - Modal title * @param {string} message - Confirmation message * @param {string} type - 'warning' | 'error' | 'info' * @param {Function} onConfirm - Called when user confirms * @param {Function|null} onCancel - Called when user cancels */ -if (typeof showConfirmModal === 'undefined') { - window.showConfirmModal = function showConfirmModal(title, message, type = 'warning', onConfirm, onCancel = null) { - const modalId = 'confirmModal' + Date.now(); - const colors = { warning: 'var(--terminal-amber)', error: 'var(--status-closed)', info: 'var(--terminal-cyan)' }; - const icons = { warning: '[ ! ]', error: '[ X ]', info: '[ i ]' }; - const color = colors[type] || colors.warning; - const icon = icons[type] || icons.warning; - const safeTitle = lt.escHtml(title); - const safeMessage = lt.escHtml(message); +function showConfirmModal(title, message, type = 'warning', onConfirm, onCancel = null) { + const modalId = 'confirmModal' + Date.now(); + const colors = { warning: 'var(--terminal-amber)', error: 'var(--status-closed)', info: 'var(--terminal-cyan)' }; + const icons = { warning: '[ ! ]', error: '[ X ]', info: '[ i ]' }; + const color = colors[type] || colors.warning; + const icon = icons[type] || icons.warning; + const safeTitle = lt.escHtml(title); + const safeMessage = lt.escHtml(message); - document.body.insertAdjacentHTML('beforeend', ` -