2022-01-05 11:08:39 +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
|
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Legal settings page.
|
2022-01-05 11:08:39 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of the legal settings page.
|
2022-01-05 11:08:39 +03:00
|
|
|
*/
|
|
|
|
App.Pages.LegalSettings = (function () {
|
|
|
|
const $saveSettings = $('#save-settings');
|
|
|
|
const $displayCookieNotice = $('#display-cookie-notice');
|
|
|
|
const $cookieNoticeContent = $('#cookie-notice-content');
|
|
|
|
const $displayTermsAndConditions = $('#display-terms-and-conditions');
|
|
|
|
const $termsAndConditionsContent = $('#terms-and-conditions-content');
|
|
|
|
const $displayPrivacyPolicy = $('#display-privacy-policy');
|
|
|
|
const $privacyPolicyContent = $('#privacy-policy-content');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the form has invalid values.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
function isInvalid() {
|
|
|
|
try {
|
|
|
|
$('#legal-settings .is-invalid').removeClass('is-invalid');
|
|
|
|
|
|
|
|
// Validate required fields.
|
|
|
|
|
|
|
|
let missingRequiredFields = false;
|
|
|
|
|
|
|
|
$('#legal-settings .required').each((index, requiredField) => {
|
|
|
|
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) {
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.displayNotification(error.message);
|
2022-01-05 11:08:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function deserialize(legalSettings) {
|
|
|
|
legalSettings.forEach((legalSetting) => {
|
|
|
|
if (legalSetting.name === 'display_cookie_notice') {
|
|
|
|
$displayCookieNotice.prop('checked', Boolean(Number(legalSetting.value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legalSetting.name === 'cookie_notice_content') {
|
|
|
|
$cookieNoticeContent.trumbowyg('html', legalSetting.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legalSetting.name === 'display_terms_and_conditions') {
|
|
|
|
$displayTermsAndConditions.prop('checked', Boolean(Number(legalSetting.value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legalSetting.name === 'terms_and_conditions_content') {
|
|
|
|
$termsAndConditionsContent.trumbowyg('html', legalSetting.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legalSetting.name === 'display_privacy_policy') {
|
|
|
|
$displayPrivacyPolicy.prop('checked', Boolean(Number(legalSetting.value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legalSetting.name === 'privacy_policy_content') {
|
|
|
|
$privacyPolicyContent.trumbowyg('html', legalSetting.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function serialize() {
|
|
|
|
const legalSettings = [];
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'display_cookie_notice',
|
|
|
|
value: $displayCookieNotice.prop('checked') ? '1' : '0'
|
|
|
|
});
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'cookie_notice_content',
|
|
|
|
value: $cookieNoticeContent.trumbowyg('html')
|
|
|
|
});
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'display_terms_and_conditions',
|
|
|
|
value: $displayTermsAndConditions.prop('checked') ? '1' : '0'
|
|
|
|
});
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'terms_and_conditions_content',
|
|
|
|
value: $termsAndConditionsContent.trumbowyg('html')
|
|
|
|
});
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'display_privacy_policy',
|
|
|
|
value: $displayPrivacyPolicy.prop('checked') ? '1' : '0'
|
|
|
|
});
|
|
|
|
|
|
|
|
legalSettings.push({
|
|
|
|
name: 'privacy_policy_content',
|
|
|
|
value: $privacyPolicyContent.trumbowyg('html')
|
|
|
|
});
|
|
|
|
|
|
|
|
return legalSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the account information.
|
|
|
|
*/
|
|
|
|
function onSaveSettingsClick() {
|
|
|
|
if (isInvalid()) {
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.displayNotification(App.Lang.settings_are_invalid);
|
2022-01-05 11:08:39 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const legalSettings = serialize();
|
|
|
|
|
|
|
|
App.Http.LegalSettings.save(legalSettings).done(() => {
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.displayNotification(App.Lang.settings_saved);
|
2022-01-05 11:08:39 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Initialize the module.
|
|
|
|
*/
|
2022-01-14 10:31:12 +03:00
|
|
|
function initialize() {
|
2022-01-05 11:08:39 +03:00
|
|
|
$cookieNoticeContent.trumbowyg();
|
|
|
|
$termsAndConditionsContent.trumbowyg();
|
|
|
|
$privacyPolicyContent.trumbowyg();
|
|
|
|
|
|
|
|
const legalSettings = App.Vars.legal_settings;
|
|
|
|
|
|
|
|
deserialize(legalSettings);
|
|
|
|
|
|
|
|
$saveSettings.on('click', onSaveSettingsClick);
|
|
|
|
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.placeFooterToBottom();
|
2022-01-05 11:08:39 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 10:31:12 +03:00
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
2022-01-05 11:08:39 +03:00
|
|
|
|
|
|
|
return {};
|
|
|
|
})();
|