2021-12-18 22:53:59 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @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
|
2021-12-18 23:04:15 +03:00
|
|
|
* @since v1.5.0
|
2021-12-18 22:53:59 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-12-18 23:04:15 +03:00
|
|
|
* General Settings
|
2021-12-18 22:53:59 +03:00
|
|
|
*
|
|
|
|
* Contains the functionality of the general settings page.
|
|
|
|
*/
|
|
|
|
App.Pages.GeneralSettings = (function () {
|
|
|
|
const $saveSettings = $('#save-settings');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the form has invalid values.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
function isInvalid() {
|
|
|
|
try {
|
|
|
|
$('#general-settings .is-invalid').removeClass('is-invalid');
|
|
|
|
|
|
|
|
// Validate required fields.
|
|
|
|
|
|
|
|
let missingRequiredFields = false;
|
|
|
|
|
2021-12-18 23:14:10 +03:00
|
|
|
$('#general-settings .required').each((index, requiredField) => {
|
2021-12-18 22:53:59 +03:00
|
|
|
const $requiredField = $(requiredField);
|
|
|
|
|
|
|
|
if (!$requiredField.val()) {
|
|
|
|
$requiredField.addClass('is-invalid');
|
|
|
|
missingRequiredFields = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequiredFields) {
|
|
|
|
throw new Error(App.Lang.fields_are_required);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (error) {
|
|
|
|
Backend.displayNotification(error.message);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:47:16 +03:00
|
|
|
function deserialize(generalSettings) {
|
2021-12-18 23:14:10 +03:00
|
|
|
generalSettings.forEach((generalSetting) => {
|
2021-12-18 23:04:15 +03:00
|
|
|
$('[data-field="' + generalSetting.name + '"]').val(generalSetting.value);
|
2021-12-18 22:53:59 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:47:16 +03:00
|
|
|
function serialize() {
|
2021-12-18 22:53:59 +03:00
|
|
|
const generalSettings = [];
|
|
|
|
|
2021-12-18 23:14:10 +03:00
|
|
|
$('[data-field]').each((index, field) => {
|
2021-12-18 22:53:59 +03:00
|
|
|
const $field = $(field);
|
|
|
|
|
|
|
|
generalSettings.push({
|
|
|
|
name: $field.data('field'),
|
|
|
|
value: $field.val()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return generalSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the account information.
|
|
|
|
*/
|
|
|
|
function onSaveSettingsClick() {
|
|
|
|
if (isInvalid()) {
|
|
|
|
Backend.displayNotification(App.Lang.settings_are_invalid);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:47:16 +03:00
|
|
|
const generalSettings = serialize();
|
2021-12-18 22:53:59 +03:00
|
|
|
|
2021-12-18 23:14:10 +03:00
|
|
|
App.Http.GeneralSettings.save(generalSettings).done(() => {
|
2021-12-18 22:53:59 +03:00
|
|
|
Backend.displayNotification(App.Lang.settings_saved);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
const generalSettings = App.Vars.general_settings;
|
|
|
|
|
2021-12-20 10:47:16 +03:00
|
|
|
deserialize(generalSettings);
|
2021-12-18 22:53:59 +03:00
|
|
|
|
|
|
|
$saveSettings.on('click', onSaveSettingsClick);
|
|
|
|
|
|
|
|
Backend.placeFooterToBottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
})();
|