Security: - Fix IDOR in delete/update comment (add ticket visibility check) - XSS defense-in-depth in DashboardView active filters - Replace innerHTML with DOM construction in toast.js - Remove redundant real_escape_string in check_duplicates - Add rate limiting to get_template, download_attachment, audit_log, saved_filters, user_preferences endpoints Bug fixes: - Session timeout now reads from config instead of hardcoded 18000 - TicketController uses $GLOBALS['config'] instead of duplicate .env parsing - Add DISCORD_WEBHOOK_URL to centralized config - Cleanup script uses hashmap for O(1) ticket ID lookups Dead code removal (~100 lines): - Remove dead getTicketComments() from TicketModel (wrong bind_param type) - Remove dead getCategories()/getTypes() from DashboardController - Remove ~80 lines dead Discord webhook code from update_ticket API Consolidation: - Create api/bootstrap.php for shared API setup (auth, CSRF, rate limit) - Convert 6 API endpoints to use bootstrap - Extract escapeHtml/getTicketIdFromUrl into shared utils.js - Batch save for user preferences (1 request instead of 7) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
95 lines
2.6 KiB
JavaScript
95 lines
2.6 KiB
JavaScript
/**
|
||
* Terminal-style toast notification system with queuing
|
||
*/
|
||
|
||
// Toast queue management
|
||
let toastQueue = [];
|
||
let currentToast = null;
|
||
|
||
function showToast(message, type = 'info', duration = 3000) {
|
||
// Queue if a toast is already showing
|
||
if (currentToast) {
|
||
toastQueue.push({ message, type, duration });
|
||
return;
|
||
}
|
||
|
||
displayToast(message, type, duration);
|
||
}
|
||
|
||
function displayToast(message, type, duration) {
|
||
// Create toast element
|
||
const toast = document.createElement('div');
|
||
toast.className = `terminal-toast toast-${type}`;
|
||
currentToast = toast;
|
||
|
||
// Icon based on type
|
||
const icons = {
|
||
success: '✓',
|
||
error: '✗',
|
||
info: 'ℹ',
|
||
warning: '⚠'
|
||
};
|
||
|
||
const iconSpan = document.createElement('span');
|
||
iconSpan.className = 'toast-icon';
|
||
iconSpan.textContent = `[${icons[type] || 'ℹ'}]`;
|
||
|
||
const msgSpan = document.createElement('span');
|
||
msgSpan.className = 'toast-message';
|
||
msgSpan.textContent = message;
|
||
|
||
const closeSpan = document.createElement('span');
|
||
closeSpan.className = 'toast-close';
|
||
closeSpan.style.cssText = 'margin-left: auto; cursor: pointer; opacity: 0.7; padding-left: 1rem;';
|
||
closeSpan.textContent = '[×]';
|
||
|
||
toast.appendChild(iconSpan);
|
||
toast.appendChild(msgSpan);
|
||
toast.appendChild(closeSpan);
|
||
|
||
// Add to document
|
||
document.body.appendChild(toast);
|
||
|
||
// Trigger animation
|
||
setTimeout(() => toast.classList.add('show'), 10);
|
||
|
||
// Manual dismiss handler
|
||
const closeBtn = toast.querySelector('.toast-close');
|
||
closeBtn.addEventListener('click', () => dismissToast(toast));
|
||
|
||
// Auto-remove after duration
|
||
const timeoutId = setTimeout(() => {
|
||
dismissToast(toast);
|
||
}, duration);
|
||
|
||
// Store timeout ID for manual dismiss
|
||
toast.timeoutId = timeoutId;
|
||
}
|
||
|
||
function dismissToast(toast) {
|
||
// Clear auto-dismiss timeout
|
||
if (toast.timeoutId) {
|
||
clearTimeout(toast.timeoutId);
|
||
}
|
||
|
||
toast.classList.remove('show');
|
||
setTimeout(() => {
|
||
toast.remove();
|
||
currentToast = null;
|
||
|
||
// Show next toast in queue
|
||
if (toastQueue.length > 0) {
|
||
const next = toastQueue.shift();
|
||
displayToast(next.message, next.type, next.duration);
|
||
}
|
||
}, 300);
|
||
}
|
||
|
||
// Convenience functions
|
||
window.toast = {
|
||
success: (msg, duration) => showToast(msg, 'success', duration),
|
||
error: (msg, duration) => showToast(msg, 'error', duration),
|
||
info: (msg, duration) => showToast(msg, 'info', duration),
|
||
warning: (msg, duration) => showToast(msg, 'warning', duration)
|
||
};
|