EHDEM commited on
Commit
331afa1
·
verified ·
1 Parent(s): 403a5f7

make add a new student and remove a student into one thing but make it a choice

Browse files
Files changed (1) hide show
  1. admin-dashboard.html +105 -98
admin-dashboard.html CHANGED
@@ -60,48 +60,25 @@
60
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Student & Class Management</h2>
61
 
62
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
63
- <!-- Add Student Form -->
64
  <div class="bg-gray-50 p-4 rounded-lg">
65
- <h3 class="text-lg font-medium mb-3">Add New Student</h3>
66
- <form id="add-student-form">
67
- <div class="mb-3">
68
- <label class="block text-gray-700 mb-1">Class</label>
69
- <select class="w-full px-3 py-2 border rounded" id="add-student-class" required>
70
- <option value="">Select Class</option>
71
- <option value="BUDI">BUDI</option>
72
- <option value="USAHA">USAHA</option>
73
- <option value="MAJU">MAJU</option>
74
- <option value="JAYA">JAYA</option>
75
- </select>
76
  </div>
77
- <div class="mb-3">
78
- <label class="block text-gray-700 mb-1">Form</label>
79
- <select class="w-full px-3 py-2 border rounded" id="add-student-form" required>
80
- <option value="">Select Form</option>
81
- <option value="1">Form 1</option>
82
- <option value="2">Form 2</option>
83
- <option value="3">Form 3</option>
84
- <option value="4">Form 4</option>
85
- <option value="5">Form 5</option>
86
- </select>
87
- </div>
88
- <div class="mb-3">
89
- <label class="block text-gray-700 mb-1">Student Name</label>
90
- <input type="text" class="w-full px-3 py-2 border rounded" id="add-student-name" required>
91
- </div>
92
- <button type="submit" class="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700">
93
- Add Student
94
- </button>
95
- </form>
96
- </div>
97
 
98
- <!-- Remove Student Form -->
99
- <div class="bg-gray-50 p-4 rounded-lg">
100
- <h3 class="text-lg font-medium mb-3">Remove Student</h3>
101
- <form id="remove-student-form">
102
  <div class="mb-3">
103
  <label class="block text-gray-700 mb-1">Class</label>
104
- <select class="w-full px-3 py-2 border rounded" id="remove-student-class" required>
105
  <option value="">Select Class</option>
106
  <option value="BUDI">BUDI</option>
107
  <option value="USAHA">USAHA</option>
@@ -111,7 +88,7 @@
111
  </div>
112
  <div class="mb-3">
113
  <label class="block text-gray-700 mb-1">Form</label>
114
- <select class="w-full px-3 py-2 border rounded" id="remove-student-form" required>
115
  <option value="">Select Form</option>
116
  <option value="1">Form 1</option>
117
  <option value="2">Form 2</option>
@@ -120,18 +97,33 @@
120
  <option value="5">Form 5</option>
121
  </select>
122
  </div>
123
- <div class="mb-3">
124
- <label class="block text-gray-700 mb-1">Student</label>
125
- <select class="w-full px-3 py-2 border rounded" id="remove-student-name" disabled required>
126
- <option value="">Select Student</option>
127
- </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  </div>
129
- <button type="submit" class="w-full bg-red-600 text-white py-2 rounded hover:bg-red-700">
130
- Remove Student
131
- </button>
132
  </form>
133
  </div>
134
- </div>
135
 
136
  <!-- School Structure Management -->
137
  <div class="mt-6">
@@ -269,63 +261,80 @@
269
  document.getElementById('management-section').classList.toggle('hidden');
270
  });
271
 
272
- // Load students for removal
273
- document.getElementById('remove-student-class').addEventListener('change', loadStudentsForRemoval);
274
- document.getElementById('remove-student-form').addEventListener('change', loadStudentsForRemoval);
 
 
 
 
 
 
 
 
 
 
 
275
 
276
- // Add student form
277
- document.getElementById('add-student-form').addEventListener('submit', function(e) {
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  e.preventDefault();
279
- const className = document.getElementById('add-student-class').value;
280
- const form = document.getElementById('add-student-form').value;
281
- const studentName = document.getElementById('add-student-name').value;
282
 
283
- if (!className || !form || !studentName) {
284
- showManagementMessage('Please fill all fields', 'error');
285
  return;
286
  }
287
 
288
- // Add to students data structure
289
  const key = `${className}-${form}`;
290
- if (!students[key]) {
291
- students[key] = [];
292
- }
293
- students[key].push(studentName);
294
 
295
- // Save to localStorage
296
- localStorage.setItem('studentData', JSON.stringify(students));
297
-
298
- showManagementMessage('Student added successfully!');
299
- this.reset();
300
- });
301
-
302
- // Remove student form
303
- document.getElementById('remove-student-form').addEventListener('submit', function(e) {
304
- e.preventDefault();
305
- const className = document.getElementById('remove-student-class').value;
306
- const form = document.getElementById('remove-student-form').value;
307
- const studentName = document.getElementById('remove-student-name').value;
308
 
309
- if (!className || !form || !studentName) {
310
- showManagementMessage('Please fill all fields', 'error');
311
- return;
312
- }
 
 
 
 
 
 
 
 
 
 
313
 
314
- // Remove from students data structure
315
- const key = `${className}-${form}`;
316
- if (students[key]) {
317
- students[key] = students[key].filter(name => name !== studentName);
318
-
319
- // Save to localStorage
320
  localStorage.setItem('studentData', JSON.stringify(students));
321
-
322
- showManagementMessage('Student removed successfully!');
323
- loadStudentsForRemoval();
324
  this.reset();
325
  }
326
  });
327
-
328
- // Add class form
329
  document.getElementById('add-class-form').addEventListener('submit', function(e) {
330
  e.preventDefault();
331
  const newClassName = document.getElementById('new-class-name').value.trim().toUpperCase();
@@ -388,12 +397,11 @@
388
  showManagementMessage(`Class ${classToRemove} and all its students removed successfully!`);
389
  this.reset();
390
  });
391
-
392
- // Load students for removal dropdown
393
- function loadStudentsForRemoval() {
394
- const classVal = document.getElementById('remove-student-class').value;
395
- const formVal = document.getElementById('remove-student-form').value;
396
- const studentSelect = document.getElementById('remove-student-name');
397
 
398
  studentSelect.innerHTML = '<option value="">Select Student</option>';
399
  studentSelect.disabled = true;
@@ -411,8 +419,7 @@
411
  }
412
  }
413
  }
414
-
415
- // Show management message
416
  function showManagementMessage(message, type = 'success') {
417
  const messageDiv = document.getElementById('management-message');
418
  messageDiv.textContent = message;
 
60
  <h2 class="text-xl font-semibold mb-4 text-gray-800">Student & Class Management</h2>
61
 
62
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
63
+ <!-- Student Management Form -->
64
  <div class="bg-gray-50 p-4 rounded-lg">
65
+ <div class="flex justify-between items-center mb-4">
66
+ <h3 class="text-lg font-medium">Student Management</h3>
67
+ <div class="flex">
68
+ <button id="add-student-btn" class="px-4 py-2 bg-blue-600 text-white rounded-l-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
69
+ Add Student
70
+ </button>
71
+ <button id="remove-student-btn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-r-lg hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-300">
72
+ Remove Student
73
+ </button>
 
 
74
  </div>
75
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
+ <!-- Form that changes based on selection -->
78
+ <form id="student-form">
 
 
79
  <div class="mb-3">
80
  <label class="block text-gray-700 mb-1">Class</label>
81
+ <select class="w-full px-3 py-2 border rounded" id="student-class" required>
82
  <option value="">Select Class</option>
83
  <option value="BUDI">BUDI</option>
84
  <option value="USAHA">USAHA</option>
 
88
  </div>
89
  <div class="mb-3">
90
  <label class="block text-gray-700 mb-1">Form</label>
91
+ <select class="w-full px-3 py-2 border rounded" id="student-form" required>
92
  <option value="">Select Form</option>
93
  <option value="1">Form 1</option>
94
  <option value="2">Form 2</option>
 
97
  <option value="5">Form 5</option>
98
  </select>
99
  </div>
100
+
101
+ <!-- Add Student Fields (shown by default) -->
102
+ <div id="add-student-fields">
103
+ <div class="mb-3">
104
+ <label class="block text-gray-700 mb-1">Student Name</label>
105
+ <input type="text" class="w-full px-3 py-2 border rounded" id="student-name" required>
106
+ </div>
107
+ <button type="submit" class="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700">
108
+ Add Student
109
+ </button>
110
+ </div>
111
+
112
+ <!-- Remove Student Fields (hidden by default) -->
113
+ <div id="remove-student-fields" class="hidden">
114
+ <div class="mb-3">
115
+ <label class="block text-gray-700 mb-1">Student</label>
116
+ <select class="w-full px-3 py-2 border rounded" id="student-to-remove" disabled required>
117
+ <option value="">Select Student</option>
118
+ </select>
119
+ </div>
120
+ <button type="submit" class="w-full bg-red-600 text-white py-2 rounded hover:bg-red-700">
121
+ Remove Student
122
+ </button>
123
  </div>
 
 
 
124
  </form>
125
  </div>
126
+ </div>
127
 
128
  <!-- School Structure Management -->
129
  <div class="mt-6">
 
261
  document.getElementById('management-section').classList.toggle('hidden');
262
  });
263
 
264
+ // Toggle between add/remove student forms
265
+ const addStudentBtn = document.getElementById('add-student-btn');
266
+ const removeStudentBtn = document.getElementById('remove-student-btn');
267
+ const addFields = document.getElementById('add-student-fields');
268
+ const removeFields = document.getElementById('remove-student-fields');
269
+
270
+ addStudentBtn.addEventListener('click', function() {
271
+ addFields.classList.remove('hidden');
272
+ removeFields.classList.add('hidden');
273
+ addStudentBtn.classList.replace('bg-gray-200', 'bg-blue-600');
274
+ addStudentBtn.classList.replace('text-gray-700', 'text-white');
275
+ removeStudentBtn.classList.replace('bg-red-600', 'bg-gray-200');
276
+ removeStudentBtn.classList.replace('text-white', 'text-gray-700');
277
+ });
278
 
279
+ removeStudentBtn.addEventListener('click', function() {
280
+ addFields.classList.add('hidden');
281
+ removeFields.classList.remove('hidden');
282
+ removeStudentBtn.classList.replace('bg-gray-200', 'bg-red-600');
283
+ removeStudentBtn.classList.replace('text-gray-700', 'text-white');
284
+ addStudentBtn.classList.replace('bg-blue-600', 'bg-gray-200');
285
+ addStudentBtn.classList.replace('text-white', 'text-gray-700');
286
+ });
287
+
288
+ // Load students when class/form changes
289
+ document.getElementById('student-class').addEventListener('change', loadStudentsForManagement);
290
+ document.getElementById('student-form').addEventListener('change', loadStudentsForManagement);
291
+
292
+ // Handle form submission
293
+ document.getElementById('student-form').addEventListener('submit', function(e) {
294
  e.preventDefault();
295
+ const className = document.getElementById('student-class').value;
296
+ const form = document.getElementById('student-form').value;
 
297
 
298
+ if (!className || !form) {
299
+ showManagementMessage('Please select both class and form', 'error');
300
  return;
301
  }
302
 
 
303
  const key = `${className}-${form}`;
 
 
 
 
304
 
305
+ if (addFields.classList.contains('hidden')) {
306
+ // Remove student
307
+ const studentName = document.getElementById('student-to-remove').value;
308
+ if (!studentName) {
309
+ showManagementMessage('Please select a student', 'error');
310
+ return;
311
+ }
 
 
 
 
 
 
312
 
313
+ if (students[key]) {
314
+ students[key] = students[key].filter(name => name !== studentName);
315
+ localStorage.setItem('studentData', JSON.stringify(students));
316
+ showManagementMessage('Student removed successfully!');
317
+ loadStudentsForManagement();
318
+ this.reset();
319
+ }
320
+ } else {
321
+ // Add student
322
+ const studentName = document.getElementById('student-name').value;
323
+ if (!studentName) {
324
+ showManagementMessage('Please enter a student name', 'error');
325
+ return;
326
+ }
327
 
328
+ if (!students[key]) {
329
+ students[key] = [];
330
+ }
331
+ students[key].push(studentName);
 
 
332
  localStorage.setItem('studentData', JSON.stringify(students));
333
+ showManagementMessage('Student added successfully!');
 
 
334
  this.reset();
335
  }
336
  });
337
+ // Add class form
 
338
  document.getElementById('add-class-form').addEventListener('submit', function(e) {
339
  e.preventDefault();
340
  const newClassName = document.getElementById('new-class-name').value.trim().toUpperCase();
 
397
  showManagementMessage(`Class ${classToRemove} and all its students removed successfully!`);
398
  this.reset();
399
  });
400
+ // Load students for management dropdown
401
+ function loadStudentsForManagement() {
402
+ const classVal = document.getElementById('student-class').value;
403
+ const formVal = document.getElementById('student-form').value;
404
+ const studentSelect = document.getElementById('student-to-remove');
 
405
 
406
  studentSelect.innerHTML = '<option value="">Select Student</option>';
407
  studentSelect.disabled = true;
 
419
  }
420
  }
421
  }
422
+ // Show management message
 
423
  function showManagementMessage(message, type = 'success') {
424
  const messageDiv = document.getElementById('management-message');
425
  messageDiv.textContent = message;