06/11 Update Inspection result will include GPS
This commit is contained in:
@@ -238,6 +238,8 @@
|
||||
<div class="insp-wrap mt-3">
|
||||
<form method="post" action="{{ url_for('inspections.execute', inspection_id=inspection.id) }}" enctype="multipart/form-data" id="inspectionForm" novalidate>
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="submit_lat" id="submitLat">
|
||||
<input type="hidden" name="submit_lng" id="submitLng">
|
||||
|
||||
{# ── Header ── #}
|
||||
<div class="insp-header">
|
||||
@@ -889,6 +891,23 @@ document.getElementById('inspectionForm').addEventListener('submit', async funct
|
||||
}
|
||||
}
|
||||
}
|
||||
// Capture GPS on final submit (not draft) — fire-and-forget with short timeout
|
||||
if (_submittingAction === 'submit' && navigator.geolocation) {
|
||||
await new Promise(resolve => {
|
||||
const timer = setTimeout(resolve, 4000); // give up after 4 s
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
pos => {
|
||||
document.getElementById('submitLat').value = pos.coords.latitude;
|
||||
document.getElementById('submitLng').value = pos.coords.longitude;
|
||||
clearTimeout(timer);
|
||||
resolve();
|
||||
},
|
||||
() => { clearTimeout(timer); resolve(); }, // permission denied / unavailable — proceed without
|
||||
{ timeout: 4000, maximumAge: 60000 }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Native form submit — browser handles multipart encoding and follows the redirect
|
||||
form.submit();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user