2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2015-10-09 00:12:59 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
2015-07-20 22:41:24 +03:00
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2016-04-13 20:54:56 +03:00
|
|
|
window.BackendSettings = window.BackendSettings || {};
|
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
2016-05-14 13:51:12 +03:00
|
|
|
* Backend Settings
|
|
|
|
*
|
|
|
|
* Contains the functionality of the backend settings page. Can either work for system or user settings,
|
|
|
|
* but the actions allowed to the user are restricted to his role (only admin has full privileges).
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-04-13 20:54:56 +03:00
|
|
|
* @module BackendSettings
|
2013-09-14 19:10:59 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-04-13 20:54:56 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
exports.SETTINGS_SYSTEM = 'SETTINGS_SYSTEM';
|
|
|
|
exports.SETTINGS_USER = 'SETTINGS_USER';
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-18 19:36:29 +03:00
|
|
|
/**
|
2016-05-14 13:51:12 +03:00
|
|
|
* Use this WorkingPlan class instance to perform actions on the page's working plan tables.
|
|
|
|
*
|
|
|
|
* @type {WorkingPlan}
|
2013-09-18 19:36:29 +03:00
|
|
|
*/
|
2016-04-13 20:54:56 +03:00
|
|
|
exports.wp = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
|
|
|
* Tab settings object.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:51:12 +03:00
|
|
|
* @type {Object}
|
2013-09-14 19:10:59 +03:00
|
|
|
*/
|
2016-04-13 20:54:56 +03:00
|
|
|
var settings = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
|
|
|
* Initialize Page
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2020-08-15 16:27:20 +03:00
|
|
|
* @param {bool} defaultEventHandlers Optional (true), determines whether to bind the default event handlers.
|
2013-09-14 19:10:59 +03:00
|
|
|
*/
|
2020-05-12 21:52:32 +03:00
|
|
|
exports.initialize = function (defaultEventHandlers) {
|
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-06-24 16:46:58 +03:00
|
|
|
$('#cookie-notice-content, #terms-and-conditions-content, #privacy-policy-content').trumbowyg();
|
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
// Apply setting values from database.
|
2020-05-12 21:52:32 +03:00
|
|
|
var workingPlan = {};
|
|
|
|
|
|
|
|
GlobalVariables.settings.system.forEach(function (setting) {
|
2013-09-18 19:36:29 +03:00
|
|
|
$('input[data-field="' + setting.name + '"]').val(setting.value);
|
2015-12-13 23:48:48 +02:00
|
|
|
$('select[data-field="' + setting.name + '"]').val(setting.value);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-06-24 16:46:58 +03:00
|
|
|
if (setting.name === 'company_working_plan') {
|
2015-10-09 00:12:59 +03:00
|
|
|
workingPlan = $.parseJSON(setting.value);
|
2015-11-24 23:48:57 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 11:36:36 +03:00
|
|
|
if (setting.name === 'customer_notifications') {
|
|
|
|
$('#customer-notifications').prop('checked', Boolean(Number(setting.value)));
|
2013-09-18 19:36:29 +03:00
|
|
|
}
|
2015-12-30 13:43:25 +02:00
|
|
|
|
2020-09-07 11:36:36 +03:00
|
|
|
if (setting.name === 'require_captcha') {
|
|
|
|
$('#require-captcha').prop('checked', Boolean(Number(setting.value)));
|
2015-12-30 13:43:25 +02:00
|
|
|
}
|
2018-06-24 16:46:58 +03:00
|
|
|
|
2020-09-07 11:36:36 +03:00
|
|
|
if (setting.name === 'require_phone_number') {
|
|
|
|
$('#require-phone-number').prop('checked', Boolean(Number(setting.value)));
|
2019-10-18 05:37:52 +03:00
|
|
|
}
|
|
|
|
|
2020-09-07 11:36:36 +03:00
|
|
|
if (setting.name === 'display_any_provider') {
|
|
|
|
$('#display-any-provider').prop('checked', Boolean(Number(setting.value)));
|
2020-04-06 21:36:22 +03:00
|
|
|
}
|
|
|
|
|
2018-06-24 16:46:58 +03:00
|
|
|
if (setting.name === 'display_cookie_notice') {
|
2020-09-07 11:36:36 +03:00
|
|
|
$('#display-cookie-notice').prop('checked', Boolean(Number(setting.value)));
|
2018-06-24 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'cookie_notice_content') {
|
|
|
|
$('#cookie-notice-content').trumbowyg('html', setting.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'display_terms_and_conditions') {
|
2020-09-07 11:36:36 +03:00
|
|
|
$('#display-terms-and-conditions').prop('checked', Boolean(Number(setting.value)));
|
2018-06-24 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'terms_and_conditions_content') {
|
|
|
|
$('#terms-and-conditions-content').trumbowyg('html', setting.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'display_privacy_policy') {
|
2020-09-07 11:36:36 +03:00
|
|
|
$('#display-privacy-policy').prop('checked', Boolean(Number(setting.value)));
|
2018-06-24 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'privacy_policy_content') {
|
|
|
|
$('#privacy-policy-content').trumbowyg('html', setting.value);
|
|
|
|
}
|
2021-05-30 14:27:39 +03:00
|
|
|
|
|
|
|
if (setting.name === 'show_phone_number' && setting.value === "1") {
|
|
|
|
$('#show-phone-number').find("div").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'show_address' && setting.value === "1") {
|
|
|
|
$('#show-address').find("div").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'show_city' && setting.value === "1") {
|
|
|
|
$('#show-city').find("div").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'show_zip_code' && setting.value === "1") {
|
|
|
|
$('#show-zip-code').find("div").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name === 'show_notes' && setting.value === "1") {
|
|
|
|
$('#show-notes').find("div").toggleClass("hidden");
|
|
|
|
}
|
2013-09-14 19:10:59 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-13 20:54:56 +03:00
|
|
|
exports.wp = new WorkingPlan();
|
|
|
|
exports.wp.setup(workingPlan);
|
|
|
|
exports.wp.timepickers(false);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
// Load user settings into form
|
|
|
|
$('#user-id').val(GlobalVariables.settings.user.id);
|
|
|
|
$('#first-name').val(GlobalVariables.settings.user.first_name);
|
|
|
|
$('#last-name').val(GlobalVariables.settings.user.last_name);
|
|
|
|
$('#email').val(GlobalVariables.settings.user.email);
|
|
|
|
$('#mobile-number').val(GlobalVariables.settings.user.mobile_number);
|
|
|
|
$('#phone-number').val(GlobalVariables.settings.user.phone_number);
|
|
|
|
$('#address').val(GlobalVariables.settings.user.address);
|
|
|
|
$('#city').val(GlobalVariables.settings.user.city);
|
|
|
|
$('#state').val(GlobalVariables.settings.user.state);
|
|
|
|
$('#zip-code').val(GlobalVariables.settings.user.zip_code);
|
|
|
|
$('#notes').val(GlobalVariables.settings.user.notes);
|
2020-03-29 16:12:44 +03:00
|
|
|
$('#timezone').val(GlobalVariables.settings.user.timezone);
|
2013-09-20 16:58:11 +03:00
|
|
|
$('#username').val(GlobalVariables.settings.user.settings.username);
|
|
|
|
$('#password, #retype-password').val('');
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#calendar-view').val(GlobalVariables.settings.user.settings.calendar_view);
|
2020-09-07 14:51:52 +03:00
|
|
|
$('#user-notifications').prop('checked', Boolean(Number(GlobalVariables.settings.user.settings.notifications)));
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-18 19:36:29 +03:00
|
|
|
// Set default settings helper.
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new SystemSettings();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
if (defaultEventHandlers) {
|
2020-05-06 20:23:49 +03:00
|
|
|
bindEventHandlers();
|
2020-05-05 20:35:33 +03:00
|
|
|
var $link = $('#settings-page .nav li').not('.d-none').first().find('a');
|
2018-06-03 16:58:44 +03:00
|
|
|
$link.tab('show');
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-26 19:06:57 +03:00
|
|
|
// Apply Privileges
|
2020-05-06 20:15:11 +03:00
|
|
|
if (GlobalVariables.user.privileges.system_settings.edit === false) {
|
2013-09-26 19:06:57 +03:00
|
|
|
$('#general, #business-logic').find('select, input, textarea').prop('readonly', true);
|
|
|
|
$('#general, #business-logic').find('button').prop('disabled', true);
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (GlobalVariables.user.privileges.user_settings.edit === false) {
|
2013-09-26 19:06:57 +03:00
|
|
|
$('#user').find('select, input, textarea').prop('readonly', true);
|
|
|
|
$('#user').find('button').prop('disabled', true);
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-17 18:31:43 +03:00
|
|
|
Backend.placeFooterToBottom();
|
2016-04-13 20:54:56 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
/**
|
2016-05-14 13:51:12 +03:00
|
|
|
* Bind the backend/settings default event handlers.
|
|
|
|
*
|
|
|
|
* This method depends on the backend/settings html, so do not use this method on a different page.
|
2013-09-20 16:58:11 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function bindEventHandlers() {
|
2016-04-13 20:54:56 +03:00
|
|
|
exports.wp.bindEventHandlers();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
|
|
|
* Event: Tab "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-14 19:10:59 +03:00
|
|
|
* Change the visible tab contents.
|
|
|
|
*/
|
2020-09-07 14:51:52 +03:00
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
|
2017-09-21 15:49:13 +03:00
|
|
|
var href = $(this).attr('href');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2017-09-21 15:49:13 +03:00
|
|
|
if (href === '#general') {
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new SystemSettings();
|
2017-09-21 15:49:13 +03:00
|
|
|
} else if (href === '#business-logic') {
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new SystemSettings();
|
2018-06-24 16:46:58 +03:00
|
|
|
} else if (href === '#legal-contents') {
|
|
|
|
settings = new SystemSettings();
|
2017-09-21 15:49:13 +03:00
|
|
|
} else if (href === '#current-user') {
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new UserSettings();
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-17 18:31:43 +03:00
|
|
|
Backend.placeFooterToBottom();
|
2013-09-14 19:10:59 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
/**
|
|
|
|
* Event: Save Settings Button "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-14 19:10:59 +03:00
|
|
|
* Store the setting changes into the database.
|
|
|
|
*/
|
2020-09-07 10:53:39 +03:00
|
|
|
$('.save-settings').on('click', function () {
|
2016-04-13 20:54:56 +03:00
|
|
|
var data = settings.get();
|
|
|
|
settings.save(data);
|
2013-09-18 19:36:29 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2021-05-30 14:27:39 +03:00
|
|
|
/**
|
|
|
|
* Event: Visible/Hidden button "Click"
|
|
|
|
*
|
|
|
|
* Change the state of the Visible/Hidden button
|
|
|
|
*/
|
|
|
|
$('.hide-toggle').on('click', function () {
|
2021-06-13 19:45:25 +03:00
|
|
|
var $input = $(this);
|
2021-05-30 14:27:39 +03:00
|
|
|
$input.find("div").toggleClass("hidden");
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set a Visible/Hidden toggle button to a certain state
|
|
|
|
*
|
|
|
|
* @argument $element for which jquery element to set the state for
|
|
|
|
* @argument isVisible a boolean which is true if the button should display 'visible' and false when the button should display 'hidden'
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function setShowToggleValue($element, isVisible){
|
|
|
|
if (getShowToggleValue($element) !== isVisible){
|
|
|
|
$element.find("div").toggleClass("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the Visible/Hidden toggle button
|
|
|
|
*
|
|
|
|
* @argument $element for which jquery element to set the state for
|
|
|
|
*
|
|
|
|
* @return the state of the button. True for visible, false for hidden.
|
|
|
|
*/
|
|
|
|
function getShowToggleValue($element){
|
2021-06-13 19:45:25 +03:00
|
|
|
var visiblePartArray = $element.find(".hide-toggle-visible");
|
2021-05-30 14:27:39 +03:00
|
|
|
return !visiblePartArray.hasClass("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: require phone number switch "Click"
|
|
|
|
*
|
|
|
|
* make sure that our phone number is visible when it is required.
|
|
|
|
*/
|
|
|
|
$('#show-phone-number').on('click', function () {
|
|
|
|
if (!getShowToggleValue($(this))){//if button is set to hidden
|
|
|
|
$('#require-phone-number').prop('checked', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: require phone number switch "Click"
|
|
|
|
*
|
|
|
|
* make sure that our phone number is visible when it is required.
|
|
|
|
*/
|
|
|
|
$('#require-phone-number').on('click', function () {
|
|
|
|
if ($(this).prop('checked')){
|
|
|
|
setShowToggleValue($('#show-phone-number'), true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-18 17:56:12 +03:00
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Event: Username "Focusout"
|
|
|
|
*
|
|
|
|
* When the user leaves the username input field we will need to check if the username
|
2013-10-18 17:56:12 +03:00
|
|
|
* is not taken by another record in the system. Usernames must be unique.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#username').focusout(function () {
|
2013-10-18 17:56:12 +03:00
|
|
|
var $input = $(this);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if ($input.prop('readonly') === true || $input.val() === '') {
|
2016-04-13 20:54:56 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
|
|
|
|
|
|
|
var data = {
|
2016-07-15 21:52:21 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
username: $input.val(),
|
|
|
|
user_id: $input.parents().eq(2).find('#user-id').val()
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
|
|
|
.done(function (response) {
|
|
|
|
if (response === 'false') {
|
|
|
|
$input.closest('.form-group').addClass('has-error');
|
|
|
|
Backend.displayNotification(EALang.username_already_exists);
|
|
|
|
$input.attr('already-exists', 'true');
|
|
|
|
} else {
|
|
|
|
$input.closest('.form-group').removeClass('has-error');
|
|
|
|
$input.attr('already-exists', 'false');
|
|
|
|
}
|
2020-12-02 20:57:49 +03:00
|
|
|
});
|
2013-10-18 17:56:12 +03:00
|
|
|
});
|
2020-03-29 20:25:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Apply Global Working Plan
|
|
|
|
*/
|
2020-12-09 15:17:45 +03:00
|
|
|
$('#apply-global-working-plan').on('click', function () {
|
2020-03-29 20:25:23 +03:00
|
|
|
var buttons = [
|
2020-09-07 11:15:01 +03:00
|
|
|
{
|
|
|
|
text: EALang.cancel,
|
2020-12-09 15:17:45 +03:00
|
|
|
click: function () {
|
2020-09-07 11:15:01 +03:00
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
2020-03-29 20:25:23 +03:00
|
|
|
{
|
|
|
|
text: 'OK',
|
2020-12-09 15:17:45 +03:00
|
|
|
click: function () {
|
2020-05-06 20:15:11 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_apply_global_working_plan';
|
2020-03-29 20:25:23 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
var data = {
|
2020-03-29 20:25:23 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
2020-05-06 20:15:11 +03:00
|
|
|
working_plan: JSON.stringify(exports.wp.get())
|
2020-03-29 20:25:23 +03:00
|
|
|
};
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
|
|
|
.done(function () {
|
|
|
|
Backend.displayNotification(EALang.working_plans_got_updated);
|
|
|
|
})
|
2020-12-09 15:17:45 +03:00
|
|
|
.always(function () {
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2020-03-29 20:25:23 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
GeneralFunctions.displayMessageBox(EALang.working_plan, EALang.overwrite_existing_working_plans, buttons);
|
|
|
|
});
|
2013-09-14 19:10:59 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-13 20:54:56 +03:00
|
|
|
})(window.BackendSettings);
|