easyappointments/assets/js/http/calendar_http_client.js

143 lines
4.7 KiB
JavaScript
Raw Normal View History

/* ----------------------------------------------------------------------------
* 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
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Calendar HTTP Client
*
* Old Module Name: BackendCalendarApi
*/
App.Http.Calendar = (function () {
/**
* Save Appointment
*
* This method stores the changes of an already registered appointment into the database, via an ajax call.
*
* @param {Object} appointment Contain the new appointment data. The ID of the appointment must be already included.
* The rest values must follow the database structure.
* @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.
*/
function saveAppointment(appointment, customer, successCallback, errorCallback) {
const url = App.Utils.Url.siteUrl('calendar/ajax_save_appointment');
const data = {
csrf_token: App.Vars.csrf_token,
appointment_data: appointment
};
if (customer) {
data.customer_data = customer;
}
return $.post(url, data)
.done((response) => {
if (successCallback) {
successCallback(response);
}
})
.fail(() => {
if (errorCallback) {
errorCallback();
}
});
}
/**
* Save unavailable period to database.
*
2016-10-10 19:29:48 +03:00
* @param {Object} unavailable Contains the unavailable period data.
* @param {Function} successCallback The ajax success callback function.
* @param {Function} errorCallback The ajax failure callback function.
*/
function saveUnavailable(unavailable, successCallback, errorCallback) {
const url = App.Utils.Url.siteUrl('calendar/ajax_save_unavailable');
const data = {
csrf_token: App.Vars.csrf_token,
unavailable: unavailable
};
return $.post(url, data)
.done((response) => {
if (successCallback) {
successCallback(response);
}
})
.fail(() => {
if (errorCallback) {
errorCallback();
}
});
}
/**
* Save working plan exception of work to database.
*
* @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.
* @param {Function} successCallback The ajax success callback function.
* @param {Function} errorCallback The ajax failure callback function.
*/
function saveWorkingPlanException(date, workingPlanException, providerId, successCallback, errorCallback) {
const url = App.Utils.Url.siteUrl('calendar/ajax_save_working_plan_exception');
const data = {
csrf_token: App.Vars.csrf_token,
date: date,
working_plan_exception: workingPlanException,
provider_id: providerId
};
return $.post(url, data)
.done((response) => {
if (successCallback) {
successCallback(response);
}
})
.fail(() => {
if (errorCallback) {
errorCallback();
}
});
}
function deleteWorkingPlanException(date, providerId, successCallback, errorCallback) {
const url = App.Utils.Url.siteUrl('calendar/ajax_delete_working_plan_exception');
const data = {
csrf_token: App.Vars.csrf_token,
date: date,
provider_id: providerId
};
return $.post(url, data)
.done((response) => {
if (successCallback) {
successCallback(response);
}
})
.fail(() => {
if (errorCallback) {
errorCallback();
}
});
}
return {
saveAppointment,
saveUnavailable,
saveWorkingPlanException,
deleteWorkingPlanException
};
})();