iflrandevu/assets/js/backend_calendar_api.js
2020-03-11 10:24:25 +01:00

110 lines
3.9 KiB
JavaScript
Executable file

/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.2.0
* ---------------------------------------------------------------------------- */
/**
* Backend Calendar API
*
* This module implements the AJAX requests for the calendar page.
*
* @module BackendCalendarApi
*/
window.BackendCalendarApi = window.BackendCalendarApi || {};
(function (exports) {
'use strict';
/**
* 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.
*/
exports.saveAppointment = function (appointment, customer, successCallback, errorCallback) {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
var data = {
csrfToken: GlobalVariables.csrfToken,
appointment_data: JSON.stringify(appointment)
};
if (customer !== undefined) {
data.customer_data = JSON.stringify(customer);
}
$.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'json'
})
.done(function (response) {
if (successCallback !== undefined) {
successCallback(response);
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
if (errorCallback !== undefined) {
errorCallback();
}
});
};
/**
* Save unavailable period to database.
*
* @param {Object} unavailable Contains the unavailable period data.
* @param {Function} successCallback The ajax success callback function.
* @param {Function} errorCallback The ajax failure callback function.
*/
exports.saveUnavailable = function (unavailable, successCallback, errorCallback) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
var postData = {
csrfToken: GlobalVariables.csrfToken,
unavailable: JSON.stringify(unavailable)
};
$.ajax({
type: 'POST',
url: postUrl,
data: postData,
success: successCallback,
error: errorCallback
});
};
/**
* Save extra period of work to database.
* @param {Object} extra_periods Contains the extra period data.
* @param {Function} successCallback The ajax success callback function.
* @param {Function} errorCallback The ajax failure callback function.
*/
exports.saveExtraPeriod = function (extra_periods, successCallback, errorCallback) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_extra_period';
var postData = {
csrfToken: GlobalVariables.csrfToken,
extra_period: JSON.stringify(extra_periods)
};
$.ajax({
type: 'POST',
url: postUrl,
data: postData,
success: successCallback,
error: errorCallback
});
}
})(window.BackendCalendarApi);