diff --git a/appointment/__init__.py b/appointment/__init__.py index a3f5e75..e1badb1 100644 --- a/appointment/__init__.py +++ b/appointment/__init__.py @@ -5,4 +5,4 @@ __package_name__ = "django-appointment" __url__ = "https://github.com/adamspd/django-appointment" __version__ = "3.0.0" -__test_version__ = True +__test_version__ = False diff --git a/appointment/services.py b/appointment/services.py index e144081..e8a4527 100644 --- a/appointment/services.py +++ b/appointment/services.py @@ -26,7 +26,7 @@ day_off_exists_for_date_range, exclude_booked_slots, get_all_appointments, get_all_staff_members, get_appointment_by_id, get_appointments_for_date_and_time, get_staff_member_appointment_list, get_staff_member_from_user_id_or_logged_in, get_times_from_config, get_user_by_email, - get_working_hours_for_staff_and_day, working_hours_exist) + get_working_hours_for_staff_and_day, parse_name, working_hours_exist) from appointment.utils.error_codes import ErrorCode from appointment.utils.json_context import convert_appointment_to_json, get_generic_context, json_response from appointment.utils.permissions import check_entity_ownership @@ -310,8 +310,10 @@ def save_appointment(appt, client_name, client_email, start_time, phone_number, :return: The modified appointment. """ # Modify and save client details + first_name, last_name = parse_name(client_name) client = appt.client - client.name = client_name + client.first_name = first_name + client.last_name = last_name client.email = client_email client.save() @@ -593,7 +595,6 @@ def create_new_appointment(data, request): def update_existing_appointment(data, request): try: appt = Appointment.objects.get(id=data.get("appointment_id")) - print(f"want_reminder: {data.get('want_reminder')}") want_reminder = data.get("want_reminder") == 'true' appt = save_appointment( appt, diff --git a/appointment/static/js/app_admin/staff_index.js b/appointment/static/js/app_admin/staff_index.js index 1a5e8b0..aef40ee 100644 --- a/appointment/static/js/app_admin/staff_index.js +++ b/appointment/static/js/app_admin/staff_index.js @@ -184,6 +184,7 @@ function displayEventList(events, date) { for (let item of eventItems) { item.addEventListener('click', function () { const eventId = this.getAttribute('data-event-id'); + AppState.eventIdSelected = eventId; showEventModal(eventId, false, false).then(r => r); }); } @@ -320,6 +321,16 @@ function confirmDeleteAppointment(appointmentId) { } showErrorModal(data.message, successTxt); closeConfirmModal(); // Close the confirmation modal + + // Remove the deleted appointment from the global appointments array + appointments = appointments.filter(appointment => appointment.id !== appointmentId); + + // Refresh the event list for the current date + const currentDate = AppState.calendar.getDate(); + const dateEvents = appointments + .filter(event => moment(currentDate).isSame(event.start_time, 'day')) + .sort((a, b) => new Date(a.start_time) - new Date(b.start_time)); + displayEventList(dateEvents, currentDate); }) .catch(error => { console.error('Error:', error); @@ -410,7 +421,6 @@ async function updateAppointmentDate(event, revertFunction) { const responseData = await response.json(); if (response.ok) { - console.log("Updated message: " + responseData.message) showErrorModal(responseData.message, successTxt) } else { console.error('Failed to update appointment date. Server responded with:', response.statusText); @@ -533,6 +543,7 @@ function adjustModalButtonsVisibility(isEditMode, isCreatingMode) { // ################################################################ // function toggleEditMode() { + console.log("I was called in toggleEditMode") const modal = document.getElementById("eventDetailsModal"); const appointment = appointments.find(app => Number(app.id) === Number(AppState.eventIdSelected)); AppState.isCreating = false; // Turn off creating mode @@ -541,6 +552,8 @@ function toggleEditMode() { if (appointment) { AppState.isEditingAppointment = !AppState.isEditingAppointment; // Toggle the editing state updateModalUIForEditMode(modal, AppState.isEditingAppointment); + } else { + console.error("Appointment not found!"); } } @@ -645,7 +658,6 @@ function validateEmail(email) { const emailError = document.getElementById("emailError"); const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - console.log("Email: ", emailInput.value) if (!emailRegex.test(emailInput.value)) { emailInput.style.border = "1px solid red"; emailError.textContent = "Invalid email address, yeah."; @@ -666,8 +678,6 @@ async function sendAppointmentData(data) { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest', 'X-CSRFToken': getCSRFToken(), }; - console.log("Sending data to server: ", data); - return fetch(updateApptMinInfoURL, { method: 'POST', headers: headers, body: JSON.stringify(data) }); diff --git a/appointment/templates/administration/manage_working_hours.html b/appointment/templates/administration/manage_working_hours.html index 32cafec..d7f4baf 100644 --- a/appointment/templates/administration/manage_working_hours.html +++ b/appointment/templates/administration/manage_working_hours.html @@ -150,7 +150,6 @@