@@ -240,6 +283,8 @@ window.AbhaCreateModal = (function () {
var resendRemaining = 0;
var mobileResendTimer = null;
var mobileResendRemaining = 0;
+ var aadhaarResendCount = 0;
+ var mobileResendCount = 0;
function csrf() {
var input = document.querySelector('input[name="= csrf_token() ?>"]');
@@ -247,13 +292,51 @@ window.AbhaCreateModal = (function () {
}
function escapeHtml(value) { return $('
').text(value == null ? '' : String(value)).html(); }
function apiMessage(response, fallback) {
- var message = response && (response.error_text || response.message)
- ? escapeHtml(response.error_text || response.message)
+ var raw = response && (response.error_text || response.message)
+ ? String(response.error_text || response.message)
: fallback;
+ if (/loginId/i.test(raw) && /invalid/i.test(raw)) {
+ raw = 'Aadhaar Number is not valid. Valid 12-digit Aadhaar number is required.';
+ }
+ var message = escapeHtml(raw);
return response && response.request_id
? message + '
Bridge Request ID: ' + escapeHtml(response.request_id) + ' '
: message;
}
+ function validateVerhoeff(num) {
+ num = digits(num);
+ if (num.length !== 12 || num.charAt(0) === '0' || num.charAt(0) === '1') {
+ return false;
+ }
+ var d = [
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
+ [1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
+ [2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
+ [3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
+ [4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
+ [5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
+ [6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
+ [7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
+ [8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
+ [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
+ ];
+ var p = [
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
+ [1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
+ [5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
+ [8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
+ [9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
+ [4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
+ [2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
+ [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]
+ ];
+ var c = 0;
+ var inverted = num.split('').reverse();
+ for (var i = 0; i < inverted.length; i++) {
+ c = d[c][p[i % 8][parseInt(inverted[i], 10)]];
+ }
+ return (c === 0);
+ }
function alertBox(type, message) {
$('#abhaCreateAlert').html(message ? '
' + message + '
' : '');
}
@@ -272,14 +355,19 @@ window.AbhaCreateModal = (function () {
resendTimer = null;
mobileResendTimer = null;
}
- function startResendTimer(button, seconds, setter, getter) {
+ function startResendTimer(button, seconds) {
resendRemaining = Math.max(60, Number(seconds) || 60);
button.prop('disabled', true);
function tick() {
if (resendRemaining <= 0) {
window.clearInterval(resendTimer);
resendTimer = null;
- button.prop('disabled', false).text('Resend OTP');
+ if (aadhaarResendCount < 2) {
+ var remaining = 2 - aadhaarResendCount;
+ button.prop('disabled', false).text('Resend OTP (' + remaining + ' left)');
+ } else {
+ button.prop('disabled', true).text('Resend limit reached (max 2)');
+ }
return;
}
button.text('Resend OTP in ' + resendRemaining + 's');
@@ -296,7 +384,12 @@ window.AbhaCreateModal = (function () {
if (mobileResendRemaining <= 0) {
window.clearInterval(mobileResendTimer);
mobileResendTimer = null;
- button.prop('disabled', false).text('Resend OTP');
+ if (mobileResendCount < 2) {
+ var remaining = 2 - mobileResendCount;
+ button.prop('disabled', false).text('Resend OTP (' + remaining + ' left)');
+ } else {
+ button.prop('disabled', true).text('Resend limit reached (max 2)');
+ }
return;
}
button.text('Resend OTP in ' + mobileResendRemaining + 's');
@@ -333,27 +426,67 @@ window.AbhaCreateModal = (function () {
return merged;
}
- function sendAadhaarOtp() {
+ function sendAadhaarOtp(isResend) {
var aadhaar = digits($('#abhaCreateAadhaar').val());
var mobile = digits($('#abhaCreateMobile').val());
- if (aadhaar.length !== 12) { alertBox('warning', 'Enter a valid 12-digit Aadhaar number.'); return; }
- if (mobile.length !== 10) { alertBox('warning', 'Enter a valid 10-digit mobile number for ABHA communication.'); return; }
- if (!$('#abhaCreateConsent1').is(':checked')) { alertBox('warning', 'Aadhaar authentication consent is mandatory before sending the OTP.'); return; }
- if (!$('#abhaCreateConsent4').is(':checked')) { alertBox('warning', 'Confirm that the consent was explained to the patient.'); return; }
+ var totalConsent = $('.abha-consent-chk').length;
+ var checkedConsent = $('.abha-consent-chk:checked').length;
+ var isAllConsentChecked = (totalConsent > 0 && checkedConsent === totalConsent) || $('#abhaCreateConsentAgree').is(':checked');
+
+ // Reset visual validation states
+ $('#abhaCreateAadhaar').removeClass('is-invalid');
+ $('#abhaCreateMobile').removeClass('is-invalid');
+ $('#abhaCreateConsentWrap').removeClass('border-danger');
+ $('#abhaCreateConsentAgreeWrap').removeClass('border-danger');
+ $('#abhaCreateConsentError').addClass('d-none');
+
+ if (aadhaar.length !== 12 || !validateVerhoeff(aadhaar)) {
+ $('#abhaCreateAadhaar').addClass('is-invalid').trigger('focus');
+ alertBox('warning', 'Aadhaar Number is not valid. Valid 12-digit Aadhaar number is required.');
+ return;
+ }
+ if (mobile.length !== 10 || !/^[6-9]\d{9}$/.test(mobile)) {
+ $('#abhaCreateMobile').addClass('is-invalid').trigger('focus');
+ alertBox('warning', 'Please enter a valid 10-digit mobile number for ABHA communication.');
+ return;
+ }
+ if (!isAllConsentChecked) {
+ $('#abhaCreateConsentWrap').addClass('border-danger');
+ $('#abhaCreateConsentAgreeWrap').addClass('border-danger');
+ $('#abhaCreateConsentError').removeClass('d-none');
+ alertBox('warning', 'Consent is mandatory. Please review and check "I Agree" to all consent declarations before proceeding to the next step.');
+ $('#abhaCreateConsentAgree').trigger('focus');
+ return;
+ }
+
+ if (isResend === true) {
+ if (aadhaarResendCount >= 2) {
+ alertBox('warning', 'Maximum 2 resend attempts reached for Aadhaar OTP.');
+ return;
+ }
+ aadhaarResendCount++;
+ } else {
+ aadhaarResendCount = 0;
+ }
communicationMobile = mobile;
var button = $('#abhaCreateSendOtpBtn').prop('disabled', true).html('
Sending');
- $.post('= base_url('abha/create/initiate') ?>', { aadhaar: aadhaar, auth_type: 'aadhaar_otp', '= csrf_token() ?>': csrf() }, function (response) {
+ $.post('= base_url('abha/create/initiate') ?>', {
+ aadhaar: aadhaar,
+ auth_type: 'aadhaar_otp',
+ consent: 1,
+ '= csrf_token() ?>': csrf()
+ }, function (response) {
button.prop('disabled', false).html('
Send OTP');
- if (!response || response.ok != 1) { alertBox('danger', apiMessage(response, 'Unable to send Aadhaar OTP.')); return; }
+ if (!response || response.ok != 1) {
+ alertBox('danger', apiMessage(response, 'Unable to send Aadhaar OTP.'));
+ return;
+ }
createTxnId = response.txn_id || '';
$('#abhaCreateOtp').val('');
- var destination = response.masked_mobile || ((response.message || '').match(/\*{2,}\d{4}/) || [''])[0];
- var bridgeMessage = String(response.message || '').trim();
- if (!bridgeMessage) {
- bridgeMessage = 'OTP sent to the Aadhaar registered mobile number' + (destination ? ' ending with ' + destination : '') + '.';
- }
- $('#abhaCreateOtpHint').text(bridgeMessage);
+ var destination = response.masked_mobile || ((response.message || '').match(/\*{2,}\d{4}/) || [''])[0] || '******XXXX';
+ var promptMessage = 'We just sent an OTP on the Mobile Number ' + destination + ' linked with Aadhaar. Enter the OTP below to proceed with ABHA creation.';
+ $('#abhaCreateOtpHint').text(promptMessage);
$('#abhaCreateOtpRequestId')
.toggleClass('d-none', !response.request_id)
.text(response.request_id ? 'Bridge Request ID: ' + response.request_id : '');
@@ -368,10 +501,13 @@ window.AbhaCreateModal = (function () {
function verifyAadhaarOtp() {
var otp = digits($('#abhaCreateOtp').val());
- if (otp.length !== 6) { alertBox('warning', 'Enter the 6-digit OTP.'); return; }
+ if (otp.length !== 6) {
+ alertBox('warning', 'Enter the 6-digit OTP.');
+ return;
+ }
var button = $('#abhaCreateVerifyOtpBtn').prop('disabled', true).html('
Verifying');
$.post('= base_url('abha/create/verify_otp') ?>', { txn_id: createTxnId, otp: otp, mobile: communicationMobile, '= csrf_token() ?>': csrf() }, function (response) {
- button.prop('disabled', false).html('
Verify & Create ABHA');
+ button.prop('disabled', false).html('
Verify & Proceed');
if (!response || response.ok != 1) {
alertBox('danger', apiMessage(response, 'Invalid OTP - Please enter a valid OTP. Entered OTP is either expired or incorrect.'));
return;
@@ -379,80 +515,166 @@ window.AbhaCreateModal = (function () {
stopTimers();
createdProfile = response;
createTxnId = response.txn_id || createTxnId;
- // ABDM already created this ABHA with the alternate mobile; requesting another
- // mobile OTP here would return whichever ABHA owns that number (e.g. the parent).
- var alreadyCreated = response.abha_created == 1 || digits(response.abha_number).length === 14;
- if (!alreadyCreated && communicationMobile && digits(response.mobile).slice(-10) !== communicationMobile) {
- requestMobileOtp();
+
+ // Case 1: ABHA Already Exists (VRFY_ABHA_404 & User Step 9-10)
+ if (response.already_exists) {
+ renderProfile(response);
+ alertBox('success', '
ABHA Already Exist: An active ABHA account is registered with this Aadhaar Number.');
return;
}
- renderProfile(response);
- if (alreadyCreated) {
- reportCommunicationMobileStatus(response);
+
+ // Case 2: New ABHA (CRT_ABHA_101 & User Steps 4-8)
+ // Check communication mobile vs Aadhaar-linked mobile
+ if (response.is_comm_mobile_same) {
+ // CRT_ABHA_108: Mobile already verified by Aadhaar OTP -> Skip mobile OTP, go straight to ABHA address
+ loadAddressSuggestions();
+ alertBox('info', '
NO ABHA user registered with this Aadhaar Number. Communication mobile matches Aadhaar-linked mobile. Please choose your ABHA address.');
+ return;
+ } else {
+ // CRT_ABHA_109: Different mobile -> Verify communication mobile OTP
+ requestMobileOtp(false);
+ return;
}
}, 'json').fail(function (xhr) {
- button.prop('disabled', false).html('
Verify & Create ABHA');
+ button.prop('disabled', false).html('
Verify & Proceed');
alertBox('danger', apiMessage(xhr.responseJSON, 'OTP verification failed.'));
});
}
- // Explains the alternate-mobile outcome so the operator is never left guessing whether it was attached.
- function reportCommunicationMobileStatus(response) {
- var abhaText = formatAbha(response.abha_number) || 'the ABHA';
- var created = 'ABHA
' + escapeHtml(abhaText) + ' created successfully by ABDM during Aadhaar OTP verification.';
- if (!communicationMobile) {
- alertBox('success', created);
- return;
+ function requestMobileOtp(isResend) {
+ if (isResend === true) {
+ if (mobileResendCount >= 2) {
+ alertBox('warning', 'Maximum 2 resend attempts reached for Mobile OTP.');
+ return;
+ }
+ mobileResendCount++;
+ } else {
+ mobileResendCount = 0;
}
- var maskedComm = escapeHtml(maskMobile(communicationMobile));
- if (response.mobile_source === 'abdm' && digits(response.mobile).slice(-10) === communicationMobile) {
- alertBox('success', created + '
ABDM confirmed mobile
' + maskedComm + ' as the ABHA communication number. It will be saved on the patient record. No separate mobile OTP is needed.');
- return;
- }
- if (response.mobile_source === 'enrolment') {
- alertBox('success', created + '
Alternate mobile
' + maskedComm + ' was submitted with the Aadhaar verification that created this ABHA and will be saved on the patient record. ABDM did not echo it back in the response, so confirm it in the ABHA app if the beneficiary reports missing notifications.'
- + '
HMS does not send a second mobile OTP: that check returns whichever ABHA already owns this number (for example a parent\'s ABHA) and would overwrite this record.');
- return;
- }
- alertBox('warning', created + '
The alternate mobile
' + maskedComm + ' could not be attached, and ABDM returned
' + (escapeHtml(maskMobile(response.mobile)) || 'no number') + ' instead. Attach or change the number from the ABHA app/portal.');
- }
- function requestMobileOtp() {
- alertBox('info', 'Aadhaar verified. Requesting OTP for the alternate communication mobile...');
+ alertBox('info', 'Aadhaar verified. Requesting OTP for communication mobile...');
$.post('= base_url('abha/create/communication') ?>', { mobile: communicationMobile, txn_id: createTxnId, '= csrf_token() ?>': csrf() }, function (response) {
if (!response || response.ok != 1) {
- renderProfile(createdProfile || {});
- alertBox('warning', 'Aadhaar verification succeeded, but the alternate mobile OTP could not be sent: ' + apiMessage(response, 'Unable to send mobile OTP.'));
+ // Fallback to address creation if communication OTP cannot be dispatched
+ loadAddressSuggestions();
+ alertBox('warning', 'Aadhaar verified, but alternate mobile OTP could not be sent: ' + apiMessage(response, 'Unable to send mobile OTP.') + ' Proceeding with Aadhaar mobile.');
return;
}
mobileTxnId = response.txn_id || createTxnId;
- $('#abhaCreateMobileHint').text(response.message || ('OTP sent to ' + maskMobile(communicationMobile) + '.'));
+ var masked = maskMobile(communicationMobile);
+ $('#abhaCreateMobileHint').html('We just sent a separate verification OTP to your Communication Mobile Number
' + escapeHtml(masked) + ' . Enter the OTP below to proceed.');
$('#abhaCreateMobileOtp').val('');
showStep(3);
startMobileResendTimer($('#abhaCreateMobileResendBtn'));
$('#abhaCreateMobileOtp').trigger('focus');
}, 'json').fail(function (xhr) {
- renderProfile(createdProfile || {});
- alertBox('warning', 'Aadhaar verification succeeded, but the alternate mobile OTP could not be sent: ' + apiMessage(xhr.responseJSON, 'Unable to send mobile OTP.'));
+ loadAddressSuggestions();
+ alertBox('warning', 'Aadhaar verified, but alternate mobile OTP could not be sent: ' + apiMessage(xhr.responseJSON, 'Unable to send mobile OTP.') + ' Proceeding with Aadhaar mobile.');
});
}
function verifyMobileOtp() {
var otp = digits($('#abhaCreateMobileOtp').val());
- if (otp.length !== 6) { alertBox('warning', 'Enter the 6-digit mobile OTP.'); return; }
+ if (otp.length !== 6) {
+ alertBox('warning', 'Enter the 6-digit mobile OTP.');
+ return;
+ }
var button = $('#abhaCreateVerifyMobileBtn').prop('disabled', true).html('
Verifying');
$.post('= base_url('abha/create/verify_comm_otp') ?>', { txn_id: mobileTxnId, otp: otp, mobile: communicationMobile, '= csrf_token() ?>': csrf() }, function (response) {
- button.prop('disabled', false).html('
Verify & Update Mobile');
- if (!response || response.ok != 1) { alertBox('danger', apiMessage(response, 'Mobile OTP verification failed.')); return; }
+ button.prop('disabled', false).html('
Verify & Proceed');
+ if (!response || response.ok != 1) {
+ alertBox('danger', apiMessage(response, 'Mobile OTP verification failed.'));
+ return;
+ }
stopTimers();
createdProfile = mergeProfile(createdProfile, response);
- renderProfile(createdProfile);
+ loadAddressSuggestions();
+ alertBox('success', '
Communication mobile verified successfully! Now choose your ABHA address.');
}, 'json').fail(function (xhr) {
- button.prop('disabled', false).html('
Verify & Update Mobile');
+ button.prop('disabled', false).html('
Verify & Proceed');
alertBox('danger', apiMessage(xhr.responseJSON, 'Mobile OTP verification failed.'));
});
}
+ function loadAddressSuggestions() {
+ showStep(4);
+ $('#abhaCreateAddressAlert').empty();
+ $('#abhaCreateAddressList').html('
Loading address suggestions…
');
+ $('#abhaCreateCustomWrap').addClass('d-none');
+ $('#abhaCreateCustomAddress').val('');
+
+ $.post('= base_url('abha/create/address_suggestions') ?>', { txn_id: createTxnId, '= csrf_token() ?>': csrf() }, function (response) {
+ if (!response || response.ok != 1 || !(response.suggestions || []).length) {
+ $('#abhaCreateAddressList').html('
' + apiMessage(response, 'No suggested ABHA addresses are available from the bridge.') + ' Please enter a custom address below.
');
+ $('#abhaCreateCustomWrap').removeClass('d-none');
+ return;
+ }
+ var html = '';
+ (response.suggestions || []).forEach(function (address, index) {
+ html += '
'
+ + ' '
+ + escapeHtml(address)
+ + ' ';
+ });
+ $('#abhaCreateAddressList').html(html);
+ }, 'json').fail(function (xhr) {
+ $('#abhaCreateAddressList').html('
' + apiMessage(xhr.responseJSON, 'Unable to load address suggestions.') + ' Please enter a custom address below.
');
+ $('#abhaCreateCustomWrap').removeClass('d-none');
+ });
+ }
+
+ function confirmAddress() {
+ var custom = $.trim($('#abhaCreateCustomAddress').val());
+ var selected = $('input[name="abhaCreateAddressPick"]:checked').val() || '';
+ var address = $('#abhaCreateCustomWrap').hasClass('d-none') ? selected : (custom || selected);
+ if (!address) {
+ $('#abhaCreateAddressAlert').html('
Select a suggested address or enter a custom one.
');
+ return;
+ }
+
+ var handle = address.split('@')[0];
+ // Enforce CRT_ABHA_112 validation rules
+ if (handle.length < 8 || handle.length > 18) {
+ $('#abhaCreateAddressAlert').html('
ABHA address must be between 8 and 18 characters.
');
+ return;
+ }
+ if (/^[._]|[._]$/.test(handle)) {
+ $('#abhaCreateAddressAlert').html('
Special character dot (.) and underscore (_) can only be in between, not at the beginning or end.
');
+ return;
+ }
+ var dots = (handle.match(/\./g) || []).length;
+ var underscores = (handle.match(/_/g) || []).length;
+ if (dots > 1 || underscores > 1 || !/^[a-zA-Z0-9._]+$/.test(handle)) {
+ $('#abhaCreateAddressAlert').html('
Only letters, numbers, at most 1 dot (.) and/or 1 underscore (_) are allowed.
');
+ return;
+ }
+
+ var button = $('#abhaCreateConfirmAddressBtn').prop('disabled', true).html('
Creating ABHA…');
+ $.post('= base_url('abha/create/address') ?>', { txn_id: createTxnId, abha_address: address, '= csrf_token() ?>': csrf() }, function (response) {
+ button.prop('disabled', false).html('
Confirm Address & Create ABHA');
+ if (!response || response.ok != 1) {
+ var err = apiMessage(response, 'Unable to set the ABHA address.');
+ if (/already exist|already in use|taken/i.test(err)) {
+ err = 'ABHA Address is already exist';
+ }
+ $('#abhaCreateAddressAlert').html('
' + err + '
');
+ return;
+ }
+ if (createdProfile) {
+ createdProfile.abha_address = response.abha_address || address;
+ }
+ renderProfile(createdProfile || {});
+ alertBox('success', '
ABHA Created Successfully! ABHA address set to
' + escapeHtml(response.abha_address || address) + ' .');
+ }, 'json').fail(function (xhr) {
+ button.prop('disabled', false).html('
Confirm Address & Create ABHA');
+ var err = apiMessage(xhr.responseJSON, 'Unable to set the ABHA address.');
+ if (/already exist|already in use|taken/i.test(err)) {
+ err = 'ABHA Address is already exist';
+ }
+ $('#abhaCreateAddressAlert').html('
' + err + '
');
+ });
+ }
+
function renderProfile(profile) {
createdProfile = profile;
$('#abhaCreateProfileName').text(profile.name || '-');
@@ -466,7 +688,7 @@ window.AbhaCreateModal = (function () {
? maskMobile(profile.mobile) + (profile.mobile_source === 'enrolment' ? ' (submitted at enrolment)' : '')
: '-');
$('#abhaCreateProfileFullAddress').text([profile.address, profile.district, profile.state, profile.zip].filter(Boolean).join(', ') || '-');
- $('#abhaCreateStatusText').text(profile.abha_number ? 'ABHA Ready' : 'ABHA Verified');
+ $('#abhaCreateStatusText').text(profile.abha_number ? (profile.already_exists ? 'ABHA Active' : 'ABHA Ready') : 'ABHA Verified');
var photo = photoSrc(profile.photo);
$('#abhaCreatePhoto').toggleClass('d-none', !photo).attr('src', photo || '');
@@ -477,62 +699,19 @@ window.AbhaCreateModal = (function () {
var isOfficial = profile.card_source !== 'generated';
var note = isOfficial
? ''
- : '
Provisional card generated by the Bridge, not the official ABDM card.
';
+ : '
Provisional card generated by Bridge.
';
$('#abhaCreateCardWrap').html('
' + note);
$('#abhaCreateDownloadCard').attr('href', cardSrc).removeClass('d-none');
} else {
- var reason = profile.card_message ? escapeHtml(profile.card_message) : 'ABDM did not issue an official ABHA card for this session.';
+ var reason = profile.card_message ? escapeHtml(profile.card_message) : 'Official ABHA card was not returned by the Bridge.';
$('#abhaCreateCardWrap').html('
' + reason + '
');
$('#abhaCreateDownloadCard').addClass('d-none');
}
- showStep(4);
- }
-
- function loadAddressSuggestions() {
showStep(5);
- $('#abhaCreateAddressAlert').empty();
- $('#abhaCreateAddressList').html('
Loading suggestions…
');
- $('#abhaCreateCustomWrap').addClass('d-none');
- $('#abhaCreateCustomAddress').val('');
-
- $.post('= base_url('abha/create/address_suggestions') ?>', { txn_id: createTxnId, '= csrf_token() ?>': csrf() }, function (response) {
- if (!response || response.ok != 1 || !(response.suggestions || []).length) {
- $('#abhaCreateAddressList').empty();
- $('#abhaCreateCustomWrap').removeClass('d-none');
- $('#abhaCreateAddressAlert').html('
' + apiMessage(response, 'No ABHA address suggestions are available.') + ' You can type a custom address below.
');
- return;
- }
- var html = '';
- (response.suggestions || []).forEach(function (address, index) {
- html += '
' + escapeHtml(address) + '';
- });
- $('#abhaCreateAddressList').html(html);
- }, 'json').fail(function (xhr) {
- $('#abhaCreateAddressList').empty();
- $('#abhaCreateCustomWrap').removeClass('d-none');
- $('#abhaCreateAddressAlert').html('
' + apiMessage(xhr.responseJSON, 'Unable to load ABHA address suggestions.') + ' You can type a custom address below.
');
- });
- }
-
- function confirmAddress() {
- var custom = $.trim($('#abhaCreateCustomAddress').val());
- var selected = $('input[name="abhaCreateAddressPick"]:checked').val() || '';
- var address = $('#abhaCreateCustomWrap').hasClass('d-none') ? selected : (custom || selected);
- if (!address) { $('#abhaCreateAddressAlert').html('
Select a suggested address or enter a custom one.
'); return; }
-
- var button = $('#abhaCreateConfirmAddressBtn').prop('disabled', true).html('
Saving');
- $.post('= base_url('abha/create/address') ?>', { txn_id: createTxnId, abha_address: address, '= csrf_token() ?>': csrf() }, function (response) {
- button.prop('disabled', false).html('
Confirm Address & Create ABHA');
- if (!response || response.ok != 1) {
- $('#abhaCreateAddressAlert').html('
' + apiMessage(response, 'Unable to set the ABHA address.') + '
');
- return;
- }
- createdProfile.abha_address = response.abha_address || address;
- renderProfile(createdProfile);
- alertBox('success', 'ABHA address updated to
' + escapeHtml(createdProfile.abha_address) + ' .');
- }, 'json').fail(function (xhr) {
- button.prop('disabled', false).html('
Confirm Address & Create ABHA');
- $('#abhaCreateAddressAlert').html('
' + apiMessage(xhr.responseJSON, 'Unable to set the ABHA address.') + '
');
+ // Mark previous steps as done
+ $('.abha-create-step').each(function () {
+ var itemStep = Number($(this).data('step'));
+ $(this).toggleClass('active', itemStep === 5).toggleClass('done', itemStep < 5);
});
}
@@ -545,38 +724,97 @@ window.AbhaCreateModal = (function () {
field.attr('type', isHidden ? 'text' : 'password');
$(this).find('i').attr('class', isHidden ? 'bi bi-eye-slash' : 'bi bi-eye');
});
- $('#abhaCreateSendOtpBtn').on('click', sendAadhaarOtp);
- $('#abhaCreateResendBtn').on('click', sendAadhaarOtp);
+
+ function clearConsentValidation() {
+ $('#abhaCreateConsentWrap').removeClass('border-danger');
+ $('#abhaCreateConsentAgreeWrap').removeClass('border-danger');
+ $('#abhaCreateConsentError').addClass('d-none');
+ if ($('#abhaCreateAlert').text().indexOf('Consent is mandatory') !== -1) {
+ alertBox('', '');
+ }
+ }
+
+ $('#abhaCreateConsentAgree').on('change', function () {
+ var checked = $(this).is(':checked');
+ $('.abha-consent-chk').prop('checked', checked);
+ $('#abhaCreateSelectAllConsent').text(checked ? 'Deselect All' : 'Select All');
+ if (checked) {
+ clearConsentValidation();
+ }
+ });
+
+ $('.abha-consent-chk').on('change', function () {
+ var total = $('.abha-consent-chk').length;
+ var checked = $('.abha-consent-chk:checked').length;
+ var allChecked = (total > 0 && checked === total);
+ $('#abhaCreateConsentAgree').prop('checked', allChecked);
+ $('#abhaCreateSelectAllConsent').text(allChecked ? 'Deselect All' : 'Select All');
+ if (allChecked) {
+ clearConsentValidation();
+ }
+ });
+
+ $('#abhaCreateSelectAllConsent').on('click', function () {
+ var total = $('.abha-consent-chk').length;
+ var checked = $('.abha-consent-chk:checked').length;
+ var shouldCheck = (checked < total);
+ $('.abha-consent-chk').prop('checked', shouldCheck);
+ $('#abhaCreateConsentAgree').prop('checked', shouldCheck);
+ $(this).text(shouldCheck ? 'Deselect All' : 'Select All');
+ if (shouldCheck) {
+ clearConsentValidation();
+ }
+ });
+
+ $('#abhaCreateAadhaar').on('input', function () {
+ $(this).removeClass('is-invalid');
+ if ($('#abhaCreateAlert').text().indexOf('Aadhaar Number is not valid') !== -1) {
+ alertBox('', '');
+ }
+ });
+
+ $('#abhaCreateMobile').on('input', function () {
+ $(this).removeClass('is-invalid');
+ if ($('#abhaCreateAlert').text().indexOf('mobile number') !== -1) {
+ alertBox('', '');
+ }
+ });
+
+ $('#abhaCreateSendOtpBtn').on('click', function () { sendAadhaarOtp(false); });
+ $('#abhaCreateResendBtn').on('click', function () { sendAadhaarOtp(true); });
$('#abhaCreateChangeAadhaarBtn').on('click', function () { stopTimers(); showStep(1); });
$('#abhaCreateVerifyOtpBtn').on('click', verifyAadhaarOtp);
$('#abhaCreateOtp').on('keydown', function (event) { if (event.key === 'Enter') { event.preventDefault(); verifyAadhaarOtp(); } });
+
$('#abhaCreateVerifyMobileBtn').on('click', verifyMobileOtp);
- $('#abhaCreateMobileResendBtn').on('click', requestMobileOtp);
- $('#abhaCreateSkipMobileBtn').on('click', function () { stopTimers(); renderProfile(createdProfile || {}); });
- $('#abhaCreateChangeMobileBtn').on('click', function () {
+ $('#abhaCreateMobileResendBtn').on('click', function () { requestMobileOtp(true); });
+ $('#abhaCreateSkipMobileBtn').on('click', function () {
stopTimers();
- showStep(1);
- alertBox('warning', 'Enter the mobile number already linked with this Aadhaar, then request a new Aadhaar OTP.');
- $('#abhaCreateMobile').trigger('focus');
+ loadAddressSuggestions();
+ alertBox('info', 'Proceeding with Aadhaar-linked mobile for ABHA.');
});
+ $('#abhaCreateMobileOtp').on('keydown', function (event) { if (event.key === 'Enter') { event.preventDefault(); verifyMobileOtp(); } });
+
$('#abhaCreateChooseAddressBtn').on('click', loadAddressSuggestions);
- $('#abhaCreateAddressBackBtn').on('click', function () { showStep(4); });
+ $('#abhaCreateAddressBackBtn').on('click', function () {
+ if (createdProfile && createdProfile.already_exists) {
+ showStep(5);
+ } else {
+ showStep(2);
+ }
+ });
$('#abhaCreateCustomToggle').on('click', function () {
$('#abhaCreateCustomWrap').toggleClass('d-none');
- if (!$('#abhaCreateCustomWrap').hasClass('d-none')) $('#abhaCreateCustomAddress').trigger('focus');
+ if (!$('#abhaCreateCustomWrap').hasClass('d-none')) {
+ $('#abhaCreateCustomAddress').trigger('focus');
+ }
});
$('#abhaCreateConfirmAddressBtn').on('click', confirmAddress);
+ $('#abhaCreateCustomAddress').on('keydown', function (event) { if (event.key === 'Enter') { event.preventDefault(); confirmAddress(); } });
$('#abhaCreateRegisterBtn').on('click', function () {
if (!createdProfile) return;
var profile = createdProfile;
- if (profile.need_confirmation === false && Number(profile.patient_id || 0) > 0) {
- $('#abhaCreateModal').one('hidden.bs.modal', function () {
- if (typeof onCompleted === 'function') onCompleted(profile);
- });
- modal.hide();
- return;
- }
$('#abhaCreateModal').one('hidden.bs.modal', function () {
if (typeof onCompleted === 'function') onCompleted(profile);
});
@@ -593,11 +831,16 @@ window.AbhaCreateModal = (function () {
mobileTxnId = '';
communicationMobile = '';
createdProfile = null;
+ aadhaarResendCount = 0;
+ mobileResendCount = 0;
stopTimers();
- $('#abhaCreateAadhaar,#abhaCreateMobile,#abhaCreateOtp,#abhaCreateMobileOtp,#abhaCreateCustomAddress').val('');
+ $('#abhaCreateAadhaar,#abhaCreateMobile,#abhaCreateOtp,#abhaCreateMobileOtp,#abhaCreateCustomAddress').val('').removeClass('is-invalid');
$('#abhaCreateMobile').val(digits(prefillMobile));
$('#abhaCreateOtpRequestId').addClass('d-none').text('');
- $('#abhaCreateConsent1,#abhaCreateConsent2,#abhaCreateConsent3,#abhaCreateConsent4').prop('checked', false);
+ $('#abhaCreateConsent1,#abhaCreateConsent2,#abhaCreateConsent3,#abhaCreateConsent4,#abhaCreateConsentAgree').prop('checked', false);
+ $('#abhaCreateConsentWrap,#abhaCreateConsentAgreeWrap').removeClass('border-danger');
+ $('#abhaCreateConsentError').addClass('d-none');
+ $('#abhaCreateSelectAllConsent').text('Select All');
$('#abhaCreatePhoto,#abhaCreateDownloadCard').addClass('d-none');
showStep(1);
modal.show();