// Attendance Functions for Teacher Dashboard // Constants const ATTENDANCE_MODAL_ID = 'attendanceModal'; const QUICK_ATTENDANCE_FORM_ID = 'quickAttendanceForm'; const ATTENDANCE_FORM_ID = 'attendanceForm'; // Attendance Modal Functions async function openAttendanceModal(routineId, date) { try { console.log('Opening attendance modal for routine:', routineId, 'date:', date); // Validate and clean inputs routineId = routineId?.trim().replace(/['"]+/g, ''); date = date || getCurrentDate(); if (!routineId) { throw new Error('Invalid routine ID'); } // Get required elements const modal = document.getElementById(ATTENDANCE_MODAL_ID); const modalRoutineId = document.getElementById('modalRoutineId'); const modalDate = document.getElementById('modalDate'); const modalStudentList = document.getElementById('modalStudentList'); if (!modal || !modalRoutineId || !modalDate || !modalStudentList) { throw new Error('Required modal elements not found'); } // Set form values modalRoutineId.value = routineId; modalDate.value = date; // Show loading state showLoadingSpinner(modalStudentList, 'Loading students...'); // Show modal showModal(ATTENDANCE_MODAL_ID); // Fetch students const data = await apiRequest(`${API_BASE_URL}/get-students/?routine_id=${routineId}`); if (data.error) { throw new Error(data.error); } // Render student list with enhanced UI renderStudentList(modalStudentList, data.students); } catch (error) { console.error('Error in openAttendanceModal:', error); showError(document.getElementById('modalStudentList'), error); hideModal(ATTENDANCE_MODAL_ID); } } function renderStudentList(container, students) { if (!container || !Array.isArray(students)) return; container.innerHTML = `
| ${index + 1} | ${student.name} | ${student.id} |
|