2013-09-03 21:58:56 +03:00
|
|
|
/**
|
|
|
|
* This namespace handles the js functionality of the users backend page. It uses three other
|
|
|
|
* classes (defined below) in order to handle the admin, provider and secretary record types.
|
|
|
|
*
|
2013-09-23 18:42:36 +03:00
|
|
|
* @namespace BackendUsers
|
2013-07-27 00:30:44 +03:00
|
|
|
*/
|
2013-09-03 21:58:56 +03:00
|
|
|
var BackendUsers = {
|
2013-09-23 18:42:36 +03:00
|
|
|
MIN_PASSWORD_LENGTH: 7,
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
|
|
|
* Contains the current tab record methods for the page.
|
|
|
|
*
|
|
|
|
* @type AdminsHelper|ProvidersHelper|SecretariesHelper
|
|
|
|
*/
|
|
|
|
helper: {},
|
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.
|
2013-09-24 16:09:04 +03:00
|
|
|
*
|
2013-09-25 18:43:17 +03:00
|
|
|
* @type {object}
|
2013-09-24 16:09:04 +03:00
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
wp: {},
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
/**
|
|
|
|
* Initialize the backend users page.
|
|
|
|
*
|
|
|
|
* @param {bool} defaultEventHandlers (OPTIONAL) Whether to bind the default event handlers
|
|
|
|
* (default: true).
|
|
|
|
*/
|
|
|
|
initialize: function(defaultEventHandlers) {
|
|
|
|
if (defaultEventHandlers == undefined) defaultEventHandlers = true;
|
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
// Initialize jScrollPane Scrollbars
|
|
|
|
$('#filter-admins .results').jScrollPane();
|
|
|
|
$('#filter-providers .results').jScrollPane();
|
|
|
|
$('#filter-secretaries .results').jScrollPane();
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Instanciate default helper object (admin).
|
|
|
|
BackendUsers.helper = new AdminsHelper();
|
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
BackendUsers.helper.filter('');
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.wp = new WorkingPlan();
|
|
|
|
BackendUsers.wp.bindEventHandlers();
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Fill the services and providers list boxes.
|
|
|
|
$.each(GlobalVariables.services, function(index, service) {
|
2013-09-14 19:10:59 +03:00
|
|
|
var html = '<label class="checkbox"><input type="checkbox" data-id="' + service.id + '" />'
|
|
|
|
+ service.name + '</label>';
|
2013-09-03 21:58:56 +03:00
|
|
|
$('#provider-services').append(html);
|
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#provider-services').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-10-10 19:50:33 +03:00
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
$.each(GlobalVariables.providers, function(index, provider) {
|
2013-09-14 19:10:59 +03:00
|
|
|
var html = '<label class="checkbox"><input type="checkbox" data-id="' + provider.id + '" />'
|
|
|
|
+ provider.first_name + ' ' + provider.last_name + '</label>';
|
2013-09-03 21:58:56 +03:00
|
|
|
$('#secretary-providers').append(html);
|
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#secretary-providers').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-09-03 21:58:56 +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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-03 21:58:56 +03:00
|
|
|
// Bind event handlers.
|
|
|
|
if (defaultEventHandlers) BackendUsers.bindEventHandlers();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds the defauly backend users event handlers. Do not use this method on a different
|
|
|
|
* page because it needs the backend users page DOM.
|
|
|
|
*/
|
|
|
|
bindEventHandlers: function() {
|
|
|
|
/**
|
|
|
|
* Event: Page Tab Button "Click"
|
|
|
|
*
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
if ($(this).hasClass('admins-tab')) { // display admins tab
|
|
|
|
$('#admins').show();
|
|
|
|
BackendUsers.helper = new AdminsHelper();
|
|
|
|
} 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 });
|
2013-09-03 21:58:56 +03:00
|
|
|
BackendUsers.helper = new ProvidersHelper();
|
|
|
|
} else if ($(this).hasClass('secretaries-tab')) { // display secretaries tab
|
|
|
|
$('#secretaries').show();
|
|
|
|
BackendUsers.helper = new SecretariesHelper();
|
|
|
|
|
|
|
|
// Update the list with the all the available providers.
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'key': ''
|
|
|
|
};
|
2013-09-03 21:58:56 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
//////////////////////////////////////////////////////////
|
2013-09-24 19:05:40 +03:00
|
|
|
//console.log('Get all db providers response:', response);
|
2013-09-03 21:58:56 +03:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-09-03 21:58:56 +03:00
|
|
|
|
|
|
|
GlobalVariables.providers = response;
|
2013-10-10 19:50:33 +03:00
|
|
|
|
|
|
|
$('#secretary-providers').data('jsp').destroy();
|
2013-09-03 21:58:56 +03:00
|
|
|
$('#secretary-providers').html('');
|
|
|
|
$.each(GlobalVariables.providers, function(index, provider) {
|
2013-09-14 19:10:59 +03:00
|
|
|
var html = '<label class="checkbox"><input type="checkbox" data-id="' + provider.id + '" />'
|
|
|
|
+ provider.first_name + ' ' + provider.last_name + '</label>';
|
2013-09-03 21:58:56 +03:00
|
|
|
$('#secretary-providers').append(html);
|
|
|
|
});
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', true);
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#secretary-providers').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-09-03 21:58:56 +03:00
|
|
|
}, 'json');
|
|
|
|
}
|
|
|
|
|
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
BackendUsers.helper.filter('');
|
|
|
|
$('.filter-key').val('');
|
|
|
|
});
|
|
|
|
|
2013-09-24 16:09:04 +03:00
|
|
|
/**
|
|
|
|
* Event: Admin, Provider, Secretary Username "Focusout"
|
|
|
|
*
|
|
|
|
* When the user leaves the username input field we will need to check if the username
|
|
|
|
* is not taken by another record in the system. Usernames must be unique.
|
|
|
|
*/
|
|
|
|
$('#admin-username, #provider-username, #secretary-username').focusout(function() {
|
|
|
|
var $input = $(this);
|
|
|
|
|
|
|
|
if ($input.prop('readonly') == true || $input.val() == '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-09-24 16:09:04 +03:00
|
|
|
'username': $input.val(),
|
2013-11-23 21:10:31 +02:00
|
|
|
'user_id': $input.parents().eq(2).find('.record-id').val()
|
2013-09-23 18:42:36 +03:00
|
|
|
};
|
2013-09-24 16:09:04 +03:00
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
///////////////////////////////////////////////////////
|
2013-11-23 21:10:31 +02:00
|
|
|
console.log('Validate Username Response:', response);
|
2013-09-23 18:42:36 +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
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
});
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
// ------------------------------------------------------------------------
|
2013-09-24 16:09:04 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
AdminsHelper.prototype.bindEventHandlers();
|
2013-09-03 21:58:56 +03:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
ProvidersHelper.prototype.bindEventHandlers();
|
2013-09-03 21:58:56 +03:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
SecretariesHelper.prototype.bindEventHandlers();
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
2013-09-24 16:09:04 +03:00
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|