Ignore:
Timestamp:
10/12/24 21:32:15 (5 weeks ago)
Author:
macagaso <gasoskamarija@…>
Branches:
master
Parents:
743de55
Message:

Updated version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/js/calendar.js

    r743de55 r43c9090  
     1let lastClickedItem=null;
    12let calendar = document.querySelector('.calendar')
    23
     
    1920        document.getElementById("last-check").innerHTML=window.selectedTime;
    2021        showModal();
     22        document.getElementById("coupon-type").selectedIndex=0;
     23        document.getElementById("medical-condition").innerHTML='';
     24
    2125    }
    2226
     
    7175function displayFreeAppointments(appointments) {
    7276    const container = document.getElementById('hourly-terms');
    73     container.innerHTML = ''; // Clear previous appointments
     77    container.innerHTML = '';
    7478
    7579    appointments.forEach(appointment => {
     
    8892
    8993        appointmentDiv.textContent = formattedTime;
    90         appointmentDiv.dataset.time = formattedDate+" "+formattedTime; // Store full date-time
     94        appointmentDiv.dataset.time = formattedDate+" "+formattedTime;
    9195
    9296        appointmentDiv.addEventListener('click', () => {
     97            if(lastClickedItem){
     98                lastClickedItem.style.backgroundColor="white";
     99            }
     100            lastClickedItem=appointmentDiv;
     101            lastClickedItem.style.backgroundColor="grey";
    93102            window.selectedTime = appointmentDiv.dataset.time;
    94103            document.getElementById('book-button').disabled = false;
     
    109118
    110119    let currDate = new Date()
    111     if (!month) month = currDate.getMonth()
     120
     121    if (typeof month !== 'number') month = currDate.getMonth();
    112122    if (!year) year = currDate.getFullYear()
    113123
     
    129139                            <span></span>`;
    130140            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            })
    132151
    133152            if (i - first_day.getDay() + 1 === currDate.getDate() && year === currDate.getFullYear() && month === currDate.getMonth()) {
     
    176195
    177196
    178 
     197window.onload = async function () {
     198temp=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.