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-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
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
(function(exports){
|
|
|
|
|
|
|
|
'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
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
exports.initialize = function(defaultEventHandlers) {
|
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
// Initialize jScrollPane Scrollbars
|
|
|
|
$('#filter-admins .results').jScrollPane();
|
|
|
|
$('#filter-providers .results').jScrollPane();
|
|
|
|
$('#filter-secretaries .results').jScrollPane();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Instanciate default helper object (admin).
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new AdminsHelper();
|
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
|
|
|
helper.bindEventHandlers();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
exports.wp = new WorkingPlan();
|
|
|
|
exports.wp.bindEventHandlers();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Fill the services and providers list boxes.
|
2015-07-25 15:04:23 +03:00
|
|
|
var html = '<div class="col-md-12">';
|
2013-09-03 21:58:56 +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">' +
|
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + service.id + '" />' +
|
2015-10-09 00:12:59 +03:00
|
|
|
service.name +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</label>' +
|
|
|
|
'</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);
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#provider-services').jScrollPane({ mouseWheelSpeed: 70 });
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-05-14 13:40:11 +03:00
|
|
|
html = '<div class="col-md-12">';
|
2013-09-03 21:58:56 +03:00
|
|
|
$.each(GlobalVariables.providers, function(index, provider) {
|
2015-10-09 00:12:59 +03:00
|
|
|
html +=
|
2015-07-25 15:04:23 +03:00
|
|
|
'<div class="checkbox">' +
|
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
2015-10-09 00:12:59 +03:00
|
|
|
provider.first_name + ' ' + provider.last_name +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</label>' +
|
|
|
|
'</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);
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#secretary-providers').jScrollPane({ mouseWheelSpeed: 70 });
|
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
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Binds the defauly 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.
|
|
|
|
*/
|
|
|
|
$('.tab').click(function() {
|
2013-10-11 18:58:46 +03:00
|
|
|
$(this).parent().find('.active').removeClass('active');
|
2013-09-03 21:58:56 +03:00
|
|
|
$(this).addClass('active');
|
|
|
|
$('.tab-content').hide();
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admins, #providers, #secretaries').off();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
if ($(this).hasClass('admins-tab')) { // display admins tab
|
|
|
|
$('#admins').show();
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new AdminsHelper();
|
2013-09-03 21:58:56 +03:00
|
|
|
} else if ($(this).hasClass('providers-tab')) { // display providers tab
|
|
|
|
$('#providers').show();
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#provider-services').data('jsp').destroy();
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#provider-services').jScrollPane({ mouseWheelSpeed: 70 });
|
2016-04-26 22:33:30 +03:00
|
|
|
helper = new ProvidersHelper();
|
2013-09-03 21:58:56 +03:00
|
|
|
} else if ($(this).hasClass('secretaries-tab')) { // display secretaries tab
|
|
|
|
$('#secretaries').show();
|
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.
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
key: ''
|
|
|
|
};
|
2013-09-03 21:58:56 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
GlobalVariables.providers = response;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#secretary-providers').data('jsp').destroy();
|
2015-07-25 15:04:23 +03:00
|
|
|
|
|
|
|
var html = '<div class="col-md-12">';
|
2013-09-03 21:58:56 +03:00
|
|
|
$.each(GlobalVariables.providers, function(index, provider) {
|
2015-10-09 00:12:59 +03:00
|
|
|
html +=
|
2015-07-25 15:04:23 +03:00
|
|
|
'<div class="checkbox">' +
|
|
|
|
'<label class="checkbox">' +
|
|
|
|
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
2015-10-09 00:12:59 +03:00
|
|
|
provider.first_name + ' ' + provider.last_name +
|
2015-07-25 15:04:23 +03:00
|
|
|
'</label>' +
|
|
|
|
'</div>';
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2015-07-25 15:04:23 +03:00
|
|
|
});
|
|
|
|
html += '</div>';
|
|
|
|
$('#secretary-providers').html(html);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2015-07-25 15:04:23 +03:00
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', true);
|
|
|
|
$('#secretary-providers').jScrollPane({ mouseWheelSpeed: 70 });
|
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.
|
|
|
|
*/
|
|
|
|
$('#admin-username, #provider-username, #secretary-username').focusout(function() {
|
|
|
|
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
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
if (response == false) {
|
|
|
|
$input.css('border', '2px solid red');
|
2013-11-23 21:10:31 +02:00
|
|
|
$input.attr('already-exists', 'true');
|
2013-12-20 19:44:44 +02: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 {
|
|
|
|
$input.css('border', '');
|
2013-11-23 21:10:31 +02:00
|
|
|
$input.attr('already-exists', 'false');
|
2013-12-20 19:44:44 +02: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
|
|
|
});
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
})(window.BackendUsers);
|