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/admin-terms.js

    r743de55 r43c9090  
    11import { deleteAppointment, confirmCarriedOut, getUsersByTermExcept, removeRequestAndUpdateUser, removeAppointment, makeReservation ,displayDiv} from './shared.js';
    22
     3let lastClickedItem=null;
    34let calendar = document.querySelector('.calendar')
    45let importantDate;
     
    109110    }));
    110111
    111     await fetch(`/api/appointments/create`, {
     112    const response=await fetch(`/api/appointments/create`, {
    112113        method: 'POST',
    113114        headers: {
    114115            'Content-Type': 'application/json',
    115116        },
    116         body: JSON.stringify(requestBody) // Send all appointments in one request
     117        body: JSON.stringify(requestBody)
    117118    });
     119    if(response.ok){
     120        location.reload();
     121    }
     122
    118123}
    119124document.getElementById('create-appointments').addEventListener('click', async function () {
     
    124129    const interval = parseInt(document.getElementById('time-interval').value);
    125130
    126     if (!startDate || !endDate || !startTime || !endTime || !interval) {
     131    if (!startDate || !endDate || !startTime || !endTime || isNaN(interval)) {
    127132        alert("Please fill out all the fields.");
    128133        return;
     
    142147            const existingTimes = existingMapped.get(date);
    143148            if (checkOverlap(existingTimes, time)) {
    144                 conflictingAppointments.push(newAppointment);  // Add to conflict list if overlaps
     149                conflictingAppointments.push(newAppointment);
    145150            } else {
    146151                successfulAppointments.push(newAppointment);
     
    240245        requestedRow.appendChild(couponCodeTd);
    241246        requestedElement.appendChild(requestedRow);
    242         displayDiv(dateTime);
    243247    })
     248    displayDiv(dateTime);
    244249}
    245250function getAllRequests(dateTime,containerId){
     
    277282
    278283        itemDiv.addEventListener('click', async () => {
     284            document.getElementById("summary").style.display='none';
    279285            try{
    280 
     286                if(lastClickedItem){
     287                    lastClickedItem.style.backgroundColor="#f9f9f9";
     288                }
     289                lastClickedItem=itemDiv;
     290                itemDiv.style.backgroundColor="grey";
    281291                const isReserved=await isAppointmentReserved(item.localDateTime);
    282292                const isEmpty=await isAppointmentEmpty(item.localDateTime);
     
    285295                cleanData("requested")
    286296                if (isReserved) {
     297                    document.getElementById("summary").style.display='block';
    287298                    document.getElementById("approved-table").style.display = 'block';
    288299                    document.getElementById("requested-table").style.display = 'none';
     
    292303                    deleteBtn.setAttribute("term",item.localDateTime);
    293304                    deleteBtn.setAttribute("type","cancelledAppointmentByAdmin");
    294                     //da go isprogramirash delete-approval
    295305                    document.getElementById("delete-approval").addEventListener('click', function() {
    296306                        removeAppointment(item.localDateTime,"cancelledAppointmentByAdmin");
     
    307317                }
    308318                else if(!isEmpty){
     319                    document.getElementById("summary").style.display='block';
    309320                    document.getElementById("approved-table").style.display = 'none';
    310321                    document.getElementById("requested-table").style.display = 'block';
     
    316327                }
    317328                else{
     329                    document.getElementById("summary").style.display='none';
    318330                    document.getElementById("approved-table").style.display = 'none';
    319331                    document.getElementById("requested-table").style.display = 'none';
     
    365377    let currDate = new Date()
    366378
    367     // if (!month) month = currDate.getMonth()
    368379    console.log(month);
    369380    if (typeof month !== 'number') month = currDate.getMonth();
     
    374385    calendar_header_year.innerHTML = year
    375386
    376     // get first day of month
    377387
    378388    let first_day = new Date(year, month, 1)
     
    395405            }
    396406            day.addEventListener('click', () => {
     407                document.getElementById("summary").style.display='none';
    397408                let temp=document.getElementsByClassName('curr-date');
    398409                Array.from(temp).forEach(element => {
     
    458469    const otherPickersInterval = 30;
    459470
    460     for (let hour = 7; hour < 22; hour++) { // 0 to 23 for 24-hour format
     471    for (let hour = 7; hour < 22; hour++) {
    461472        for (let minutes = 0; minutes < 60; minutes++) {
    462473            const formattedHour = hour.toString().padStart(2, '0');
     
    504515        .then(data => {
    505516            console.log(data.message);
     517            location.reload();
    506518        })
    507519        .catch(error => {
     
    525537        if (response.ok) {
    526538            alert("Free appointments for the selected date range were deleted.");
     539            location.reload();
    527540        } else {
    528541            alert("An error occurred while trying to delete the appointments.");
Note: See TracChangeset for help on using the changeset viewer.