EHDEM commited on
Commit
c7fa340
·
verified ·
1 Parent(s): 801f72d

MAKE ATTENDANCE.HTML FUNCTIONAL

Browse files
Files changed (1) hide show
  1. attendance.html +32 -22
attendance.html CHANGED
@@ -271,9 +271,8 @@ function updateDateTime() {
271
  attendanceForm.classList.remove('hidden');
272
  successMessage.classList.add('hidden');
273
  });
274
-
275
  // Submit form
276
- submitBtn.addEventListener('click', function() {
277
  // Validate form
278
  const studentClass = document.getElementById('class').value;
279
  const form = document.getElementById('form').value;
@@ -296,20 +295,30 @@ function updateDateTime() {
296
  attendance: attendance,
297
  class: studentClass,
298
  form: form,
299
- studentName: student
300
  };
301
- // Send data to GitHub
302
- const success = await sendDataToGitHub(data);
303
-
304
- if (success) {
305
- // Show success message
306
- attendanceForm.classList.add('hidden');
307
- successMessage.classList.remove('hidden');
308
- successMessage.classList.add('fade-in');
309
- }
310
- });
311
 
312
- // Sample menu data (in a real app, this would come from a database)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  const menus = {
314
  breakfast: {
315
  regular: [
@@ -537,7 +546,7 @@ function updateDateTime() {
537
  'Accept': 'application/vnd.github.v3+json'
538
  },
539
  body: JSON.stringify({
540
- message: `New attendance record - ${data.studentName}`,
541
  content: btoa(newContent),
542
  sha: sha || undefined, // Only include if file exists
543
  branch: 'main'
@@ -553,8 +562,7 @@ function updateDateTime() {
553
  return true;
554
  } catch (error) {
555
  console.error('Error sending data to GitHub:', error);
556
- alert('Failed to submit attendance. Please try again later.');
557
- return false;
558
  }
559
  }
560
  // Student data organized by class and form
@@ -669,7 +677,7 @@ function updateDateTime() {
669
  }
670
  });
671
  });
672
- // Function to reset the form
673
  function resetForm() {
674
  // Clear form fields
675
  document.getElementById('class').value = '';
@@ -678,8 +686,8 @@ function updateDateTime() {
678
  document.getElementById('student').disabled = true;
679
  document.getElementById('student-container').classList.add('hidden');
680
  document.querySelector('input[name="attendance"][value="yes"]').checked = true;
681
- eatingDetails.classList.remove('hidden');
682
- // Hide success message and show form
683
  successMessage.classList.add('hidden');
684
  attendanceForm.classList.remove('hidden');
685
 
@@ -687,10 +695,12 @@ function updateDateTime() {
687
  if (isCurrentTimeMealPeriod()) {
688
  document.getElementById('menu-display-container').classList.remove('hidden');
689
  attendanceForm.classList.add('hidden');
 
 
 
690
  }
691
  }
692
-
693
- // Update menu periodically to reflect current meal time
694
  setInterval(() => {
695
  const currentMeal = getCurrentMealTime();
696
  if (currentMeal !== selectedMeal) {
 
271
  attendanceForm.classList.remove('hidden');
272
  successMessage.classList.add('hidden');
273
  });
 
274
  // Submit form
275
+ submitBtn.addEventListener('click', async function() {
276
  // Validate form
277
  const studentClass = document.getElementById('class').value;
278
  const form = document.getElementById('form').value;
 
295
  attendance: attendance,
296
  class: studentClass,
297
  form: form,
298
+ studentName: attendance === 'yes' ? student : 'N/A'
299
  };
 
 
 
 
 
 
 
 
 
 
300
 
301
+ try {
302
+ // Send data to GitHub
303
+ const success = await sendDataToGitHub(data);
304
+
305
+ if (success) {
306
+ // Show success message
307
+ attendanceForm.classList.add('hidden');
308
+ successMessage.classList.remove('hidden');
309
+ successMessage.classList.add('fade-in');
310
+
311
+ // Store record in localStorage for reports
312
+ let records = JSON.parse(localStorage.getItem('attendanceRecords') || '[]');
313
+ records.push(data);
314
+ localStorage.setItem('attendanceRecords', JSON.stringify(records));
315
+ }
316
+ } catch (error) {
317
+ console.error('Error submitting attendance:', error);
318
+ alert('Failed to submit attendance. Please try again.');
319
+ }
320
+ });
321
+ // Sample menu data (in a real app, this would come from a database)
322
  const menus = {
323
  breakfast: {
324
  regular: [
 
546
  'Accept': 'application/vnd.github.v3+json'
547
  },
548
  body: JSON.stringify({
549
+ message: `New attendance record - ${new Date().toISOString()}`,
550
  content: btoa(newContent),
551
  sha: sha || undefined, // Only include if file exists
552
  branch: 'main'
 
562
  return true;
563
  } catch (error) {
564
  console.error('Error sending data to GitHub:', error);
565
+ throw error; // Re-throw to be caught by calling function
 
566
  }
567
  }
568
  // Student data organized by class and form
 
677
  }
678
  });
679
  });
680
+ // Function to reset the form
681
  function resetForm() {
682
  // Clear form fields
683
  document.getElementById('class').value = '';
 
686
  document.getElementById('student').disabled = true;
687
  document.getElementById('student-container').classList.add('hidden');
688
  document.querySelector('input[name="attendance"][value="yes"]').checked = true;
689
+
690
+ // Hide success message and show form
691
  successMessage.classList.add('hidden');
692
  attendanceForm.classList.remove('hidden');
693
 
 
695
  if (isCurrentTimeMealPeriod()) {
696
  document.getElementById('menu-display-container').classList.remove('hidden');
697
  attendanceForm.classList.add('hidden');
698
+ } else {
699
+ document.getElementById('menu-display-container').classList.add('hidden');
700
+ attendanceForm.classList.remove('hidden');
701
  }
702
  }
703
+ // Update menu periodically to reflect current meal time
 
704
  setInterval(() => {
705
  const currentMeal = getCurrentMealTime();
706
  if (currentMeal !== selectedMeal) {