diff --git a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php index 47d90dec..e549a444 100644 --- a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php +++ b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php @@ -468,6 +468,13 @@ max-width: 220px; height: auto; } + + #tgics-validate-wa-modal { + z-index: 1055; + } + .tgics-validate-backdrop { + z-index: 1050; + } @include('layouts.shared/footer-script') @@ -825,6 +832,40 @@ } } + function hideTgicsValidateModal() { + stopTgicsWaPoll(); + var $modal = $('#tgics-validate-wa-modal'); + if ($.fn.modal && typeof $modal.modal === 'function') { + $modal.modal('hide'); + } else if (window.bootstrap && bootstrap.Modal) { + var inst = bootstrap.Modal.getInstance($modal[0]); + if (inst) { + inst.hide(); + } + } + $modal.removeClass('show').css('display', 'none').attr('aria-hidden', 'true'); + $('.tgics-validate-backdrop').remove(); + $('body').removeClass('modal-open').css('overflow', ''); + } + + function showTgicsValidateModal() { + var $modal = $('#tgics-validate-wa-modal'); + if ($.fn.modal && typeof $modal.modal === 'function') { + $modal.modal('show'); + return; + } + if (window.bootstrap && bootstrap.Modal) { + bootstrap.Modal.getOrCreateInstance($modal[0]).show(); + return; + } + // Manual fallback when Bootstrap modal JS is unavailable + $modal.addClass('show').css('display', 'block').attr('aria-hidden', 'false'); + if (!$('.tgics-validate-backdrop').length) { + $('body').append('
'); + } + $('body').addClass('modal-open'); + } + function startTgicsWaPoll(contactId) { stopTgicsWaPoll(); tgicsWaPollStartedAt = Date.now(); @@ -862,40 +903,57 @@ }, 3000); } - $(document).on('click', '.tgics-validate-wa-btn', function() { + $(document).on('click', '.tgics-validate-wa-btn', function(e) { + e.preventDefault(); + e.stopPropagation(); var contactId = $(this).attr('data-contact-id') || ''; var validateUrl = $(this).attr('data-validate-url') || ''; var doctorName = $(this).attr('data-doctor-name') || 'Doctor'; if (!contactId || !validateUrl) { + Swal.fire({ + icon: 'error', + title: 'Validation unavailable', + text: 'Missing doctor contact link. Please re-enrol or contact support.' + }); return; } $('#tgics-validate-wa-doctor').text(doctorName); $('#tgics-validate-wa-open').attr('href', validateUrl); $('#tgics-validate-wa-qr').empty(); - if (typeof QRCode !== 'undefined') { - new QRCode(document.getElementById('tgics-validate-wa-qr'), { - text: validateUrl, - width: 200, - height: 200 - }); - } else { - $('#tgics-validate-wa-qr').html('Unable to render QR. Use Open link instead.
'); + try { + if (typeof QRCode !== 'undefined') { + new QRCode(document.getElementById('tgics-validate-wa-qr'), { + text: validateUrl, + width: 200, + height: 200 + }); + } else { + $('#tgics-validate-wa-qr').html( + 'QR library unavailable. Use the button below.
' + ); + } + } catch (qrErr) { + console.error(qrErr); + $('#tgics-validate-wa-qr').html( + 'Unable to render QR. Use the button below.
' + ); } - var $modal = $('#tgics-validate-wa-modal'); - if (typeof bootstrap !== 'undefined' && bootstrap.Modal) { - bootstrap.Modal.getOrCreateInstance($modal[0]).show(); - } else if ($modal.modal) { - $modal.modal('show'); - } else { - $modal.show(); - } + showTgicsValidateModal(); startTgicsWaPoll(contactId); }); + $(document).on('click', '#tgics-validate-wa-modal [data-bs-dismiss="modal"], #tgics-validate-wa-modal .btn-close, #tgics-validate-wa-modal .btn-secondary', function() { + hideTgicsValidateModal(); + }); + $(document).on('click', '.tgics-validate-backdrop', function() { + hideTgicsValidateModal(); + }); + $('#tgics-validate-wa-modal').on('hidden.bs.modal hide.bs.modal', function() { stopTgicsWaPoll(); + $('.tgics-validate-backdrop').remove(); }); $('#execution-form').on('submit', function(event) { @@ -944,28 +1002,27 @@ today = yyyy + '-' + mm + '-' + dd; var recordDateField = document.getElementById('field-plan_date'); - recordDateField.setAttribute('min', today); + if (recordDateField) { + recordDateField.setAttribute('min', today); + } var executionDateField = document.getElementById('execution-plan_date'); - //executionDateField.setAttribute('min', today); - - // $('.edit-btn').click(function() { - // var executionexeField = document.getElementById('execution-record_date'); - // executionexeField.setAttribute('min', executionDateField.value); - // }); $('.edit-btn').click(function() { var executionexeField = document.getElementById('execution-execution_date'); - executionexeField.setAttribute('min', executionDateField.value); + if (executionexeField && executionDateField && executionDateField.value) { + executionexeField.setAttribute('min', executionDateField.value); + } }); - - - executionDateField.addEventListener('change', function() { - console.log('gg'); - var executionexeField = document.getElementById('execution-record_date'); - executionexeField.setAttribute('min', executionDateField.value); - }); + if (executionDateField) { + executionDateField.addEventListener('change', function() { + var executionexeField = document.getElementById('execution-record_date'); + if (executionexeField) { + executionexeField.setAttribute('min', executionDateField.value); + } + }); + } });