From de0ef5dcaacd7d2ddaa3d257ac8d4042be6f5fca Mon Sep 17 00:00:00 2001 From: Tanuja Pansare Date: Fri, 30 Oct 2026 10:27:41 +0530 Subject: [PATCH] Form changes Horizon - Upload Daily Field Work Photo --- ...a8b3-d211-46ba-b867-69d4b85da68d.blade.php | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php index 67faea71..5f67524b 100644 --- a/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php +++ b/resources/views/form/rapport-horizon/1793272971-f2e4a8b3-d211-46ba-b867-69d4b85da68d.blade.php @@ -366,33 +366,47 @@ const photoInput = document.getElementById('field-upload_photo'); $('#start-photo-camera').on('click', async function () { - try { - if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { - throw new Error('Camera access is not supported by this browser.'); - } + try { + if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) { + throw new Error('Camera access requires HTTPS or localhost.'); + } - photoStream = await navigator.mediaDevices.getUserMedia({ - video: { facingMode: { ideal: 'environment' } }, - audio: false - }); + // This triggers the browser's native camera permission prompt + photoStream = await navigator.mediaDevices.getUserMedia({ + video: { facingMode: { ideal: 'environment' } }, + audio: false + }); - video.srcObject = photoStream; - video.style.display = 'block'; - preview.style.display = 'none'; + video.srcObject = photoStream; + video.style.display = 'block'; + preview.style.display = 'none'; - $('#start-photo-camera').hide(); - $('#capture-photo').show(); - $('#retake-photo').hide(); + $('#start-photo-camera').hide(); + $('#capture-photo').show(); + $('#retake-photo').hide(); - } catch (error) { - Swal.fire({ - icon: 'error', - title: 'Camera Unavailable', - text: 'Please allow camera access and try again.' - }); - } + } catch (error) { + console.error('Camera error:', error); + + if (error.name === 'NotAllowedError' || + error.name === 'PermissionDeniedError') { + + Swal.fire({ + icon: 'warning', + title: 'Camera Permission Required', + text: 'Please allow camera access in your browser settings and click Open Camera again.' }); + } else { + Swal.fire({ + icon: 'error', + title: 'Camera Unavailable', + text: 'Unable to access your camera. Please check your camera and try again.' + }); + } + } +}); + $('#capture-photo').on('click', function () { if (!photoStream || !video.videoWidth) { return;