class SideMenu extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' } constructor() { super(); this.attachShadow({ mode: 'open' }); // ... existing constructor code ... // Load student data when class/form changes this.shadowRoot.querySelector('#class-select').addEventListener('change', this.loadStudents.bind(this)); this.shadowRoot.querySelector('#form-select').addEventListener('change', this.loadStudents.bind(this)); this.shadowRoot.querySelector('#submit-attendance').addEventListener('click', this.submitAttendance.bind(this)); } loadStudents() { const classVal = this.shadowRoot.querySelector('#class-select').value; const formVal = this.shadowRoot.querySelector('#form-select').value; const studentSelect = this.shadowRoot.querySelector('#student-select'); studentSelect.innerHTML = ''; studentSelect.disabled = true; if (classVal && formVal) { const key = `${classVal}-${formVal}`; if (students[key]) { students[key].forEach(student => { const option = document.createElement('option'); option.value = student; option.textContent = student; studentSelect.appendChild(option); }); studentSelect.disabled = false; } } } submitAttendance() { const classVal = this.shadowRoot.querySelector('#class-select').value; const formVal = this.shadowRoot.querySelector('#form-select').value; const studentVal = this.shadowRoot.querySelector('#student-select').value; const attendance = this.shadowRoot.querySelector('input[name="attendance"]:checked').value; if (!classVal || !formVal) { alert('Please select both class and form'); return; } if (attendance === 'yes' && !studentVal) { alert('Please select a student'); return; } // Create attendance record const record = { timestamp: new Date().toISOString(), mealTime: getCurrentMealTime(), attendance: attendance, class: classVal, form: formVal, studentName: attendance === 'yes' ? studentVal : 'N/A' }; // Save to localStorage let records = JSON.parse(localStorage.getItem('attendanceRecords') || '[]'); records.push(record); localStorage.setItem('attendanceRecords', JSON.stringify(records)); alert('Attendance submitted successfully!'); this.fetchAttendanceData(); } ); this.shadowRoot.innerHTML = `

Dining Hall Menu

Attendance Form
Will Eat Today
No data available
Have Eaten Today
No data available
`; } connectedCallback() { this.shadowRoot.querySelector('.close-btn').addEventListener('click', () => { this.classList.remove('open'); }); } updateStudentList(listId, students) { const list = this.shadowRoot.querySelector(`#${listId}`); list.innerHTML = ''; if (students.length === 0) { list.innerHTML = '
No data available
'; return; } students.forEach(student => { const item = document.createElement('div'); item.className = 'student-item'; item.textContent = `${student.studentName} (${student.class} ${student.form})`; list.appendChild(item); }); } } customElements.define('side-menu', SideMenu);