/** * Admin Dashboard JavaScript */ document.addEventListener('DOMContentLoaded', function() { // Initialize progress bars initProgressBars(); // Initialize confirmation dialogs for delete buttons initConfirmDialogs(); // Add automatic fade-out for flash messages after 5 seconds initFlashMessages(); }); /** * Initialize progress bars by setting the width based on data-width attribute */ function initProgressBars() { const progressBars = document.querySelectorAll('.progress-bar-fill'); progressBars.forEach(bar => { const width = bar.getAttribute('data-width'); if (width) { // Use setTimeout to allow for a smooth animation setTimeout(() => { bar.style.width = `${width}%`; }, 100); } }); } /** * Initialize confirmation dialogs for delete buttons */ function initConfirmDialogs() { const confirmForms = document.querySelectorAll('form[onsubmit*="confirm"]'); confirmForms.forEach(form => { form.onsubmit = function() { const message = this.getAttribute('onsubmit').match(/confirm\('([^']+)'\)/)[1]; return confirm(message); }; }); } /** * Initialize auto-hide for flash messages */ function initFlashMessages() { const flashMessages = document.querySelectorAll('.flash-messages .alert'); flashMessages.forEach(message => { // Auto-hide messages after 5 seconds setTimeout(() => { message.style.opacity = '0'; message.style.transition = 'opacity 0.5s ease'; // Remove from DOM after fade out setTimeout(() => { message.remove(); }, 500); }, 5000); }); }