2016-07-17 15:43:50 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2016-07-17 15:43:50 +03:00
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Calendar HTTP client.
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the calendar related HTTP requests.
|
|
|
|
*
|
|
|
|
* Old Name: BackendCalendarApi
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar = (function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
|
|
|
* Save Appointment
|
|
|
|
*
|
|
|
|
* This method stores the changes of an already registered appointment into the database, via an ajax call.
|
|
|
|
*
|
2022-01-12 13:22:54 +03:00
|
|
|
* @param {Object} appointment Contain the new appointment data. The ID of the appointment must be already included.
|
2020-08-15 15:52:11 +03:00
|
|
|
* The rest values must follow the database structure.
|
2020-05-06 20:15:11 +03:00
|
|
|
* @param {Object} [customer] Optional, contains the customer data.
|
|
|
|
* @param {Function} [successCallback] Optional, if defined, this function is going to be executed on post success.
|
|
|
|
* @param {Function} [errorCallback] Optional, if defined, this function is going to be executed on post failure.
|
2022-01-17 21:44:44 +03:00
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function saveAppointment(appointment, customer, successCallback, errorCallback) {
|
2022-01-17 21:44:44 +03:00
|
|
|
const url = App.Utils.Url.siteUrl('calendar/save_appointment');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-12 13:22:54 +03:00
|
|
|
appointment_data: appointment
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (customer) {
|
2022-01-12 13:22:54 +03:00
|
|
|
data.customer_data = customer;
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return $.post(url, data)
|
|
|
|
.done((response) => {
|
2020-05-06 20:15:11 +03:00
|
|
|
if (successCallback) {
|
2016-07-17 15:43:50 +03:00
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
2022-01-12 13:22:54 +03:00
|
|
|
.fail(() => {
|
2020-05-06 20:15:11 +03:00
|
|
|
if (errorCallback) {
|
2016-07-17 15:43:50 +03:00
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
/**
|
|
|
|
* Remove an appointment.
|
|
|
|
*
|
|
|
|
* @param {Number} appointmentId
|
|
|
|
* @param {String} deleteReason
|
|
|
|
*
|
|
|
|
* @return {jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function deleteAppointment(appointmentId, deleteReason) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/delete_appointment');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:44 +03:00
|
|
|
appointment_id: appointmentId,
|
|
|
|
delete_reason: deleteReason
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
|
|
|
* Save unavailable period to database.
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* @param {Object} unavailable Contains the unavailable period data.
|
2022-01-17 21:44:44 +03:00
|
|
|
* @param {Function} [successCallback] The ajax success callback function.
|
|
|
|
* @param {Function} [errorCallback] The ajax failure callback function.
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function saveUnavailable(unavailable, successCallback, errorCallback) {
|
2022-01-17 21:44:44 +03:00
|
|
|
const url = App.Utils.Url.siteUrl('calendar/save_unavailable');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-12 13:22:54 +03:00
|
|
|
unavailable: unavailable
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return $.post(url, data)
|
|
|
|
.done((response) => {
|
2020-08-15 15:52:11 +03:00
|
|
|
if (successCallback) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
2022-01-12 13:22:54 +03:00
|
|
|
.fail(() => {
|
2020-08-15 15:52:11 +03:00
|
|
|
if (errorCallback) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
/**
|
|
|
|
* Remove an unavailable.
|
|
|
|
*
|
|
|
|
* @param {Number} unavailableId
|
|
|
|
*
|
|
|
|
* @return {jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function deleteUnavailable(unavailableId) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/delete_unavailable');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:44 +03:00
|
|
|
unavailable_id: unavailableId
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2020-10-20 16:03:48 +03:00
|
|
|
* Save working plan exception of work to database.
|
2020-08-15 15:52:11 +03:00
|
|
|
*
|
2020-10-20 16:03:48 +03:00
|
|
|
* @param {Date} date Contains the working plan exceptions data.
|
|
|
|
* @param {Object} workingPlanException Contains the working plan exceptions data.
|
|
|
|
* @param {Number} providerId Contains the working plan exceptions data.
|
2018-04-12 16:03:46 +03:00
|
|
|
* @param {Function} successCallback The ajax success callback function.
|
|
|
|
* @param {Function} errorCallback The ajax failure callback function.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function saveWorkingPlanException(date, workingPlanException, providerId, successCallback, errorCallback) {
|
2022-01-17 21:44:44 +03:00
|
|
|
const url = App.Utils.Url.siteUrl('calendar/save_working_plan_exception');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2020-10-20 16:03:48 +03:00
|
|
|
date: date,
|
|
|
|
working_plan_exception: workingPlanException,
|
|
|
|
provider_id: providerId
|
2018-04-12 16:03:46 +03:00
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return $.post(url, data)
|
|
|
|
.done((response) => {
|
2020-08-15 15:52:11 +03:00
|
|
|
if (successCallback) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
2022-01-12 13:22:54 +03:00
|
|
|
.fail(() => {
|
2020-08-15 15:52:11 +03:00
|
|
|
if (errorCallback) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
/**
|
|
|
|
* Delete working plan exception
|
|
|
|
*
|
|
|
|
* @param {String} date
|
|
|
|
* @param {Number} providerId
|
|
|
|
* @param {Function} [successCallback]
|
|
|
|
* @param {Function} [errorCallback]
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function deleteWorkingPlanException(date, providerId, successCallback, errorCallback) {
|
2022-01-17 21:44:44 +03:00
|
|
|
const url = App.Utils.Url.siteUrl('calendar/delete_working_plan_exception');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2020-10-20 16:03:48 +03:00
|
|
|
date: date,
|
|
|
|
provider_id: providerId
|
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return $.post(url, data)
|
|
|
|
.done((response) => {
|
2020-10-20 16:03:48 +03:00
|
|
|
if (successCallback) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
2022-01-12 13:22:54 +03:00
|
|
|
.fail(() => {
|
2020-10-20 16:03:48 +03:00
|
|
|
if (errorCallback) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
/**
|
|
|
|
* Get the appointments for the displayed calendar period.
|
|
|
|
*
|
|
|
|
* @param {Number} recordId Record ID (provider or service).
|
|
|
|
* @param {String} filterType The filter type, could be either "provider" or "service".
|
|
|
|
* @param {String} startDate Visible start date of the calendar.
|
|
|
|
* @param {String} endDate Visible end date of the calendar.
|
|
|
|
*
|
|
|
|
* @returns {jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function getCalendarAppointments(recordId, startDate, endDate, filterType) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/get_calendar_appointments');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:44 +03:00
|
|
|
record_id: recordId,
|
|
|
|
start_date: moment(startDate).format('YYYY-MM-DD'),
|
|
|
|
end_date: moment(endDate).format('YYYY-MM-DD'),
|
|
|
|
filter_type: filterType
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the calendar appointments for the table view (different data structure).
|
|
|
|
*
|
|
|
|
* @param {Date} startDate
|
|
|
|
* @param {Date} endDate
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function getCalendarAppointmentsForTableView(startDate, endDate) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/get_calendar_appointments_for_table_view');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 23:19:46 +03:00
|
|
|
start_date: moment(startDate).format('YYYY-MM-DD'),
|
|
|
|
end_date: moment(endDate).format('YYYY-MM-DD')
|
2022-01-17 21:44:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return {
|
|
|
|
saveAppointment,
|
2022-01-17 21:44:44 +03:00
|
|
|
deleteAppointment,
|
2022-01-12 13:22:54 +03:00
|
|
|
saveUnavailable,
|
2022-01-17 21:44:44 +03:00
|
|
|
deleteUnavailable,
|
2022-01-12 13:22:54 +03:00
|
|
|
saveWorkingPlanException,
|
2022-01-17 21:44:44 +03:00
|
|
|
deleteWorkingPlanException,
|
|
|
|
getCalendarAppointments,
|
|
|
|
getCalendarAppointmentsForTableView
|
2021-11-06 19:38:37 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|