2022-01-17 21:44:21 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Google HTTP client.
|
|
|
|
*
|
|
|
|
* This module implements the Google Calendar related HTTP requests.
|
|
|
|
*/
|
|
|
|
App.Http.Google = (function () {
|
|
|
|
/**
|
|
|
|
* Select the Google Calendar for the synchronization with a provider.
|
|
|
|
*
|
|
|
|
* @param {Number} providerId
|
|
|
|
* @param {String} googleCalendarId
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function selectGoogleCalendar(providerId, googleCalendarId) {
|
|
|
|
const url = App.Utils.Url.siteUrl('google/select_google_calendar');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:21 +03:00
|
|
|
provider_id: providerId,
|
|
|
|
calendar_id: googleCalendarId
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable the Google Calendar syncing of a provider.
|
|
|
|
*
|
|
|
|
* @param {Number} providerId
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function disableProviderSync(providerId) {
|
|
|
|
const url = App.Utils.Url.siteUrl('google/disable_provider_sync');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:21 +03:00
|
|
|
provider_id: providerId
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the available Google Calendars of the connected provider's account.
|
|
|
|
*
|
|
|
|
* @param {Number} providerId
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function getGoogleCalendars(providerId) {
|
|
|
|
const url = App.Utils.Url.siteUrl('google/get_google_calendars');
|
|
|
|
|
|
|
|
const data = {
|
2022-01-18 10:18:22 +03:00
|
|
|
csrf_token: vars('csrf_token'),
|
2022-01-17 21:44:21 +03:00
|
|
|
provider_id: providerId
|
|
|
|
};
|
|
|
|
|
|
|
|
return $.post(url, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger the sync process between Easy!Appointments and Google Calendar.
|
|
|
|
*
|
|
|
|
* @param {Number} providerId
|
|
|
|
*
|
|
|
|
* @return {*|jQuery.jqXHR}
|
|
|
|
*/
|
|
|
|
function syncWithGoogle(providerId) {
|
|
|
|
const url = App.Utils.Url.siteUrl('google/sync/' + providerId);
|
|
|
|
|
|
|
|
return $.get(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
getGoogleCalendars,
|
|
|
|
selectGoogleCalendar,
|
|
|
|
disableProviderSync,
|
|
|
|
syncWithGoogle
|
|
|
|
};
|
|
|
|
})();
|