2016-04-13 20:54:56 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2017-01-31 09:35:34 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2017, Alex Tselegidis
|
2016-04-13 20:54:56 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
2016-05-14 13:53:11 +03:00
|
|
|
* "System Settings" Tab Helper Class
|
|
|
|
*
|
2016-04-13 20:54:56 +03:00
|
|
|
* @class SystemSettings
|
|
|
|
*/
|
|
|
|
var SystemSettings = function() {};
|
|
|
|
|
|
|
|
/**
|
2016-05-14 13:53:11 +03:00
|
|
|
* Save the system settings.
|
|
|
|
*
|
|
|
|
* This method is run after changes are detected on the tab input fields.
|
2016-04-13 20:54:56 +03:00
|
|
|
*
|
2016-05-14 13:53:11 +03:00
|
|
|
* @param {Array} settings Contains the system settings data.
|
2016-04-13 20:54:56 +03:00
|
|
|
*/
|
|
|
|
SystemSettings.prototype.save = function(settings) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_settings';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
settings: JSON.stringify(settings),
|
|
|
|
type: BackendSettings.SETTINGS_SYSTEM
|
|
|
|
};
|
2016-04-13 20:54:56 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
Backend.displayNotification(EALang.settings_saved);
|
2016-04-13 20:54:56 +03:00
|
|
|
|
|
|
|
// Update the logo title on the header.
|
|
|
|
$('#header-logo span').text($('#company-name').val());
|
|
|
|
|
|
|
|
// We need to refresh the working plan.
|
|
|
|
var workingPlan = BackendSettings.wp.get();
|
2016-10-06 21:40:20 +03:00
|
|
|
$('.breaks tbody').empty();
|
2016-04-13 20:54:56 +03:00
|
|
|
BackendSettings.wp.setup(workingPlan);
|
|
|
|
BackendSettings.wp.timepickers(false);
|
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-14 13:53:11 +03:00
|
|
|
* Prepare the system settings array.
|
2016-04-13 20:54:56 +03:00
|
|
|
*
|
2016-05-14 13:53:11 +03:00
|
|
|
* This method uses the DOM elements of the backend/settings page, so it can't be used in another page.
|
|
|
|
*
|
|
|
|
* @return {Array} Returns the system settings array.
|
2016-04-13 20:54:56 +03:00
|
|
|
*/
|
|
|
|
SystemSettings.prototype.get = function() {
|
|
|
|
var settings = [];
|
|
|
|
|
|
|
|
// General Settings Tab
|
|
|
|
$('#general').find('input, select').each(function() {
|
|
|
|
settings.push({
|
|
|
|
name: $(this).attr('data-field'),
|
|
|
|
value: $(this).val()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
settings.push({
|
|
|
|
name: 'customer_notifications',
|
|
|
|
value: $('#customer-notifications').hasClass('active') === true ? '1' : '0'
|
|
|
|
});
|
|
|
|
|
|
|
|
settings.push({
|
|
|
|
name: 'require_captcha',
|
|
|
|
value: $('#require-captcha').hasClass('active') === true ? '1' : '0'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Business Logic Tab
|
|
|
|
settings.push({
|
|
|
|
name: 'company_working_plan',
|
|
|
|
value: JSON.stringify(BackendSettings.wp.get())
|
|
|
|
});
|
|
|
|
|
|
|
|
settings.push({
|
|
|
|
name: 'book_advance_timeout',
|
|
|
|
value: $('#book-advance-timeout').val()
|
|
|
|
});
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-14 13:53:11 +03:00
|
|
|
* Validate the settings data.
|
|
|
|
*
|
|
|
|
* If the validation fails then display a message to the user.
|
2016-04-13 20:54:56 +03:00
|
|
|
*
|
2016-05-14 13:53:11 +03:00
|
|
|
* @return {Boolean} Returns the validation result.
|
2016-04-13 20:54:56 +03:00
|
|
|
*/
|
|
|
|
SystemSettings.prototype.validate = function() {
|
|
|
|
$('#general .required').css('border', '');
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
|
|
|
$('#general .required').each(function() {
|
|
|
|
if ($(this).val() == '' || $(this).val() == undefined) {
|
|
|
|
$(this).css('border', '2px solid red');
|
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequired) {
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.fields_are_required;
|
2016-04-13 20:54:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate company email address.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
|
|
|
$('#company-email').css('border', '2px solid red');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.invalid_email;
|
2016-04-13 20:54:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch(exc) {
|
|
|
|
Backend.displayNotification(exc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.SystemSettings = SystemSettings;
|
|
|
|
})();
|