| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- "use strict";
- window.onload = async function () {
- await getAppointment();
- }
- // Function to format time as HH:MM
- function formatTime(date) {
- const hours = date.getHours().toString().padStart(2, '0'); // Get hours and ensure two digits
- const minutes = date.getMinutes().toString().padStart(2, '0'); // Get minutes and ensure two digits
- return `${hours}:${minutes}`;
- }
- // Function to get time span (from 11:00 to 12:00 format)
- function getTimeSpan(start, end) {
- const startTime = formatTime(start);
- const endTime = formatTime(end);
- return `${startTime} to ${endTime}`;
- }
- async function getAppointment() {
- const urlParams = new URLSearchParams(window.location.search);
- const appointment = urlParams.get('appointment');
- if (!appointment) {
- window.location.replace("/html/404.html");
- }
- let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
- const response = await fetch(`/api/schedule?appointmentId=${appointment}`, options)
- .catch(err => console.error('error:' + err));
- if (response.status === 404) {
- window.location.replace("/html/404.html");
- }
- if (response.status === 410) {
- window.location.replace("/html/410.html");
- }
- const js = await response.json();
- displayAppointmentDetails(js);
- }
- function displayAppointmentDetails(appointment) {
- // Update the innerHTML of the elements to display the appointment details
- document.getElementById('appointment-date').innerText = appointment._id;
- document.getElementById('title').innerText = appointment.title;
- document.getElementById('description').innerText = appointment.description;
- // Format the dates to a more user-friendly format
- const dueDate = new Date(appointment.dueDate).toLocaleDateString();
- const startDate = new Date(appointment.startDate);
- const endDate = new Date(appointment.endDate);
- const startDateFormatted = startDate.toLocaleString();
- const endDateFormatted = endDate.toLocaleString();
- console.log(dueDate);
- console.log(startDate);
- console.log(endDate);
- document.getElementById('due-date').value = dueDate;
- document.getElementById('appointment-date').value = startDateFormatted;
- document.getElementById('time-span').value = getTimeSpan(startDate, endDate);
- // Set place
- document.getElementById('place').innerText = appointment.place;
- }
|