Changeset 43c9090 for src/main/resources/static/js/calendar.js
- Timestamp:
- 10/12/24 21:32:15 (5 weeks ago)
- Branches:
- master
- Parents:
- 743de55
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/js/calendar.js
r743de55 r43c9090 1 let lastClickedItem=null; 1 2 let calendar = document.querySelector('.calendar') 2 3 … … 19 20 document.getElementById("last-check").innerHTML=window.selectedTime; 20 21 showModal(); 22 document.getElementById("coupon-type").selectedIndex=0; 23 document.getElementById("medical-condition").innerHTML=''; 24 21 25 } 22 26 … … 71 75 function displayFreeAppointments(appointments) { 72 76 const container = document.getElementById('hourly-terms'); 73 container.innerHTML = ''; // Clear previous appointments77 container.innerHTML = ''; 74 78 75 79 appointments.forEach(appointment => { … … 88 92 89 93 appointmentDiv.textContent = formattedTime; 90 appointmentDiv.dataset.time = formattedDate+" "+formattedTime; // Store full date-time94 appointmentDiv.dataset.time = formattedDate+" "+formattedTime; 91 95 92 96 appointmentDiv.addEventListener('click', () => { 97 if(lastClickedItem){ 98 lastClickedItem.style.backgroundColor="white"; 99 } 100 lastClickedItem=appointmentDiv; 101 lastClickedItem.style.backgroundColor="grey"; 93 102 window.selectedTime = appointmentDiv.dataset.time; 94 103 document.getElementById('book-button').disabled = false; … … 109 118 110 119 let currDate = new Date() 111 if (!month) month = currDate.getMonth() 120 121 if (typeof month !== 'number') month = currDate.getMonth(); 112 122 if (!year) year = currDate.getFullYear() 113 123 … … 129 139 <span></span>`; 130 140 let selectedDate = `${year}-${(month + 1).toString().padStart(2, '0')}-${(i - first_day.getDay() + 1).toString().padStart(2, '0')}`; 131 day.addEventListener('click', () => fetchFreeOrPendingAppointments(selectedDate)); 141 day.addEventListener('click', () => { 142 let temp=document.getElementsByClassName('curr-date'); 143 Array.from(temp).forEach(element => { 144 element.classList.remove('curr-date'); 145 }); 146 day.classList.add('curr-date'); 147 document.getElementById("coupon-type").selectedIndex=0; 148 document.getElementById("medical-condition").value=''; 149 fetchFreeOrPendingAppointments(selectedDate); 150 }) 132 151 133 152 if (i - first_day.getDay() + 1 === currDate.getDate() && year === currDate.getFullYear() && month === currDate.getMonth()) { … … 176 195 177 196 178 197 window.onload = async function () { 198 temp=document.getElementById("coupon-type"); 199 try{ 200 const response = await fetch(`/api/coupons/getCouponNames`); 201 if (response.ok) { 202 const couponNames = await response.json(); 203 console.log("Coupons:", couponNames); 204 205 couponNames.forEach(coupon => { 206 const option = document.createElement("option"); 207 option.value = coupon; 208 option.textContent = coupon; 209 temp.appendChild(option); 210 }); 211 } else { 212 console.log(response.statusText); 213 } 214 } 215 catch(error){ 216 console.error("Error fetching coupons:", error); 217 } 218 219 };
Note:
See TracChangeset
for help on using the changeset viewer.