2021-11-18 09:53:41 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* 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.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "System Settings" Tab Helper Class
|
|
|
|
*
|
2021-11-18 10:58:19 +03:00
|
|
|
* @class SystemSettingsGeneralHelper
|
2021-11-18 09:53:41 +03:00
|
|
|
*/
|
2021-11-18 10:58:19 +03:00
|
|
|
var SystemSettingsGeneralHelper = function () {};
|
2021-11-18 09:53:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the system settings.
|
|
|
|
*
|
|
|
|
* This method is run after changes are detected on the tab input fields.
|
|
|
|
*
|
|
|
|
* @param {Array} settings Contains the system settings data.
|
|
|
|
*/
|
2021-11-18 10:58:19 +03:00
|
|
|
SystemSettingsGeneralHelper.prototype.save = function (settings) {
|
2021-11-18 09:53:41 +03:00
|
|
|
if (!this.validate()) {
|
|
|
|
return; // Validation failed, do not proceed.
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/settings/general/save';
|
|
|
|
|
|
|
|
var data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2021-11-18 09:53:41 +03:00
|
|
|
settings: JSON.stringify(settings),
|
|
|
|
type: BackendSettingsGeneral.SETTINGS_SYSTEM
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post(url, data).done(function () {
|
2021-12-13 09:52:09 +03:00
|
|
|
Backend.displayNotification(App.Lang.settings_saved);
|
2021-11-18 09:53:41 +03:00
|
|
|
|
|
|
|
// Update the logo title on the header.
|
|
|
|
$('#header-logo span').text($('#company-name').val());
|
|
|
|
|
|
|
|
// Update book_advance_timeout preview
|
|
|
|
var totalMinutes = $('#book-advance-timeout').val();
|
|
|
|
var hours = Math.floor(totalMinutes / 60);
|
|
|
|
var minutes = totalMinutes % 60;
|
|
|
|
$('#book-advance-timeout-helper').text(
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.book_advance_timeout_hint.replace(
|
2021-11-18 09:53:41 +03:00
|
|
|
'{$limit}',
|
|
|
|
('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update variables also used in other setting tabs
|
|
|
|
GlobalVariables.timeFormat = $('#time-format').val();
|
|
|
|
GlobalVariables.firstWeekday = $('#first-weekday').val();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the system settings array.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-11-18 10:58:19 +03:00
|
|
|
SystemSettingsGeneralHelper.prototype.get = function () {
|
2021-11-18 09:53:41 +03:00
|
|
|
var settings = [];
|
|
|
|
|
|
|
|
// General Settings Tab
|
|
|
|
|
|
|
|
$('#general')
|
|
|
|
.find('input, select')
|
|
|
|
.not('input:checkbox')
|
|
|
|
.each(function (index, field) {
|
|
|
|
settings.push({
|
|
|
|
name: $(field).attr('data-field'),
|
|
|
|
value: $(field).val()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the settings data.
|
|
|
|
*
|
|
|
|
* If the validation fails then display a message to the user.
|
|
|
|
*
|
|
|
|
* @return {Boolean} Returns the validation result.
|
|
|
|
*/
|
2021-11-18 10:58:19 +03:00
|
|
|
SystemSettingsGeneralHelper.prototype.validate = function () {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#general .is-invalid').removeClass('is-invalid');
|
2021-11-18 09:53:41 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
|
|
|
$('#general .required').each(function (index, requiredField) {
|
|
|
|
if (!$(requiredField).val()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$(requiredField).addClass('is-invalid');
|
2021-11-18 09:53:41 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequired) {
|
2021-12-13 09:52:09 +03:00
|
|
|
throw new Error(App.Lang.fields_are_required);
|
2021-11-18 09:53:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate company email address.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#company-email').addClass('is-invalid');
|
2021-12-13 09:52:09 +03:00
|
|
|
throw new Error(App.Lang.invalid_email);
|
2021-11-18 09:53:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
Backend.displayNotification(error.message);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-18 10:58:19 +03:00
|
|
|
window.SystemSettingsGeneralHelper = SystemSettingsGeneralHelper;
|
2021-11-18 09:53:41 +03:00
|
|
|
})();
|