Spaces:
Running
Running
File size: 7,654 Bytes
c596211 a142f52 c596211 a142f52 58cd75e a142f52 58cd75e a142f52 58cd75e a142f52 c596211 a142f52 c596211 a142f52 c596211 a142f52 c596211 a142f52 c596211 3fefc74 a142f52 c596211 a142f52 c596211 3fefc74 c596211 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | 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 = '<option value="">Select Student</option>';
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 = `
<style>
:host {
position: fixed;
top: 0;
left: -300px;
width: 300px;
height: 100vh;
background: white;
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
transition: left 0.3s ease;
z-index: 1000;
padding: 20px;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
:host(.open) {
left: 0;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
background: none;
border: none;
font-size: 20px;
cursor: pointer;
}
h2 {
margin-top: 0;
color: #3b82f6;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.section {
margin: 15px 0;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
.section:last-child {
border-bottom: none;
}
.section-title {
font-weight: bold;
margin-bottom: 10px;
display: flex;
align-items: center;
}
.section-title i {
margin-right: 8px;
color: #3b82f6;
}
.student-list {
max-height: 200px;
overflow-y: auto;
}
.student-item {
padding: 8px;
margin: 4px 0;
background: #f5f5f5;
border-radius: 4px;
}
input, button {
width: 100%;
padding: 8px;
margin: 5px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background: #3b82f6;
color: white;
border: none;
cursor: pointer;
}
.admin-section {
display: none;
}
.stat-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}
</style>
<div>
<button class="close-btn">×</button>
<h2>Dining Hall Menu</h2>
<!-- Attendance Form -->
<div class="section">
<div class="section-title"><i class="fas fa-edit"></i> Attendance Form</div>
<div class="form-group">
<label>Will you be eating?</label>
<div class="radio-group">
<label>
<input type="radio" name="attendance" value="yes" checked> Yes
</label>
<label>
<input type="radio" name="attendance" value="no"> No
</label>
</div>
</div>
<div class="form-group">
<select id="class-select" class="form-control">
<option value="">Select Class</option>
<option value="BUDI">BUDI</option>
<option value="USAHA">USAHA</option>
<option value="MAJU">MAJU</option>
<option value="JAYA">JAYA</option>
</select>
</div>
<div class="form-group">
<select id="form-select" class="form-control">
<option value="">Select Form</option>
<option value="1">Form 1</option>
<option value="2">Form 2</option>
<option value="3">Form 3</option>
<option value="4">Form 4</option>
<option value="5">Form 5</option>
</select>
</div>
<div class="form-group">
<select id="student-select" class="form-control" disabled>
<option value="">Select Student</option>
</select>
</div>
<button id="submit-attendance" class="submit-btn">Submit</button>
</div>
<!-- Students Who Want to Eat -->
<div class="section">
<div class="section-title"><i class="fas fa-utensils"></i> Will Eat Today</div>
<div class="student-list" id="want-to-eat-list">
<div class="student-item">No data available</div>
</div>
</div>
<!-- Students Who Have Eaten -->
<div class="section">
<div class="section-title"><i class="fas fa-check-circle"></i> Have Eaten Today</div>
<div class="student-list" id="have-eaten-list">
<div class="student-item">No data available</div>
</div>
</div>
</div>
`;
}
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 = '<div class="student-item">No data available</div>';
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); |