Spaces:
Running
Running
Download script.js from Amanvid/feeflow-navigator: direct link, hf CLI and curl.
- Browser
- Download file 7.8 kB
-
https://huggingface.co/spaces/Amanvid/feeflow-navigator/resolve/main/script.js
- Command line
-
hf download hf://spaces/Amanvid/feeflow-navigator/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Amanvid/feeflow-navigator/resolve/main/script.js
7.8 kB
| // Shared JavaScript across all pages | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize sections | |
| const classSelection = document.getElementById('classSelection'); | |
| const studentSelection = document.getElementById('studentSelection'); | |
| const parentFormSection = document.getElementById('parentFormSection'); | |
| const feeResultSection = document.getElementById('feeResultSection'); | |
| // Navigation buttons | |
| const backToClassesBtn = document.getElementById('backToClasses'); | |
| const backToStudentsBtn = document.getElementById('backToStudents'); | |
| const backToParentFormBtn = document.getElementById('backToParentForm'); | |
| const newCheckBtn = document.getElementById('newCheckButton'); | |
| const printBtn = document.getElementById('printButton'); | |
| // Form elements | |
| const parentForm = document.getElementById('parentForm'); | |
| const selectedStudentInfo = document.getElementById('selectedStudentInfo'); | |
| const selectedClassTitle = document.getElementById('selectedClassTitle'); | |
| // Mock data for demonstration (in a real app, this would come from an API) | |
| const classes = ['Class 1', 'Class 2', 'Class 3', 'Class 4', 'Class 5', 'Class 6']; | |
| const studentsByClass = { | |
| 'Class 1': ['Alice Johnson', 'Bob Smith', 'Charlie Brown'], | |
| 'Class 2': ['David Wilson', 'Eva Green', 'Frank Ocean'], | |
| 'Class 3': ['Grace Kelly', 'Henry Ford', 'Ivy League'], | |
| 'Class 4': ['Jack Sparrow', 'Karen Smith', 'Liam Neeson'], | |
| 'Class 5': ['Mona Lisa', 'Noah Ark', 'Oliver Twist'], | |
| 'Class 6': ['Peter Pan', 'Quincy Jones', 'Rose Tyler'], | |
| }; | |
| // Initialize class cards | |
| const classCardsContainer = document.querySelector('#classSelection > div'); | |
| classes.forEach(className => { | |
| const classCard = document.createElement('class-card'); | |
| classCard.setAttribute('class-name', className); | |
| classCard.setAttribute('student-count', studentsByClass[className]?.length || 0); | |
| classCardsContainer.appendChild(classCard); | |
| }); | |
| // Class card click handler | |
| document.addEventListener('classCardClicked', function(e) { | |
| const className = e.detail.className; | |
| selectedClassTitle.textContent = className; | |
| // Populate student table | |
| const studentTableBody = document.getElementById('studentTableBody'); | |
| studentTableBody.innerHTML = ''; | |
| studentsByClass[className]?.forEach((student, index) => { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${student}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">STD-${(index + 1).toString().padStart(3, '0')}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"> | |
| <button class="select-student text-indigo-600 hover:text-indigo-900" data-student="${student}"> | |
| Select <i data-feather="chevron-right" class="inline"></i> | |
| </button> | |
| </td> | |
| `; | |
| studentTableBody.appendChild(row); | |
| }); | |
| // Show student selection section | |
| classSelection.classList.add('hidden'); | |
| studentSelection.classList.remove('hidden'); | |
| feather.replace(); | |
| }); | |
| // Back to classes button | |
| backToClassesBtn.addEventListener('click', function() { | |
| studentSelection.classList.add('hidden'); | |
| classSelection.classList.remove('hidden'); | |
| }); | |
| // Student row click handler | |
| document.addEventListener('click', function(e) { | |
| if (e.target.classList.contains('select-student') || e.target.closest('.select-student')) { | |
| const studentName = e.target.closest('button').dataset.student; | |
| const className = selectedClassTitle.textContent; | |
| selectedStudentInfo.textContent = `${studentName} (${className})`; | |
| // Show parent form section | |
| studentSelection.classList.add('hidden'); | |
| parentFormSection.classList.remove('hidden'); | |
| } | |
| }); | |
| // Back to students button | |
| backToStudentsBtn.addEventListener('click', function() { | |
| parentFormSection.classList.add('hidden'); | |
| studentSelection.classList.remove('hidden'); | |
| }); | |
| // Parent form submission | |
| parentForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const parentName = document.getElementById('parentName').value; | |
| const relationship = document.getElementById('relationship').value; | |
| const phoneNumber = document.getElementById('phoneNumber').value; | |
| // Validate phone number | |
| if (!/^\d{10}$/.test(phoneNumber)) { | |
| alert('Please enter a valid 10-digit phone number'); | |
| return; | |
| } | |
| // Mock fee data (in a real app, this would come from an API) | |
| const mockFeeData = { | |
| success: true, | |
| data: { | |
| logoURL: 'http://static.photos/education/200x200/42', | |
| schoolName: 'Prestige Academy', | |
| address: '123 Education Street, Accra', | |
| studentName: selectedStudentInfo.textContent.split(' (')[0], | |
| className: selectedClassTitle.textContent, | |
| fees: 1200, | |
| books: 300, | |
| arrears: 150, | |
| amountPaid: 1000, | |
| balance: 650, | |
| dueDate: '15th September 2023', | |
| momo: '0244 123 4567 (Prestige Academy)' | |
| } | |
| }; | |
| // Fill the fee result card | |
| fillFeeResultCard(mockFeeData); | |
| // Show fee result section | |
| parentFormSection.classList.add('hidden'); | |
| feeResultSection.classList.remove('hidden'); | |
| }); | |
| // Back to parent form button | |
| backToParentFormBtn.addEventListener('click', function() { | |
| feeResultSection.classList.add('hidden'); | |
| parentFormSection.classList.remove('hidden'); | |
| }); | |
| // New check button | |
| newCheckBtn.addEventListener('click', function() { | |
| feeResultSection.classList.add('hidden'); | |
| classSelection.classList.remove('hidden'); | |
| parentForm.reset(); | |
| }); | |
| // Print button | |
| printBtn.addEventListener('click', function() { | |
| window.print(); | |
| }); | |
| // Function to fill fee result card | |
| function fillFeeResultCard(data) { | |
| if (!data.success) return; | |
| const f = data.data; | |
| /* ---- header ---- */ | |
| document.getElementById('schoolLogo').src = f.logoURL; | |
| document.getElementById('schoolName').textContent = f.schoolName; | |
| document.getElementById('schoolAddress').textContent = f.address; | |
| /* ---- fee lines ---- */ | |
| document.getElementById('resultStudentName').textContent = f.studentName; | |
| document.getElementById('resultClassName').textContent = f.className; | |
| document.getElementById('resultTotalFees').textContent = 'GH₵ ' + (f.fees + f.books + f.arrears).toLocaleString(undefined, {minimumFractionDigits: 2}); | |
| document.getElementById('resultAmountPaid').textContent = 'GH₵ ' + f.amountPaid.toLocaleString(undefined, {minimumFractionDigits: 2}); | |
| document.getElementById('resultBalance').textContent = 'GH₵ ' + f.balance.toLocaleString(undefined, {minimumFractionDigits: 2}); | |
| /* ---- footer ---- */ | |
| document.getElementById('dueDate').textContent = f.dueDate; | |
| document.getElementById('paymentNumber').textContent = f.momo; | |
| } | |
| // Initialize feather icons | |
| feather.replace(); | |
| }); |