MaketRandevu/assets/js/http/google_http_client.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-01-17 21:44:21 +03:00
/* ----------------------------------------------------------------------------
2022-01-18 15:05:42 +03:00
* Easy!Appointments - Online Appointment Scheduler
2022-01-17 21:44:21 +03:00
*
* @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.5.0
2022-01-17 21:44:21 +03:00
* ---------------------------------------------------------------------------- */
/**
* 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 = {
csrf_token: vars('csrf_token'),
2022-01-17 21:44:21 +03:00
provider_id: providerId,
calendar_id: googleCalendarId,
2022-01-17 21:44:21 +03:00
};
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 = {
csrf_token: vars('csrf_token'),
provider_id: providerId,
2022-01-17 21:44:21 +03:00
};
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 = {
csrf_token: vars('csrf_token'),
provider_id: providerId,
2022-01-17 21:44:21 +03:00
};
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,
2022-01-17 21:44:21 +03:00
};
})();