// This method initializes Add User page set-up on the page load is completed.
$(function() {
$("#trainingDatePicker").datepicker();
//$("#trainingDatePicker").datepicker("setDate", new Date());
$("#editTrainingDatePicker").datepicker();
});
function initAddUserPage() {
// Make the focus on the first element after page load completes
$("input:text:visible:first").focus();
// Populate State dropdown when page load completes.
getStates(true);
getRoles();
// Refresh the state list dropdown on change of country dropdown
$('#Country').change(function() {
getStates();
if($('#Country option:selected').val().toUpperCase() == 'MEXICO') {
$('#StateLegend').text('');
}
else {
$('#StateLegend').text('*');
}
});
// Validate Add User form fields
$.validator.addMethod("StateCheck", function (value, element) {
var country = $('#Country option:selected').val();
var state = $('#States option:selected').val();
if(state===undefined){
state = $('#States').val();
}
return StateCheck(country, state);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("securityQuestionCheck", function (value, element) {
return checkBlankOrEmpty(value, element);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("isUSPSTestCenterCheck", function (value, element) {
var testCenter = $('input[name="isUSPSTestCenter"]:checked').val();
return testCenter == 0 || $('#testCenterList').val() != null;
}, messageArr[MSG_ASSOCIATE_TC]);
$.validator.addMethod("passwordCheck", function (value, element) {
return measurePasswordStrength($("#userPassword").val(), $("#userLoginId").val());
}, 'The password you entered does not follow the password rules. Please update your password.');
$.validator.addMethod("equalToIgnoreCase", function (value, element, param) {
return this.optional(element) || (value.toLowerCase() == $(param).val().toLowerCase());
},'The Email and Retype Email do not match.');
$("#addUserForm").validate({
errorClass: "errorInline",
errorElement: "div",
errorPlacement: function(error, element) {
error.appendTo( element.parent("td"));
},
rules: {
States:{
StateCheck: true
},
securityQuestion : {
securityQuestionCheck: true
},
isUSPSTestCenter : {
isUSPSTestCenterCheck: true
},
testCenter : {
testCenterCheck: true
},
userPassword : {
passwordCheck: true
},
retypeUserPassword : {
equalTo: "#userPassword"
},
retypeEmail : {
equalToIgnoreCase: "#email"
}
},
messages: {
retypeUserPassword: {
equalTo: "The Password and Retype Password do not match. Please make sure that the passwords match."
},
retypeEmail: {
equalToIgnoreCase: "The Email and Retype Email do not match."
}
}
});
if($("input[name=isUSPSTestCenter]:checked").val() == 1) {
$('#statusInput').show();
$('#trainingDateInput').show();
$('#TestCenter').show();
getTestCenters();
}
else {
$('#statusInput').hide();
$('#trainingDateInput').hide();
$('#TestCenter').hide();
$('#isPracticalTestCenter').hide();
$('#checkboxLabel').hide();
}
// Showing the test center picklist only if user opt to associate by clicking on radio button
$('input[type=radio][name=isUSPSTestCenter]').on('change', function(){
if(this.value == 1) {
$('#statusInput').show();
$('#trainingDateInput').show();
$('#TestCenter').show();
getTestCenters();
}
else{
$('#statusInput').hide();
$('#trainingDateInput').hide();
$('#TestCenter').hide();
$('#isPracticalTestCenter').hide();
$('#checkboxLabel').hide();
}
});
$('#reasonForAccess').keypress(function() {
return $(this).val().length < 1500;
});
}
// This method initializes Add User page set-up on the page load is completed.
function initEditUserPage() {
// Make the focus on the first element after page load completes
$("input:text:visible:first").focus();
// Populate State dropdown when page load completes.
// getStatesList();
getStates(true);
// getAccountRoles(true);
// Refresh the state list dropdown on change of country dropdown
$('#Country').change(function() {
// getStatesList();
getStates();
if($('#Country option:selected').val().toUpperCase() == 'MEXICO') {
$('#StateLegend').text('');
}
else {
$('#StateLegend').text('*');
}
});
// Validate Add User form fields
$.validator.addMethod("StateCheck", function (value, element) {
var country = $('#Country option:selected').val();
var state = $('#States option:selected').val();
if(state===undefined){
state = $('#States').val();
}
return StateCheck(country, state);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("securityQuestionCheck", function (value, element) {
return checkBlankOrEmpty(value, element);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("isUSPSTestCenterCheck", function (value, element) {
var testCenter = $('input[name="isUSPSTestCenter"]:checked').val();
return testCenter == 0 || $('#testCenterList').val() != null;
}, messageArr[MSG_ASSOCIATE_TC]);
$.validator.addMethod("passwordCheck", function (value, element) {
return measurePasswordStrength($("#userPassword").val(), $("#userLoginId").val());
}, 'The password you entered does not follow the password rules. Please update your password.');
$.validator.addMethod("equalToIgnoreCase", function (value, element, param) {
return this.optional(element) || (value.toLowerCase() == $(param).val().toLowerCase());
},'The Email and Retype Email do not match.');
$("#editUserForm").validate({
errorClass: "errorInline",
errorElement: "div",
errorPlacement: function(error, element) {
error.appendTo( element.parent("td"));
},
rules: {
States:{
StateCheck: true
},
securityQuestion : {
securityQuestionCheck: true
},
isUSPSTestCenter : {
isUSPSTestCenterCheck: true
},
testCenter : {
testCenterCheck: true
},
userPassword : {
passwordCheck: true
},
retypeUserPassword : {
equalTo: "#userPassword"
},
retypeEmail : {
equalToIgnoreCase: "#email"
}
},
messages: {
retypeUserPassword: {
equalTo: "The Password and Retype Password do not match. Please make sure that the passwords match."
},
retypeEmail: {
equalToIgnoreCase: "The Email and Retype Email do not match."
}
}
});
if($("input[name=isUSPSTestCenter]:checked").val() == 1) {
$('#statusInput').show();
$('#trainingDateInput').show();
$('#TestCenter').show();
getTestCenters();
}
else {
$('#statusInput').hide();
$('#trainingDateInput').hide();
$('#TestCenter').hide();
$('#isPracticalTestCenter').hide();
$('#checkboxLabel').hide();
}
// Showing the test center picklist only if user opt to associate by clicking on radio button
$('input[type=radio][name=isUSPSTestCenter]').on('change', function(){
if(this.value == 1) {
$('#statusInput').show();
$('#trainingDateInput').show();
$('#TestCenter').show();
getTestCenters();
}
else{
$('#statusInput').hide();
$('#trainingDateInput').hide();
$('#TestCenter').hide();
$('#isPracticalTestCenter').hide();
$('#checkboxLabel').hide();
}
});
$('#reasonForAccess').keypress(function() {
return $(this).val().length < 1500;
});
}
// This method is called after Request User Access page load completes. It does the set-up of the page and initializes the components.
function initRequestUserAccessPage() {
// Activate the picklist for test center and make the focus on the first element after page load completes
$("#testCenter").pickList({
onChange: function() {
$('#testCenter').val() && $('div.errorInline[for="isUSPSTestCenter"]').remove();
}
});
$("input:text:visible:first").focus();
// Populate State dropdown when page load completes.
getStatesList();
// Refresh the state list dropdown on change of country dropdown
$('#Country').change(function() {
getStatesList();
if($('#Country option:selected').val().toUpperCase() == 'MEXICO') {
$('#StateLegend').text('');
}
else {
$('#StateLegend').text('*');
}
});
// Validate Add User form fields
$.validator.addMethod("StateCheck", function (value, element) {
var country = $('#Country option:selected').val();
var state = $('#States option:selected').val();
return StateCheck(country, state);
}, 'This field is required');
$.validator.addMethod("securityQuestionCheck", function (value, element) {
return checkBlankOrEmpty(value, element);
}, 'This field is required');
$.validator.addMethod("isUSPSTestCenterCheck", function (value, element) {
var testCenter = $('input[name="isUSPSTestCenter"]:checked').val();
return testCenter == 0 || $('#testCenter').val() != null;
}, messageArr[MSG_ASSOCIATE_TC]);
$.validator.addMethod("passwordCheck", function (value, element) {
return measurePasswordStrength($("#userPassword").val(), $("#userLoginId").val());
}, 'The password you entered does not follow the password rules. Please update your password.');
$.validator.addMethod("equalToIgnoreCase", function (value, element, param) {
return this.optional(element) || (value.toLowerCase() == $(param).val().toLowerCase());
},'The Email and Retype Email do not match.');
$("#addUserForm").validate({
errorClass: "errorInline",
errorElement: "div",
errorPlacement: function(error, element) {
var ele=element.attr('id');
var elementName = element.attr('name');
if(elementName == 'isUSPSTestCenter') {
$('
| |
').insertAfter(element.closest('tr').next());
error.appendTo( element.parent("td"));
} else {
$(' | |
').insertAfter(element.closest('tr'));
error.appendTo( element.parent("td"));
}
error.css('position', 'absolute');
},
rules: {
States:{
StateCheck: true
},
securityQuestion : {
securityQuestionCheck: true
},
isUSPSTestCenter : {
isUSPSTestCenterCheck: true
},
testCenter : {
testCenterCheck: true
},
userPassword : {
passwordCheck: true
},
retypeUserPassword : {
equalTo: "#userPassword"
},
retypeEmail : {
equalToIgnoreCase: "#email"
}
},
messages: {
retypeUserPassword: {
equalTo: "The Password and Retype Password do not match. Please make sure that the passwords match."
},
retypeEmail: {
equalToIgnoreCase: "The Email and Retype Email do not match."
}
}
});
// Activate the test center for picklist
if($("input[name=isUSPSTestCenter]:checked").val() == 1) {
$('#testCenterInput').show();
$('#statusInput').show();
$('#trainingDateInput').show();
}
else {
$('#testCenterInput').hide();
$('#statusInput').hide();
$('#trainingDateInput').hide();
}
// Showing the test center picklist only if user opt to associate by clicking on radio button
$('input[type=radio][name=isUSPSTestCenter]').on('change', function(){
if(this.value == 1) {
$('#testCenterInput').show();
$('#statusInput').show();
$('#trainingDateInput').show();
}
else{
$('#testCenterInput').hide();
$('#statusInput').hide();
$('#trainingDateInput').hide();
}
});
$('#reasonForAccess').keypress(function() {
return $(this).val().length < 1500;
});
}
// This method initializes Update profile Page set-up on the page load is completed.
function initUpdateUserPage() {
// Make the focus on the first element after page load completes
$("input:text:visible:first").focus();
// Populate State dropdown when page load completes.
//getStatesList();
getStates(true);
// Refresh the state list dropdown on change of country dropdown
$('#Country').change(function() {
getStates();
if($('#Country option:selected').val().toUpperCase() == 'MEXICO') {
$('#StateLegend').text('');
}
else {
$('#StateLegend').text('*');
}
});
// Validate my profile form fields
$.validator.addMethod("StateCheck", function (value, element) {
var country = $('#Country option:selected').val();
var state = $('#States option:selected').val();
if(state===undefined){
state = $('#States').val();
}
return StateCheck(country, state);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("securityQuestionCheck", function (value, element) {
return checkBlankOrEmpty(value, element);
}, messageArr[MSG_FIELD_REQUIRED] );
$.validator.addMethod("equalToIgnoreCase", function (value, element, param) {
return this.optional(element) || (value.toLowerCase() == $(param).val().toLowerCase());
},'The Email and Retype Email do not match.');
$("#updateProfileForm").validate({
errorClass: "errorInline",
errorElement: "div",
errorPlacement: function(error, element) {
error.appendTo( element.parent("td"));
},
rules: {
States:{
StateCheck: true
},
securityQuestion : {
securityQuestionCheck: true
},
retypeEmail : {
equalToIgnoreCase: "#email"
}
},
messages: {
retypeEmail: {
equalToIgnoreCase: "The Email and Retype Email do not match."
}
},
});
}
// Function to show message in banner
function showMessage(message) {
if(message == 'SRH25012' && document.cookie.indexOf('flag')!= -1) {
showFailureMessage("No search results found for the given criteria. Please refine your search.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return;
}
}
// Function to check conditions to display validation message for State dropdown.
function StateCheck(country, state){
return (state.toUpperCase() != 'SELECT' && state != '');
}
function showUserAddedMessage(errorCode) {
if(errorCode && errorCode != 'null' && document.cookie.indexOf('flag')!= -1) {
var errorMessage = 'Unable to add User';
if(errorCode == '164') {
errorMessage = 'Login id has already been used. Please enter a different login id.';
} else if(errorCode == '499') {
errorMessage = 'Email address has already been used. Please enter a different email address.';
}
showFailureMessage(errorMessage);
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return;
}
}
function showUserAddUpdateSuccessMessage(added, updated) {
if(added && added != 'null' && document.cookie.indexOf('flag')!= -1) {
showSuccessMessage("User has been added.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return;
} else if(updated && updated != 'null' && document.cookie.indexOf('flag')!= -1) {
showSuccessMessage("User has been updated.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return;
}
}
function showUserUpdatedMessage(errorCode) {
if (errorCode && errorCode != 'null' && document.cookie.indexOf('flag')!= -1) {
var errorMessage = 'Unable to update User';
if(errorCode == '499') {
errorMessage = 'Email address has already been used. Please enter a different email address.';
}
showFailureMessage(errorMessage);
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return;
}
}
function showChangePasswordMessage(message,errorCode) {
if (message == 'updateSuccessful' && document.cookie.indexOf('flag')!= -1) {
showSuccessMessage("User has been updated.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return false;
}
if(errorCode == '499'){
showFailureMessage("Email address has already been used. Please enter a different email address.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return false;
}
if(message == 'updateFailure' && document.cookie.indexOf('flag')!= -1) {
showFailureMessage("Unable to update user.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return false;
}
if (message == 'updatePasswordSuccessful' && document.cookie.indexOf('flag')!= -1) {
showSuccessMessage("Password has been changed.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return false;
}
if(message == 'updatePasswordFailure' && document.cookie.indexOf('flag')!= -1) {
showFailureMessage("Unable to change password.");
document.cookie = 'flag=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
return false;
}
}
function editUserCancel() {
return true;
}
function showLoginIDLastnameValidity(message) {
if (message == 'Success') {
showSuccessMessage("Please enter the security answer.");
return false;
}
// error message USR25011 & USR25021 is returned from TA
if ((message == 'Failure') || (message == 'USR25011')) {
showFailureMessage("We could not locate your record.
Please check that you have entered your details correctly and resubmit.");
return false;
}
if (message == 'USR25021') {
showFailureMessage("User Login ID and Last Name mismatch. Please provide correct details.");
return false;
}
}
function showSecurityAnswerIsValid(message) {
if (message == 'Success') {
showSuccessMessage("Please change your password below.");
return false;
}
if (message == 'Error') {
showFailureMessage("We could not locate your authorization.
Please check that you have properly entered your security answer.");
return false;
}
if (message == 'Failure') {
showFailureMessage("We're unable to process your request. Please try later.");
return false;
}
}
function showForgotPasswordMessage(message) {
if (message == 'Success') {
showSuccessMessage("Your password has been changed successfully.
Please login using your new password.");
return false;
}
if (message == 'USR25025') {
showFailureMessage("Please provide password other than current password.");
return false;
}
if (message == 'Error') {
showFailureMessage("We're unable to process your request. Please try later.");
return false;
}
if (message == 'Failure') {
showFailureMessage("We're unable to process your request. Please try later.");
return false;
}
if (message == 'USS03') {
showFailureMessage("Your Account is Locked. Please contact Administrator.");
return false;
}
if (message == 'USS05') {
showFailureMessage("The password on your account has expired. Please contact PSI support to have your password reset.");
return false;
}
}
function initForgotPasswordPage() {
// Make the focus on the first element when page load completes
$("input[type='text'],[type='password']").not('hidden').first().focus();
$.validator.addMethod("passwordCheck", function (value, element) {
return measurePasswordStrength($("#userPassword").val(), $("#loginId").val());
}, 'The password you entered does not follow the password rules. Please update your password.');
//Step 1
$('#step1btn').click(function() {
$("#forgotpassword").valid();
if($("#forgotpassword").valid())
{
checkLoginIDLastnameValidity();
}
});
//Step 2
$('#step2btn').click(function() {
$("#forgotpassword").valid();
if($("#forgotpassword").valid())
{
checkSecurityAnswerIsValid();
}
});
//Step 3
$('#step3btn').click(function() {
$("#forgotpassword").valid();
if($("#forgotpassword").valid())
{
validateForgotPasswordFormAndSubmit();
}
});
$("#forgotpassword").validate({
errorClass: "errorInline",
errorElement: "div",
errorPlacement: function(error, element) {
error.appendTo( element.parent("td"));
},
rules: {
userPassword: {
passwordCheck: true
},
confirmpassword: {
equalTo: "#userPassword"
},
securityAnswer: {
maxlength: 1000
}
},
messages: {
confirmpassword: {
equalTo: "The passwords do not match. Please make sure that the passwords match and resubmit."
},
securityAnswer: {
maxlength: "Max length allowed is 1000 characters."
}
}
});
}
function checkLoginIDLastnameValidity(){
var loginId = $('#loginId').val();
var lastName = $('#lastname').val();
var accountId = $('#accountId').val();
var servletAction = $('#loginIDLastnameValidator').val();
var contextPath = $('#contextPath').val();
var url = contextPath + "/applicantcontentservlet?actionid="+servletAction+"&loginId="+loginId+"&lastName="+lastName+"&accountId="+accountId;
$.ajax({
type: "GET",
url: url,
dataType: "json",
async: true,
cache: false,
beforeSend: function(){
var imagePath = contextPath + "/images/spinner_squares_circle.gif";
$("#loader1").html('
');
},
success: function(response) {
if(typeof response.info === 'undefined'){
showLoginIDLastnameValidity(response.error);
}
else{
$('#loginId').attr('readonly','readonly');
$('#lastname').attr('readonly','readonly');
$("#step1buttonpanel" ).hide();
$("#userId").val(response.userID);
$("#securityQuestion").html(response.secretQuestion);
var acceptImagePath = contextPath + '/images/notification/accept.png';
$("#accountIdmark").html("
");
$("#loginIdmark").html("
");
$("#lastnamemark").html("
");
$('#securityQuestionDiv').show();
showLoginIDLastnameValidity(response.info);
}
},
error: function () {
$( "#loader1" ).hide();
showLoginIDLastnameValidity('Error');
},
complete: function(){
$( "#loader1" ).hide();
$( "#error" ).hide();
}
});
}
function checkSecurityAnswerIsValid(){
var userId = $('#userId').val();
var loginId = $('#loginId').val();
var accountId = $('#accountId').val();
var securityAnswer = $('#securityAnswer').val();
var servletAction = $('#securityAnswerValidator').val();
var contextPath = $('#contextPath').val();
var url = contextPath + "/applicantcontentservlet?actionid="+servletAction+"&userId="+userId+"&securityAnswer="+securityAnswer+"&loginId="+loginId+"&accountId="+accountId;
$.ajax({
type: "GET",
url: url,
dataType: "json",
async: true,
cache: false,
beforeSend: function(){
var imagePath = contextPath + "/images/spinner_squares_circle.gif";
$("#loader2").html('
');
},
success: function(response) {
if(typeof response.info === 'undefined'){
showSecurityAnswerIsValid(response.error);
}
else {
$('#securityAnswer').attr('readonly','readonly');
var acceptImagePath = contextPath + '/images/notification/accept.png';
$("#sqmark").html("
");
$("#step2buttonpanel" ).hide();
$('#passwordDetails').show();
showSecurityAnswerIsValid(response.info);
}
},
error: function () {
$( "#loader2" ).hide();
showSecurityAnswerIsValid('Failure');
},
complete: function(){
$( "#loader2" ).hide();
$( "#error" ).hide();
}
});
}
function validateForgotPasswordFormAndSubmit()
{
var userId = $('#userId').val();
var loginId = $('#loginId').val();
var accountId = $('#accountId').val();
var securityAnswer = $('#securityAnswer').val();
var newpassword = $('#userPassword').val();
var servletAction = $('#passwordDetailsValidator').val();
var contextPath = $('#contextPath').val();
var dataObj = {actionid:servletAction, userId:userId, loginId:loginId, securityAnswer:securityAnswer, newpassword:newpassword, accountId:accountId};
var url = contextPath + "/applicantcontentservlet";
$.ajax({
type: "POST",
url: url,
data:dataObj,
dataType: "json",
async: true,
cache: false,
beforeSend: function(){
var imagePath = contextPath + "/images/spinner_squares_circle.gif";
$("#loader1").html('
');
},
success: function(response) {
if(typeof response.info === 'undefined'){
showForgotPasswordMessage(response.error);
}
else
{
window.location.href=contextPath + '/index.jsp?info='+response.info;
}
},
error: function () {
showForgotPasswordMessage('Error');
$( "#loader1" ).hide();
},
complete: function(){
$( "#loader1" ).hide();
$( "#error" ).hide();
}
});
}