myMedisys/tomcatfiles/mymedisys-frontend/WEB-INF/classes/scripts/registration/registration-sca.js
2023-09-06 05:56:42 +05:30

460 lines
12 KiB
JavaScript

var captchaWidgetId;
var onloadCallback = function() {
var recaptchaId = $("#recaptchaId").val();
if ($('#captcha').length) {
captchaWidgetId = grecaptcha.render('captcha', {
'sitekey': recaptchaId,
'callback': captchaVerifyCallback,
'expired-callback': function() { },
'theme': 'light'
});
}
};
var captchaVerifyCallback = function(response) {
$('.captchaError').remove();
};
$(document).ready(function() {
component.initFile();
$("#agencyRegistrationValidation").validate({
// Specify validation error messages
messages: {
mykad: {
minlength: "Please enter 12 digits number"
},
}
});
$("#mykad").on('blur', function(e) {
$(this).removeClass("error");
});
$("a.proj-flow").click(function() {
location.href = $(this).attr("href");
});
// letter and space only regex
$(".input-letter").each(function() {
$(".input-letter").on('keypress', function(e) {
var reg_exp = /^[a-zA-Z\s]*$/;
var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
return reg_exp.test(key);
});
});
$(".input-letter-number-dash").on('keypress', function(e) {
var reg_exp = /^[A-Za-z0-9\-]*$/;
var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
return reg_exp.test(key);
});
$(".input-letter-number-space").on('keypress', function(e) {
var reg_exp = /^[A-Za-z0-9\s]*$/;
var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
return reg_exp.test(key);
});
setFormValidation('#saRegisterValidation');
$("#contactNo").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
document.getElementById("lblAllZero").style.display = null;
$(this).closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblAllZero").style.display = "none";
}
});
$("#contactNoOwner").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
var label = "Invalid contact no format";
document.getElementById("lblOwnerError").style.display = null;
document.getElementById("lblOwnerError").innerHTML = label;
$(this).closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblOwnerError").style.display = "none";
}
});
$("#contactNoPIC").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
var label = "Invalid contact no format";
document.getElementById("lblPicError").style.display = null;
document.getElementById("lblPicError").innerHTML = label;
$('this').closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblPicError").style.display = "none";
}
});
setFormValidation('#saRegisterValidation');
$(".otp-new").otp({
callback: function() {
location.href = contextPath + "/login";
}
});
});
var formsubmit = 0; // sca start
$("form").submit(function() {
if($('form').attr('id') == "saRegisterValidation"){
console.log("sca form submitting");
var nullContact = 0;
var contact = document.getElementById("contactNoOwner").value;
console.log("contact value : " + contact);
if(contact == "" || contact == null){
console.log("contact is null");
var label = "This field is required";
document.getElementById("lblOwnerError").style.display = null;
document.getElementById("lblOwnerError").innerHTML = label;
$("#contactNoOwner").closest(".form-group").addClass("has-danger");
nullContact = 1;
}
else{
document.getElementById("lblOwnerError").style.display = "none";
}
if(!($('#sameAsOwner').is(":checked"))){
var contact2 = document.getElementById("contactNoPIC").value;
if(contact2 == "" || contact2 == null){
console.log("PIC contact is null");
var label = "This field is required";
document.getElementById("lblPicError").style.display = null;
document.getElementById("lblPicError").innerHTML = label;
$("#contactNoPIC").closest(".form-group").addClass("has-danger");
nullContact = 1;
}
else{
document.getElementById("lblPicError").style.display = "none";
}
}
if(nullContact == 1){
return false;
}
}
$('.captchaError').remove();
if (grecaptcha.getResponse(captchaWidgetId) == "") {
$("#captcha").append('<label class="captchaError">Please verify that you are not a robot.</label>');
return false;
}
if($("form").valid())
{
if( formsubmit == 1 ){
return true;
}
else
{
swal({
title: "Are you sure you want to submit the form ?",
text: "",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Submit",
}).then(result => {
//swal("Deleted!", "Your file has been deleted.", "success");
//alert(result.value)
if (result.value == true ) {
//alert(result.value)
//alert("form submit");
formsubmit = 1;
$("form").submit();
} {
//swal("Cancelled", "Your imaginary file is safe :)", "error");
return false;
swal.closeModal();
}
swal.closeModal();
});
return false;
}
}
// sca start end
});
// Wizard Initialization
$('.card-wizard').bootstrapWizard({
'tabClass': 'nav nav-pills',
onInit: function(tab, navigation, index) {
//check number of tabs and fill the entire row
var $wizard = navigation.closest('.card-wizard');
$first_li = navigation.find('li:first-child a').html();
$moving_div = $('<div class="moving-tab">' + $first_li + '</div>');
$('.card-wizard .wizard-navigation').append($moving_div);
refreshAnimation($wizard, index);
$('.moving-tab').css('transition', 'transform 0s');
},
onTabShow: function(tab, navigation, index) {
var $total = navigation.find('li').length;
var $current = index + 1;
var $wizard = navigation.closest('.card-wizard');
// If it's the last tab then hide the last button and show the finish instead
if ($current >= $total) {
$($wizard).find('.btn-next').hide();
$($wizard).find('.btn-finish').show();
} else {
$($wizard).find('.btn-next').show();
$($wizard).find('.btn-finish').hide();
}
button_text = navigation.find('li:nth-child(' + $current + ') a').html();
setTimeout(function() {
$('.moving-tab').text(button_text);
}, 150);
refreshAnimation($wizard, index);
}
});
$('.set-full-height').css('height', 'auto');
$(window).resize(function() {
$('.card-wizard').each(function() {
$wizard = $(this);
index = $wizard.bootstrapWizard('currentIndex');
refreshAnimation($wizard, index);
$('.moving-tab').css({
'transition': 'transform 0s'
});
});
});
function refreshAnimation($wizard, index) {
$total = $wizard.find('.nav li').length;
$li_width = 100 / $total;
total_steps = $wizard.find('.nav li').length;
move_distance = $wizard.width() / total_steps;
index_temp = index;
vertical_level = 0;
mobile_device = $(document).width() < 600 && $total > 3;
if (mobile_device) {
move_distance = $wizard.width() / 2;
index_temp = index % 2;
$li_width = 50;
}
$wizard.find('.nav li').css('width', $li_width + '%');
step_width = move_distance;
move_distance = move_distance * index_temp;
$current = index + 1;
if ($current == 1 || (mobile_device == true && (index % 2 == 0))) {
move_distance -= 8;
} else if ($current == total_steps || (mobile_device == true && (index % 2 == 1))) {
move_distance += 8;
}
if (mobile_device) {
vertical_level = parseInt(index / 2);
vertical_level = vertical_level * 38;
}
$wizard.find('.moving-tab').css('width', step_width);
$('.moving-tab').css({
'transform': 'translate3d(' + move_distance + 'px, ' + vertical_level + 'px, 0)',
'transition': 'all 0.5s cubic-bezier(0.29, 1.42, 0.79, 1)'
});
}
function hidePic(e) {
var checkbox = e.target;
if (checkbox.checked) {
document.getElementById('picOwner').hidden = true;
$("#saPicOwnerFullName").removeAttr("required");
$("#saPicOwnerEmail").removeAttr("required");
$("#contactNoPIC").removeAttr("required");
} else {
$('#sameAsOwner').val("false");
document.getElementById('picOwner').hidden = false;
$("#saPicOwnerFullName").attr("required", "required");
$("#saPicOwnerEmail").attr("required", "required");
$("#contactNoPIC").attr("required", "required");
}
$("#contactNo").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
document.getElementById("lblAllZero").style.display = null;
$(this).closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblAllZero").style.display = "none";
}
});
$("#contactNoOwner").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
var label = "Invalid contact no format";
document.getElementById("lblOwnerError").style.display = null;
document.getElementById("lblOwnerError").innerHTML = label;
$(this).closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblOwnerError").style.display = "none";
}
});
$("#contactNoPIC").on('blur', function() {
var contact = $(this).val().substring(3);
if(checkAllZero(contact)){
var label = "Invalid contact no format";
document.getElementById("lblPicError").style.display = null;
document.getElementById("lblPicError").innerHTML = label;
$('this').closest(".form-group").addClass("has-danger");
}
else{
document.getElementById("lblPicError").style.display = "none";
}
});
$(".otp-new").otp({
callback: function() {
location.href = contextPath + "/login";
}
});
}
// Wizard Initialization
$('.card-wizard').bootstrapWizard({
'tabClass': 'nav nav-pills',
onInit: function(tab, navigation, index) {
//check number of tabs and fill the entire row
var $wizard = navigation.closest('.card-wizard');
$first_li = navigation.find('li:first-child a').html();
$moving_div = $('<div class="moving-tab">' + $first_li + '</div>');
$('.card-wizard .wizard-navigation').append($moving_div);
refreshAnimation($wizard, index);
$('.moving-tab').css('transition', 'transform 0s');
},
onTabShow: function(tab, navigation, index) {
var $total = navigation.find('li').length;
var $current = index + 1;
var $wizard = navigation.closest('.card-wizard');
// If it's the last tab then hide the last button and show the finish instead
if ($current >= $total) {
$($wizard).find('.btn-next').hide();
$($wizard).find('.btn-finish').show();
} else {
$($wizard).find('.btn-next').show();
$($wizard).find('.btn-finish').hide();
}
button_text = navigation.find('li:nth-child(' + $current + ') a').html();
setTimeout(function() {
$('.moving-tab').text(button_text);
}, 150);
refreshAnimation($wizard, index);
}
});
$('.set-full-height').css('height', 'auto');
$(window).resize(function() {
$('.card-wizard').each(function() {
$wizard = $(this);
index = $wizard.bootstrapWizard('currentIndex');
refreshAnimation($wizard, index);
$('.moving-tab').css({
'transition': 'transform 0s'
});
});
});
function refreshAnimation($wizard, index) {
$total = $wizard.find('.nav li').length;
$li_width = 100 / $total;
total_steps = $wizard.find('.nav li').length;
move_distance = $wizard.width() / total_steps;
index_temp = index;
vertical_level = 0;
mobile_device = $(document).width() < 600 && $total > 3;
if (mobile_device) {
move_distance = $wizard.width() / 2;
index_temp = index % 2;
$li_width = 50;
}
$wizard.find('.nav li').css('width', $li_width + '%');
step_width = move_distance;
move_distance = move_distance * index_temp;
$current = index + 1;
if ($current == 1 || (mobile_device == true && (index % 2 == 0))) {
move_distance -= 8;
} else if ($current == total_steps || (mobile_device == true && (index % 2 == 1))) {
move_distance += 8;
}
if (mobile_device) {
vertical_level = parseInt(index / 2);
vertical_level = vertical_level * 38;
}
$wizard.find('.moving-tab').css('width', step_width);
$('.moving-tab').css({
'transform': 'translate3d(' + move_distance + 'px, ' + vertical_level + 'px, 0)',
'transition': 'all 0.5s cubic-bezier(0.29, 1.42, 0.79, 1)'
});
}
function checkAllZero(contact){
if(contact.charAt(0) != 0){
return false;
}
else{
for (var i = 1; i < contact.length; i++){
if(contact.charAt(i) != contact.charAt(0)){
return false
}
}
return true;
}
}