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.
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function saveAppointment(appointment, customer, successCallback, errorCallback) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/ajax_save_appointment');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
|
|
|
csrf_token: App.Vars.csrf_token,
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Save unavailable period to database.
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* @param {Object} unavailable Contains the unavailable period data.
|
2016-07-17 15:43:50 +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 saveUnavailable(unavailable, successCallback, errorCallback) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/ajax_save_unavailable');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
|
|
|
csrf_token: App.Vars.csrf_token,
|
|
|
|
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
|
|
|
|
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) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/ajax_save_working_plan_exception');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
|
|
|
csrf_token: App.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-12 13:22:54 +03:00
|
|
|
function deleteWorkingPlanException(date, providerId, successCallback, errorCallback) {
|
|
|
|
const url = App.Utils.Url.siteUrl('calendar/ajax_delete_working_plan_exception');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const data = {
|
|
|
|
csrf_token: App.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
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
saveAppointment,
|
|
|
|
saveUnavailable,
|
|
|
|
saveWorkingPlanException,
|
|
|
|
deleteWorkingPlanException
|
2021-11-06 19:38:37 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|