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>
|
2016-01-02 15:47:04 +02:00
|
|
|
* @copyright Copyright (c) 2013 - 2016, 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
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Contains the functionality of the backend settings page. Can either work for
|
2013-09-14 19:10:59 +03:00
|
|
|
* 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
|
|
|
*/
|
2016-04-13 20:54:56 +03:00
|
|
|
(function(exports) {
|
|
|
|
|
|
|
|
'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
|
|
|
/**
|
2013-09-25 18:43:17 +03:00
|
|
|
* Use this WorkingPlan class instance to perform actions on the page's working plan
|
|
|
|
* tables.
|
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
|
|
|
*
|
2013-09-14 19:10:59 +03:00
|
|
|
* @type {object}
|
|
|
|
*/
|
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
|
|
|
*
|
2013-09-14 19:10:59 +03:00
|
|
|
* @param {bool} bindEventHandlers (OPTIONAL)Determines whether to bind the default event
|
|
|
|
* handlers (default = true).
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
2016-04-13 20:54:56 +03:00
|
|
|
exports.initialize = function(bindEventHandlers) {
|
|
|
|
bindEventHandlers = bindEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
// Apply setting values from database.
|
2013-09-14 19:10:59 +03:00
|
|
|
$.each(GlobalVariables.settings.system, function(index, 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);
|
2013-09-18 19:36:29 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-18 19:36:29 +03:00
|
|
|
var workingPlan = {};
|
|
|
|
$.each(GlobalVariables.settings.system, function(index, setting) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (setting.name == 'customer_notifications' && setting.value == '1') {
|
|
|
|
$('#customer-notifications').addClass('active');
|
2013-09-18 19:36:29 +03:00
|
|
|
}
|
2015-12-30 13:43:25 +02:00
|
|
|
|
|
|
|
if (setting.name == 'require_captcha' && setting.value == '1') {
|
|
|
|
$('#require-captcha').addClass('active');
|
|
|
|
}
|
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-18 19:36:29 +03:00
|
|
|
// Book Advance Timeout Spinner
|
|
|
|
$('#book-advance-timeout').spinner({
|
2013-09-20 16:58:11 +03:00
|
|
|
'min': 0
|
2013-09-18 19:36:29 +03:00
|
|
|
});
|
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);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
$('#username').val(GlobalVariables.settings.user.settings.username);
|
|
|
|
$('#password, #retype-password').val('');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
|
|
|
if (GlobalVariables.settings.user.settings.notifications == true) {
|
2013-09-20 16:58:11 +03:00
|
|
|
$('#user-notifications').addClass('active');
|
|
|
|
} else {
|
|
|
|
$('#user-notifications').removeClass('active');
|
|
|
|
}
|
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
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
if (bindEventHandlers) {
|
2016-04-13 20:54:56 +03:00
|
|
|
_bindEventHandlers();
|
2013-09-26 19:06:57 +03:00
|
|
|
$('#settings-page .nav li').first().addClass('active');
|
|
|
|
$('#settings-page .nav li').first().find('a').trigger('click');
|
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
|
|
|
|
if (GlobalVariables.user.privileges.system_settings.edit == false) {
|
|
|
|
$('#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
|
|
|
|
2013-09-26 19:06:57 +03:00
|
|
|
if (GlobalVariables.user.privileges.user_settings.edit == false) {
|
|
|
|
$('#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
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Bind the backend/settings default event handlers. This method depends on the
|
2013-09-20 16:58:11 +03:00
|
|
|
* backend/settings html, so do not use this method on a different page.
|
|
|
|
*/
|
2016-04-13 20:54:56 +03:00
|
|
|
function _bindEventHandlers() {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
$('.tab').click(function() {
|
2013-09-20 16:58:11 +03:00
|
|
|
// Bootstrap has a bug with toggle buttons. Their toggle state is lost when the
|
2015-10-09 00:12:59 +03:00
|
|
|
// button is hidden or shown. Show before anything else we need to store the toggle
|
2013-09-20 16:58:11 +03:00
|
|
|
// and apply it whenever the user tab is clicked..
|
|
|
|
var areNotificationsActive = $('#user-notifications').hasClass('active');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-11 18:58:46 +03:00
|
|
|
$(this).parent().find('.active').removeClass('active');
|
2013-09-14 19:10:59 +03:00
|
|
|
$(this).addClass('active');
|
|
|
|
$('.tab-content').hide();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
|
|
|
if ($(this).hasClass('general-tab')) {
|
2013-09-14 19:10:59 +03:00
|
|
|
$('#general').show();
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new SystemSettings();
|
2015-10-09 00:12:59 +03:00
|
|
|
} else if ($(this).hasClass('business-logic-tab')) {
|
2013-09-14 19:10:59 +03:00
|
|
|
$('#business-logic').show();
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new SystemSettings();
|
2015-11-24 23:48:57 +02:00
|
|
|
|
2013-09-14 19:10:59 +03:00
|
|
|
} else if ($(this).hasClass('user-tab')) {
|
|
|
|
$('#user').show();
|
2016-04-13 20:54:56 +03:00
|
|
|
settings = new UserSettings();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-20 16:58:11 +03:00
|
|
|
// Apply toggle state to user notifications button.
|
|
|
|
if (areNotificationsActive) {
|
|
|
|
$('#user-notifications').addClass('active');
|
|
|
|
} else {
|
2015-10-09 00:12:59 +03:00
|
|
|
$('#user-notifications').removeClass('active');
|
2013-09-20 16:58:11 +03:00
|
|
|
}
|
2015-11-24 23:48:57 +02:00
|
|
|
} else if ($(this).hasClass('about-tab')) {0
|
2013-11-22 18:19:52 +02:00
|
|
|
$('#about').show();
|
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.
|
|
|
|
*/
|
|
|
|
$('.save-settings').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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
$('#username').focusout(function() {
|
|
|
|
var $input = $(this);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-13 20:54:56 +03:00
|
|
|
if ($input.prop('readonly') == true || $input.val() == '') {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-13 20:54:56 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username',
|
|
|
|
postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
username: $input.val(),
|
|
|
|
user_id: $input.parents().eq(2).find('#user-id').val()
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-18 17:56:12 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
2016-04-13 20:54:56 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-18 17:56:12 +03:00
|
|
|
if (response == false) {
|
|
|
|
$input.css('border', '2px solid red');
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['username_already_exists']);
|
2013-11-24 17:45:44 +02:00
|
|
|
$input.attr('already-exists', 'true');
|
2013-10-18 17:56:12 +03:00
|
|
|
} else {
|
|
|
|
$input.css('border', '');
|
2013-11-24 17:45:44 +02:00
|
|
|
$input.attr('already-exists', 'false');
|
2013-10-18 17:56:12 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-10-18 17:56:12 +03:00
|
|
|
});
|
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);
|