Changeset 43c9090 for src/main/resources/static/js
- Timestamp:
- 10/12/24 21:32:15 (3 months ago)
- Branches:
- master
- Parents:
- 743de55
- Location:
- src/main/resources/static/js
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/js/admin-terms.js
r743de55 r43c9090 1 1 import { deleteAppointment, confirmCarriedOut, getUsersByTermExcept, removeRequestAndUpdateUser, removeAppointment, makeReservation ,displayDiv} from './shared.js'; 2 2 3 let lastClickedItem=null; 3 4 let calendar = document.querySelector('.calendar') 4 5 let importantDate; … … 109 110 })); 110 111 111 await fetch(`/api/appointments/create`, {112 const response=await fetch(`/api/appointments/create`, { 112 113 method: 'POST', 113 114 headers: { 114 115 'Content-Type': 'application/json', 115 116 }, 116 body: JSON.stringify(requestBody) // Send all appointments in one request117 body: JSON.stringify(requestBody) 117 118 }); 119 if(response.ok){ 120 location.reload(); 121 } 122 118 123 } 119 124 document.getElementById('create-appointments').addEventListener('click', async function () { … … 124 129 const interval = parseInt(document.getElementById('time-interval').value); 125 130 126 if (!startDate || !endDate || !startTime || !endTime || !interval) {131 if (!startDate || !endDate || !startTime || !endTime || isNaN(interval)) { 127 132 alert("Please fill out all the fields."); 128 133 return; … … 142 147 const existingTimes = existingMapped.get(date); 143 148 if (checkOverlap(existingTimes, time)) { 144 conflictingAppointments.push(newAppointment); // Add to conflict list if overlaps149 conflictingAppointments.push(newAppointment); 145 150 } else { 146 151 successfulAppointments.push(newAppointment); … … 240 245 requestedRow.appendChild(couponCodeTd); 241 246 requestedElement.appendChild(requestedRow); 242 displayDiv(dateTime);243 247 }) 248 displayDiv(dateTime); 244 249 } 245 250 function getAllRequests(dateTime,containerId){ … … 277 282 278 283 itemDiv.addEventListener('click', async () => { 284 document.getElementById("summary").style.display='none'; 279 285 try{ 280 286 if(lastClickedItem){ 287 lastClickedItem.style.backgroundColor="#f9f9f9"; 288 } 289 lastClickedItem=itemDiv; 290 itemDiv.style.backgroundColor="grey"; 281 291 const isReserved=await isAppointmentReserved(item.localDateTime); 282 292 const isEmpty=await isAppointmentEmpty(item.localDateTime); … … 285 295 cleanData("requested") 286 296 if (isReserved) { 297 document.getElementById("summary").style.display='block'; 287 298 document.getElementById("approved-table").style.display = 'block'; 288 299 document.getElementById("requested-table").style.display = 'none'; … … 292 303 deleteBtn.setAttribute("term",item.localDateTime); 293 304 deleteBtn.setAttribute("type","cancelledAppointmentByAdmin"); 294 //da go isprogramirash delete-approval295 305 document.getElementById("delete-approval").addEventListener('click', function() { 296 306 removeAppointment(item.localDateTime,"cancelledAppointmentByAdmin"); … … 307 317 } 308 318 else if(!isEmpty){ 319 document.getElementById("summary").style.display='block'; 309 320 document.getElementById("approved-table").style.display = 'none'; 310 321 document.getElementById("requested-table").style.display = 'block'; … … 316 327 } 317 328 else{ 329 document.getElementById("summary").style.display='none'; 318 330 document.getElementById("approved-table").style.display = 'none'; 319 331 document.getElementById("requested-table").style.display = 'none'; … … 365 377 let currDate = new Date() 366 378 367 // if (!month) month = currDate.getMonth()368 379 console.log(month); 369 380 if (typeof month !== 'number') month = currDate.getMonth(); … … 374 385 calendar_header_year.innerHTML = year 375 386 376 // get first day of month377 387 378 388 let first_day = new Date(year, month, 1) … … 395 405 } 396 406 day.addEventListener('click', () => { 407 document.getElementById("summary").style.display='none'; 397 408 let temp=document.getElementsByClassName('curr-date'); 398 409 Array.from(temp).forEach(element => { … … 458 469 const otherPickersInterval = 30; 459 470 460 for (let hour = 7; hour < 22; hour++) { // 0 to 23 for 24-hour format471 for (let hour = 7; hour < 22; hour++) { 461 472 for (let minutes = 0; minutes < 60; minutes++) { 462 473 const formattedHour = hour.toString().padStart(2, '0'); … … 504 515 .then(data => { 505 516 console.log(data.message); 517 location.reload(); 506 518 }) 507 519 .catch(error => { … … 525 537 if (response.ok) { 526 538 alert("Free appointments for the selected date range were deleted."); 539 location.reload(); 527 540 } else { 528 541 alert("An error occurred while trying to delete the appointments."); -
src/main/resources/static/js/adminNewsCoupons.js
r743de55 r43c9090 6 6 let selectedImage; 7 7 let questionable; 8 let helper; 8 9 9 10 let pageType; … … 38 39 imagePreview.style.display='inline'; 39 40 imagePreview.innerHTML = `<img src="${e.target.result}" style="width: 100%; height: auto;">`; 40 selectedImage =e.target.result ; // Store the selected file41 selectedImage =e.target.result ; 41 42 42 43 console.log(selectedImage); … … 300 301 document.getElementById('text').value = param2; 301 302 let importantValue=newsItem.querySelector('img').getAttribute("data-attribute"); 303 selectedImage=importantValue; 302 304 document.getElementById('main-image').innerHTML=`<img src="${importantValue}" style="width: 20%; height: 20%;">`; 303 305 } -
src/main/resources/static/js/authentication-shared.js
r743de55 r43c9090 9 9 10 10 function phoneCheck(phone){ 11 const phonePattern = /^07\d -\d{3}-\d{3}$/;11 const phonePattern = /^07\d\d{3}\d{3}$/; 12 12 if (!phonePattern.test(phone)) { 13 13 return false; … … 32 32 return regex.test(password); 33 33 } 34 export async function verificationCheck(userData ) {34 export async function verificationCheck(userData,condition) { 35 35 if (!usernameCheck(userData.username)) { 36 36 alert("Invalid username"); … … 56 56 } 57 57 } 58 const response = await fetch(`/api/users/checkDifferentUser`, { 59 method: "POST", 60 headers: { 61 'Content-Type': 'application/json' 62 }, 63 body: JSON.stringify(userData) 64 }); 65 if (response.ok) { 66 return true; 67 } else { 68 return false; 58 if(condition!==false){ 59 const response = await fetch(`/api/users/checkDifferentUser`, { 60 method: "POST", 61 headers: { 62 'Content-Type': 'application/json' 63 }, 64 body: JSON.stringify(userData) 65 }); 66 if (response.ok) { 67 return true; 68 } else { 69 return false; 70 } 69 71 } 70 72 return true; 71 73 } -
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 }; -
src/main/resources/static/js/editUser.js
r743de55 r43c9090 3 3 import { verificationCheck } from './authentication-shared.js'; 4 4 5 let loggedPerson ;5 let loggedPerson,checkDifferent; 6 6 const modal = document.getElementById('popupModal'); 7 7 const cancelBtn = document.getElementById('cancelBtn'); … … 71 71 counter= user.carriedOut.length; 72 72 } 73 console.log(counter);74 73 return counter; 75 74 } … … 122 121 buttonCell.appendChild(button1); 123 122 button2.textContent = "Потврди одржан"; 124 button 2.addEventListener('click',()=>125 function(){123 buttonCell.appendChild(button2); 124 button2.addEventListener('click',()=> { 126 125 modal.style.display='flex'; 127 approveBtn.addEventListener('click', () => { 128 const userInput = document.getElementById('userInput').value; 129 confirmCarriedOut(request.term,userInput); 130 modal.style.display = 'none'; // Close the modal after approval 131 }); 126 document.getElementById("userInput").disabled=false; 132 127 }); 133 buttonCell.appendChild(button2); 128 approveBtn.addEventListener('click', () => { 129 const userInput = document.getElementById('userInput').value; 130 confirmCarriedOut(request.term,userInput); 131 modal.style.display = 'none'; 132 }); 133 134 134 } 135 135 … … 146 146 if(selectedValue==="requests"){ 147 147 url=`/api/requests/listAll?username=${loggedPerson.username}`; 148 tHeadArray=["Термин", 148 tHeadArray=["Термин","Медицинска состојба","Опции"]; 149 149 createHeader(tHeadArray); 150 150 getAll(url); … … 153 153 let testTemp="RESERVED"; 154 154 url=`/api/appointments/listAll?username=${loggedPerson.username}&status=${testTemp}`; 155 tHeadArray=["Термин", "Опции"];155 tHeadArray=["Термин","Медицинска состојба", "Опции"]; 156 156 createHeader(tHeadArray); 157 157 getAll(url); … … 230 230 .catch(error => { 231 231 console.error('Error fetching user data:', error); 232 return { name: '', surname: '' }; // return empty values on error232 return { name: '', surname: '' }; 233 233 }); 234 234 } … … 267 267 if (cookieUsername) { 268 268 fetchUserData(cookieUsername,"USER").then(userData => { 269 const fullName = `${userData.name} ${userData.surname}`; 270 document.getElementById('cookie-name').innerHTML = fullName; 269 console.log("success") 271 270 }); 272 } else {273 document.getElementById('cookie-name').textContent = 'Default Name';274 271 } 275 272 } … … 277 274 function saveProfileChanges() { 278 275 const userName = document.querySelector('input[name="username"]').value; 279 console.log(userName); 276 const phoneNum=document.querySelector('input[name="phone"]').value.replace(/-/g,"") 277 console.log(phoneNum); 280 278 const updatedData = { 281 279 username: userName, 282 280 name: document.querySelector('input[name="firstName"]').value, 283 281 surname: document.querySelector('input[name="lastName"]').value, 284 phone: document.querySelector('input[name="phone"]').value,282 phone: phoneNum, 285 283 age: document.querySelector('input[name="age"]').value 286 284 }; 287 if(!verificationCheck(updatedData )){285 if(!verificationCheck(updatedData,checkDifferent)){ 288 286 return; 289 287 } … … 299 297 .then(data => { 300 298 alert('Profile updated successfully!'); 301 toggleEditing(false); // Disable fields after saving changes299 toggleEditing(false); 302 300 updateCookieUsername(userName); 303 301 }) … … 313 311 }; 314 312 } 313 function removeOptions(){ 314 if(getRoleFromCookie()!=="ADMIN"){ 315 let temp=this; 316 temp.removeChild(document.getElementById("requests")); 317 temp.removeChild(document.getElementById("appointments")) 318 } 319 } 315 320 316 321 function toggleEditing(isEnabled) { … … 322 327 323 328 window.onload = function(){ 329 checkDifferent=true; 324 330 updateProfile(); 325 331 toggleEditing(false); 326 332 document.getElementById('edit-profile').addEventListener('click', function() { 327 333 const role=getQueryParams(); 328 if(role.param1 ==='ADMIN') 329 toggleEditing(true); 334 if(role.param1 ==='ADMIN'){ 335 toggleEditing(true); 336 checkDifferent=false; 337 } 338 330 339 }); 331 340 document.getElementById('saveChanges').addEventListener('click', saveProfileChanges); 332 341 document.getElementById("statusDropdown").addEventListener('change',createRowsBasedOnType); 333 334 } 342 document.getElementById("statusDropdown").addEventListener('click',removeOptions); 343 } -
src/main/resources/static/js/index.js
r743de55 r43c9090 1 1 import { verificationCheck } from "./authentication-shared.js"; 2 3 2 function toggleForm(formId, show) { 4 3 const form = document.getElementById(formId); … … 60 59 }); 61 60 } 61 else{ 62 alert("Sign in successfull! Now log in!") 63 } 62 64 return response.json(); 63 65 }) 64 66 .then(data => { 65 console.log(data.message); // Handle success message67 console.log(data.message); 66 68 }) 67 69 .catch(error => { … … 97 99 console.log('Parsed data:', data); 98 100 if (data.success) { 99 const name=data.name;100 const surname=data.surname;101 const personalisedSection=document.getElementById("personalised");102 personalisedSection.innerHTML=`Добредојде, ${name} ${surname}!`;103 101 updateUIBasedOnRole(data.userRole); 104 102 } … … 108 106 }) 109 107 .finally(() => { 110 // Close the form after handling the response111 108 toggleForm('loginForm', false); 112 109 }); -
src/main/resources/static/js/shared.js
r743de55 r43c9090 21 21 if (!response.ok) { 22 22 throw new Error('Failed to delete the appointment'); 23 } 24 else{ 25 location.reload(); 23 26 } 24 27 }) … … 47 50 48 51 if (updateResponse.ok) { 52 location.reload(); 49 53 console.log(`User updated successfully in carried_out`); 50 54 } else { … … 136 140 137 141 } 142 location.reload(); 138 143 139 144 } else { … … 149 154 if (response.ok) { 150 155 console.log('Appointment added successfully.'); 156 location.reload(); 151 157 } else { 152 158 const text = await response.text(); … … 160 166 export function displayDiv(dateTime,username){ 161 167 if (typeof username !== 'undefined'){ 162 makeReservation(dateTime, username);168 makeReservation(dateTime, username); 163 169 } 164 170 else{ 165 const inputValue = document.getElementById("username-approval"); 166 const approvedUser = inputValue.value; 167 document.getElementById("confirm-approval").addEventListener('click',makeReservation(dateTime,approvedUser)); 171 let temp=document.getElementById("confirm-approval"); 172 temp.addEventListener('click',()=>{ 173 const approvedUser = document.getElementById("username-approval").value; 174 makeReservation(dateTime,approvedUser) 175 }); 168 176 } 169 177 } -
src/main/resources/static/js/terms.js
r743de55 r43c9090 50 50 dialog.setAttribute("id","dialogPopUp"); 51 51 const message = document.createElement('p'); 52 message.textContent = ' Are you sure you want to cancel the reservation?';52 message.textContent = 'Дали сте сигурни дека сакате да откажете?'; 53 53 dialog.appendChild(message); 54 54 const yesButton = document.createElement('button'); … … 107 107 row.appendChild(termCell); 108 108 const nameCell = document.createElement('td'); 109 nameCell.textContent = request.name; // Format date109 nameCell.textContent = request.name; 110 110 row.appendChild(nameCell); 111 111 const surnameCell = document.createElement('td'); 112 surnameCell.textContent = request.surname; // Format date112 surnameCell.textContent = request.surname; 113 113 row.appendChild(surnameCell); 114 114 const couponCodeCell = document.createElement('td'); … … 119 119 row.appendChild(additionalInfoCell); 120 120 const usernameCell = document.createElement('td'); 121 usernameCell.textContent = request.username; // Format date121 usernameCell.textContent = request.username; 122 122 row.appendChild(usernameCell); 123 123 const buttonCell = document.createElement('td'); … … 139 139 const oldHead = document.getElementById('initial-head'); 140 140 if (thead) { 141 console.log("cleaned")142 141 thead.innerHTML = ''; 143 142 } … … 165 164 const row = document.createElement('tr'); 166 165 const termCell = document.createElement('td'); 167 termCell.textContent = replaceWithSpace(request.dateTime); // Format date166 termCell.textContent = replaceWithSpace(request.dateTime); 168 167 row.appendChild(termCell); 169 168 const userCell = document.createElement('td'); … … 171 170 row.appendChild(userCell); 172 171 const adminCell = document.createElement('td'); 173 adminCell.textContent = request.adminNote; // Format date172 adminCell.textContent = request.adminNote; 174 173 row.appendChild(adminCell); 175 174 const statusCell = document.createElement('td'); -
src/main/resources/static/js/users-view.js
r743de55 r43c9090 12 12 } 13 13 function calculateAge(dateBirth){ 14 console.log(dateBirth);15 14 const [year, month, day] = dateBirth.split('-').map(Number); 16 15 const birthDate = new Date(year, month - 1, day); … … 55 54 button.addEventListener('click',()=>{ 56 55 let temp=user.username; 57 console.log(temp);58 56 const params = new URLSearchParams({ param1: 'ADMIN', param2: temp }).toString(); 59 57 window.location.href = `editUser.html?${params}`; … … 90 88 document.getElementById("search-input-container").style.display = 'none'; 91 89 const selectedValue = event.currentTarget.value; 92 console.log(selectedValue);93 90 if(selectedValue!=='defaultValue') 94 91 filterUsers("status",selectedValue).then(r => console.log(r)); … … 98 95 setInitialSelectValue(userStatusElement); 99 96 const dataCheck = event.currentTarget.value; 100 console.log(dataCheck);101 97 updateSearchInputVisibility(dataCheck); 102 98 103 99 document.getElementById("search-button").addEventListener('click',function (){ 104 100 let filterTemp=document.getElementById("search-input"); 105 console.log(filterTemp.value);106 101 filterUsers(dataCheck,filterTemp.value).then(r => console.log(r)); 107 102 filterTemp.value='';
Note:
See TracChangeset
for help on using the changeset viewer.