CoolFace
Apppublic

rabahA/keymaster-highschool-dashboard

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
script.js120 linesDownload Raw Back to root
1 2// Shared JavaScript functions3document.addEventListener('DOMContentLoaded', function() {4    // Initialize tooltips5    const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));6    tooltipTriggerList.map(function(tooltipTriggerEl) {7        return new bootstrap.Tooltip(tooltipTriggerEl);8    });9 10    // Initialize buttons and actions11    initButtons();12    if (document.querySelector('.sidebar-item')) {13        setActiveSidebarItem();14    }15});16 17// Function to format dates18function formatDate(dateString) {19    const options = { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };20    return new Date(dateString).toLocaleDateString('fr-FR', options);21}22 23// Function to handle search24function handleSearch(event) {25    event.preventDefault();26    const searchTerm = document.getElementById('searchInput').value.trim().toLowerCase();27    console.log('Searching for:', searchTerm);28    // Implement search functionality29}30 31// Function to toggle active state in sidebar32function setActiveSidebarItem() {33    const currentPath = window.location.pathname.split('/').pop() || 'index.html';34    const sidebarLinks = document.querySelectorAll('.sidebar-item');35 36    sidebarLinks.forEach(link => {37        const href = link.getAttribute('href');38        const linkPath = href.split('/').pop();39        40        if (currentPath === linkPath || (currentPath === '' && linkPath === 'index.html')) {41            link.classList.add('active');42        } else {43            link.classList.remove('active');44        }45    });46}47 48// Button actions initialization49function initButtons() {50    // Add user button51    const addUserBtn = document.querySelector('button[data-action="add-user"]');52    if (addUserBtn) {53        addUserBtn.addEventListener('click', () => {54            window.location.href = 'user-form.html';55        });56    }57 58    // Add borrowing button59    const addBorrowingBtn = document.querySelector('button[data-action="add-borrowing"]');60    if (addBorrowingBtn) {61        addBorrowingBtn.addEventListener('click', () => {62            window.location.href = 'borrowing-form.html';63        });64    }65 66    // Edit buttons67    document.querySelectorAll('button[data-action="edit"]').forEach(btn => {68        btn.addEventListener('click', (e) => {69            const id = e.currentTarget.dataset.id;70            window.location.href = `edit-form.html?id=${id}`;71        });72    });73 74    // Delete buttons75    document.querySelectorAll('button[data-action="delete"]').forEach(btn => {76        btn.addEventListener('click', (e) => {77            const id = e.currentTarget.dataset.id;78            if (confirm('Êtes-vous sûr de vouloir supprimer cet élément ?')) {79                // API call to delete would go here80                console.log(`Deleting item with ID: ${id}`);81                e.currentTarget.closest('tr').remove();82            }83        });84    });85 86    // Return key button87    document.querySelectorAll('button[data-action="return-key"]').forEach(btn => {88        btn.addEventListener('click', (e) => {89            const id = e.currentTarget.dataset.id;90            // API call to mark as returned would go here91            console.log(`Marking key with ID: ${id} as returned`);92            const statusCell = e.currentTarget.closest('tr').querySelector('.status-cell');93            statusCell.innerHTML = '<span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">Rendu</span>';94        });95    });96 97    // Extend deadline button98    document.querySelectorAll('button[data-action="extend-deadline"]').forEach(btn => {99        btn.addEventListener('click', (e) => {100            const id = e.currentTarget.dataset.id;101            const newDate = prompt('Nouvelle date de retour (JJ/MM/AAAA HH:MM):');102            if (newDate) {103                // API call to extend deadline would go here104                console.log(`Extending deadline for ID: ${id} to ${newDate}`);105                const dateCell = e.currentTarget.closest('tr').querySelector('.return-date-cell');106                dateCell.textContent = newDate;107            }108        });109    });110 111    // Pagination buttons112    document.querySelectorAll('button[data-action="pagination"]').forEach(btn => {113        btn.addEventListener('click', (e) => {114            const direction = e.currentTarget.dataset.direction;115            // Handle pagination logic here116            console.log(`Navigating to ${direction} page`);117        });118    });119}120