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
|
|
|
/**
|
|
|
|
* This flag is used when trying to cancel row editing. It is
|
|
|
|
* true only whenever the user presses the cancel button.
|
|
|
|
*
|
|
|
|
* @type {bool}
|
|
|
|
*/
|
|
|
|
enableCancel: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This flag determines whether the jeditables are allowed to submit. It is
|
|
|
|
* true only whenever the user presses the save button.
|
|
|
|
*
|
|
|
|
* @type {bool}
|
|
|
|
*/
|
|
|
|
enableSubmit: false,
|
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;
|
|
|
|
|
|
|
|
// Instanciate default helper object (admin).
|
|
|
|
BackendUsers.helper = new AdminsHelper();
|
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
BackendUsers.helper.filter('');
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
|
|
|
|
$.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);
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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() {
|
|
|
|
$('.active').removeClass('active');
|
|
|
|
$(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();
|
|
|
|
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.
|
|
|
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_filter_providers';
|
|
|
|
var postData = { 'key': '' };
|
|
|
|
$.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;
|
|
|
|
|
|
|
|
$('#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);
|
|
|
|
}, '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;
|
|
|
|
}
|
|
|
|
|
2013-09-23 18:42:36 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_validate_username';
|
|
|
|
var postData = {
|
2013-09-24 16:09:04 +03:00
|
|
|
'username': $input.val(),
|
|
|
|
'record_exists': ($input.parents().eq(2).find('.record-id').val() != '') ? true : false
|
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-09-24 19:05:40 +03: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');
|
|
|
|
$input.parents().eq(3).find('.form-message').text('Username already exists.');
|
|
|
|
$input.parents().eq(3).find('.form-message').show();
|
|
|
|
} else {
|
|
|
|
$input.css('border', '');
|
|
|
|
if ($input.parents().eq(3).find('.form-message').text() == 'Username already exists.') {
|
|
|
|
$input.parents().eq(3).find('.form-message').hide();
|
|
|
|
}
|
2013-09-23 18:42:36 +03:00
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
});
|
|
|
|
|
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-24 16:09:04 +03:00
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|