EHDEM commited on
Commit
6bf265d
·
verified ·
1 Parent(s): c582c63

make it so i can pick which forms class to remove

Browse files
Files changed (1) hide show
  1. admin-dashboard.html +48 -43
admin-dashboard.html CHANGED
@@ -152,24 +152,39 @@
152
  </button>
153
  </form>
154
  </div>
155
-
156
  <!-- Remove Class -->
157
  <div class="bg-gray-50 p-4 rounded-lg">
158
  <h4 class="font-medium mb-2">Remove Existing Class</h4>
159
- <form id="remove-class-form" class="flex gap-2">
160
- <select class="flex-1 px-3 py-2 border rounded" id="class-to-remove" required>
161
- <option value="">Select Class to Remove</option>
162
- <option value="BUDI">BUDI</option>
163
- <option value="USAHA">USAHA</option>
164
- <option value="MAJU">MAJU</option>
165
- <option value="JAYA">JAYA</option>
166
- </select>
167
- <button type="submit" class="bg-red-600 text-white px-4 py-2 rounded hover:bg-red-700">
168
- Remove Class
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </button>
170
  </form>
171
  </div>
172
- </div>
173
  </div>
174
  <!-- Reports Section -->
175
  <div class="hidden" id="reports-section">
@@ -423,41 +438,31 @@
423
  showManagementMessage(`Class ${newClassName} added successfully!`);
424
  this.reset();
425
  });
 
 
 
 
 
426
 
427
- // Remove class form
428
- document.getElementById('remove-class-form').addEventListener('submit', function(e) {
429
- e.preventDefault();
430
- const classToRemove = document.getElementById('class-to-remove').value;
431
-
432
- if (!classToRemove) {
433
- showManagementMessage('Please select a class to remove', 'error');
434
- return;
435
- }
436
-
437
- // Remove class from all selects
438
- const classSelects = document.querySelectorAll('select[id$="-class"], select[id^="class-"]');
439
- classSelects.forEach(select => {
440
- Array.from(select.options).forEach(option => {
441
- if (option.value === classToRemove) {
442
- option.remove();
443
- }
444
- });
445
- });
446
 
447
- // Remove all students in this class
448
- for (const key in students) {
449
- if (key.startsWith(classToRemove)) {
 
450
  delete students[key];
 
 
 
 
451
  }
452
- }
453
-
454
- // Save to localStorage
455
- localStorage.setItem('studentData', JSON.stringify(students));
456
-
457
- showManagementMessage(`Class ${classToRemove} and all its students removed successfully!`);
458
- this.reset();
459
- });
460
- // Load students for management dropdown
461
  function loadStudentsForManagement() {
462
  const classVal = document.getElementById('student-class').value;
463
  const formVal = document.getElementById('student-form').value;
 
152
  </button>
153
  </form>
154
  </div>
 
155
  <!-- Remove Class -->
156
  <div class="bg-gray-50 p-4 rounded-lg">
157
  <h4 class="font-medium mb-2">Remove Existing Class</h4>
158
+ <form id="remove-class-form" class="space-y-3">
159
+ <div class="grid grid-cols-2 gap-3">
160
+ <div>
161
+ <label class="block text-sm font-medium text-gray-700 mb-1">Class</label>
162
+ <select class="w-full px-3 py-2 border rounded" id="class-to-remove" required>
163
+ <option value="">Select Class</option>
164
+ <option value="BUDI">BUDI</option>
165
+ <option value="USAHA">USAHA</option>
166
+ <option value="MAJU">MAJU</option>
167
+ <option value="JAYA">JAYA</option>
168
+ </select>
169
+ </div>
170
+ <div>
171
+ <label class="block text-sm font-medium text-gray-700 mb-1">Form</label>
172
+ <select class="w-full px-3 py-2 border rounded" id="form-to-remove" required>
173
+ <option value="">Select Form</option>
174
+ <option value="1">Form 1</option>
175
+ <option value="2">Form 2</option>
176
+ <option value="3">Form 3</option>
177
+ <option value="4">Form 4</option>
178
+ <option value="5">Form 5</option>
179
+ </select>
180
+ </div>
181
+ </div>
182
+ <button type="submit" class="w-full bg-red-600 text-white px-4 py-2 rounded hover:bg-red-700">
183
+ Remove Class/Form
184
  </button>
185
  </form>
186
  </div>
187
+ </div>
188
  </div>
189
  <!-- Reports Section -->
190
  <div class="hidden" id="reports-section">
 
438
  showManagementMessage(`Class ${newClassName} added successfully!`);
439
  this.reset();
440
  });
441
+ // Remove class form
442
+ document.getElementById('remove-class-form').addEventListener('submit', function(e) {
443
+ e.preventDefault();
444
+ const classToRemove = document.getElementById('class-to-remove').value;
445
+ const formToRemove = document.getElementById('form-to-remove').value;
446
 
447
+ if (!classToRemove || !formToRemove) {
448
+ showManagementMessage('Please select both class and form', 'error');
449
+ return;
450
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
 
452
+ const key = `${classToRemove}-${formToRemove}`;
453
+
454
+ // Remove the specific class-form combination
455
+ if (students[key]) {
456
  delete students[key];
457
+ localStorage.setItem('studentData', JSON.stringify(students));
458
+ showManagementMessage(`Class ${classToRemove} Form ${formToRemove} and all its students removed successfully!`);
459
+ } else {
460
+ showManagementMessage(`No students found for ${classToRemove} Form ${formToRemove}`, 'error');
461
  }
462
+
463
+ this.reset();
464
+ });
465
+ // Load students for management dropdown
 
 
 
 
 
466
  function loadStudentsForManagement() {
467
  const classVal = document.getElementById('student-class').value;
468
  const formVal = document.getElementById('student-form').value;