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-26 22:33:30 +03:00
|
|
|
window.BackendUsers = window.BackendUsers || {};
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Backend Users
|
|
|
|
*
|
|
|
|
* This module handles the js functionality of the users backend page. It uses three other
|
2015-10-09 00:12:59 +03:00
|
|
|
* classes (defined below) in order to handle the admin, provider and secretary record types.
|
|
|
|
*
|
2016-04-26 22:33:30 +03:00
|
|
|
* @module BackendUsers
|
2013-07-27 00:30:44 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimum Password Length
|
|
|
|
*
|
2016-05-14 13:40:11 +03:00
|
|
|
* @type {Number}
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
|
|
|
exports.MIN_PASSWORD_LENGTH = 7;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
|
|
|
* Contains the current tab record methods for the page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:40:11 +03:00
|
|
|
* @type {AdminsHelper|ProvidersHelper|SecretariesHelper}
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
var helper = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
/**
|
2013-09-25 18:43:17 +03:00
|
|
|
* Use this class instance for performing actions on the working plan.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:40:11 +03:00
|
|
|
* @type {WorkingPlan}
|
2013-09-24 16:09:04 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
exports.wp = {};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
|
|
|
* Initialize the backend users page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:40:11 +03:00
|
|
|
* @param {Boolean} defaultEventHandlers (OPTIONAL) Whether to bind the default event handlers.
|
2013-09-03 21:58:56 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.initialize = function (defaultEventHandlers) {
|
2016-04-26 22:33:30 +03:00
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2017-11-20 16:04:05 +03:00
|
|
|
exports.wp = new WorkingPlan();
|
|
|
|
exports.wp.bindEventHandlers();
|
|
|
|
|
2016-10-10 19:29:48 +03:00
|
|
|
// Instantiate default helper object (admin).
|
2017-11-20 16:04:05 +03:00
|
|
|
helper = new ProvidersHelper();
|
2016-04-26 22:33:30 +03:00
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
|
|
|
helper.bindEventHandlers();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Fill the services and providers list boxes.
|
2018-01-02 15:14:13 +03:00
|
|
|
var html = '<div>';
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.services, function (index, service) {
|
2015-10-09 00:12:59 +03:00
|
|
|
html +=
|
2015-07-25 15:04:23 +03:00
|
|
|
'<div class="checkbox">' +
|
2018-01-23 12:08:37 +03:00
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + service.id + '" />' +
|
|
|
|
service.name +
|
|
|
|
'</label>' +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</div>';
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
});
|
2015-07-25 15:04:23 +03:00
|
|
|
html += '</div>';
|
|
|
|
$('#provider-services').html(html);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-02 15:14:13 +03:00
|
|
|
html = '<div>';
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.providers, function (index, provider) {
|
|
|
|
html +=
|
2015-07-25 15:04:23 +03:00
|
|
|
'<div class="checkbox">' +
|
2018-01-23 12:08:37 +03:00
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
|
|
|
provider.first_name + ' ' + provider.last_name +
|
|
|
|
'</label>' +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</div>';
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
});
|
2015-07-25 15:04:23 +03:00
|
|
|
html += '</div>';
|
|
|
|
$('#secretary-providers').html(html);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-18 17:56:12 +03:00
|
|
|
$('#reset-working-plan').qtip({
|
|
|
|
position: {
|
|
|
|
my: 'top center',
|
|
|
|
at: 'bottom center'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
classes: 'qtip-green qtip-shadow custom-qtip'
|
|
|
|
}
|
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Bind event handlers.
|
2016-04-26 22:33:30 +03:00
|
|
|
if (defaultEventHandlers) {
|
|
|
|
_bindEventHandlers();
|
|
|
|
}
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
2016-10-10 19:29:48 +03:00
|
|
|
* Binds the default backend users event handlers. Do not use this method on a different
|
2013-09-03 21:58:56 +03:00
|
|
|
* page because it needs the backend users page DOM.
|
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
function _bindEventHandlers() {
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
|
|
|
* Event: Page Tab Button "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-03 21:58:56 +03:00
|
|
|
* Changes the displayed tab.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
|
2017-09-22 15:47:54 +03:00
|
|
|
if ($(this).attr('href') === '#admins') {
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new AdminsHelper();
|
2017-09-22 15:47:54 +03:00
|
|
|
} else if ($(this).attr('href') === '#providers') {
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new ProvidersHelper();
|
2017-09-22 15:47:54 +03:00
|
|
|
} else if ($(this).attr('href') === '#secretaries') {
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new SecretariesHelper();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Update the list with the all the available providers.
|
2017-09-22 15:47:54 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
|
|
|
var data = {
|
2016-07-15 21:52:21 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
key: ''
|
|
|
|
};
|
2018-01-23 12:08:37 +03:00
|
|
|
$.post(url, data, function (response) {
|
2013-09-03 21:58:56 +03:00
|
|
|
GlobalVariables.providers = response;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-02 15:14:13 +03:00
|
|
|
var html = '<div>';
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.providers, function (index, provider) {
|
|
|
|
html +=
|
2015-07-25 15:04:23 +03:00
|
|
|
'<div class="checkbox">' +
|
2018-01-23 12:08:37 +03:00
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
|
|
|
provider.first_name + ' ' + provider.last_name +
|
|
|
|
'</label>' +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</div>';
|
|
|
|
});
|
|
|
|
html += '</div>';
|
|
|
|
$('#secretary-providers').html(html);
|
2017-09-22 15:47:54 +03:00
|
|
|
$('#secretary-providers input:checkbox').prop('disabled', true);
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-09-03 21:58:56 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
|
|
|
helper.bindEventHandlers();
|
2013-09-03 21:58:56 +03:00
|
|
|
$('.filter-key').val('');
|
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Event: Admin, Provider, Secretary Username "Focusout"
|
|
|
|
*
|
|
|
|
* When the user leaves the username input field we will need to check if the username
|
2013-09-24 16:09:04 +03:00
|
|
|
* is not taken by another record in the system. Usernames must be unique.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admin-username, #provider-username, #secretary-username').focusout(function () {
|
2013-09-24 16:09:04 +03:00
|
|
|
var $input = $(this);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
if ($input.prop('readonly') == true || $input.val() == '') {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2015-11-24 00:33:42 +02:00
|
|
|
var userId = $input.parents().eq(2).find('.record-id').val();
|
|
|
|
|
|
|
|
if (userId == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
username: $input.val(),
|
|
|
|
user_id: userId
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$.post(postUrl, postData, function (response) {
|
2013-09-24 16:09:04 +03:00
|
|
|
if (response == false) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$input.closest('.form-group').addClass('has-error');
|
2013-11-23 21:10:31 +02:00
|
|
|
$input.attr('already-exists', 'true');
|
2017-09-11 17:09:15 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').text(EALang.username_already_exists);
|
2013-09-24 16:09:04 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').show();
|
|
|
|
} else {
|
2017-11-14 15:52:59 +03:00
|
|
|
$input.closest('.form-group').removeClass('has-error');
|
2013-11-23 21:10:31 +02:00
|
|
|
$input.attr('already-exists', 'false');
|
2017-09-11 17:09:15 +03:00
|
|
|
if ($input.parents().eq(3).find('.form-message').text() == EALang.username_already_exists) {
|
2013-09-24 16:09:04 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').hide();
|
|
|
|
}
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-09-23 18:42:36 +03:00
|
|
|
});
|
2017-09-22 15:47:54 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
})(window.BackendUsers);
|