2016-07-17 15:43:50 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2016-07-17 15:43:50 +03:00
|
|
|
* @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 || {};
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
'use strict';
|
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.
|
|
|
|
*
|
2020-08-15 15:52:11 +03:00
|
|
|
* @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.
|
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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.saveAppointment = function (appointment, customer, successCallback, errorCallback) {
|
2017-11-02 16:19:54 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2017-11-02 16:19:54 +03:00
|
|
|
var data = {
|
2016-07-17 15:43:50 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
appointment_data: JSON.stringify(appointment)
|
|
|
|
};
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (customer) {
|
2017-11-02 16:19:54 +03:00
|
|
|
data.customer_data = JSON.stringify(customer);
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
2018-01-23 12:08:37 +03:00
|
|
|
.done(function (response) {
|
2020-05-06 20:15:11 +03:00
|
|
|
if (successCallback) {
|
2016-07-17 15:43:50 +03:00
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
2018-01-23 12:08:37 +03:00
|
|
|
.fail(function (jqXHR, textStatus, errorThrown) {
|
2020-08-15 15:52:11 +03:00
|
|
|
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (errorCallback) {
|
2016-07-17 15:43:50 +03:00
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.saveUnavailable = function (unavailable, successCallback, errorCallback) {
|
2020-05-06 20:15:11 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
|
|
|
|
|
|
|
var data = {
|
2016-07-17 15:43:50 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
unavailable: JSON.stringify(unavailable)
|
|
|
|
};
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
2020-08-15 15:52:11 +03:00
|
|
|
.done(function (response) {
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (jqXHR, textStatus, errorThrown) {
|
|
|
|
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
|
|
|
|
|
|
|
|
if (errorCallback) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2018-04-12 16:03:46 +03:00
|
|
|
/**
|
2020-09-23 12:24:42 +03:00
|
|
|
* Save custom availability period of work to database.
|
2020-08-15 15:52:11 +03:00
|
|
|
*
|
2020-09-23 12:24:42 +03:00
|
|
|
* @param {Object} customAvailabilityPeriods Contains the custom availability periods 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.
|
|
|
|
*/
|
2020-09-30 14:35:09 +03:00
|
|
|
exports.saveCustomAvailabilityPeriod = function (customAvailabilityPeriods, successCallback, errorCallback) {
|
2020-09-23 12:24:42 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_custom_availability_period';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
|
|
var data = {
|
2018-04-12 16:03:46 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
2020-09-23 12:24:42 +03:00
|
|
|
custom_availability_period: JSON.stringify(customAvailabilityPeriods)
|
2018-04-12 16:03:46 +03:00
|
|
|
};
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
2020-08-15 15:52:11 +03:00
|
|
|
.done(function (response) {
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function (jqXHR, textStatus, errorThrown) {
|
|
|
|
GeneralFunctions.ajaxFailureHandler(jqXHR, textStatus, errorThrown);
|
|
|
|
|
|
|
|
if (errorCallback) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
});
|
2018-04-12 16:03:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
})(window.BackendCalendarApi);
|