Scan/OCR improvements: Scan New Asset button, barcode scanner fix, serial number OCR search

- Add 'Scan New Asset' button after scanning/OCR'ing an existing asset
  in both barcode and OCR modes (with resetBarcodeScanner/resetOcrScanner)
- Show scan results in-place instead of navigating away from Find Asset tab
- Fix barcode scanner: remove TRY_HARDER hint (too slow on mobile), reduce
  from 13 formats to 7 focused 1D formats, add ZXing library load check
- Extend camera fail timeout from 5s to 10s for slow mobile browsers
- Show matched_assets from OCR serial number cross-reference even when
  no machine_id pattern is detected (previously showed 'No machine ID')
- Display serial/ID DB matches alongside machine_id results when both exist
- Add null-safety to all new reset functions
This commit is contained in:
2026-06-02 18:05:24 -04:00
parent 1c63ec231f
commit dd4744df05
+34 -8
View File
@@ -2974,6 +2974,25 @@
}
}
function showFallbackCameraError(extraMsg) {
// Show just the manual search fallback without re-creating placeholder
const fallback = document.getElementById('manualSearchFallback');
if (fallback) {
fallback.style.display = 'block';
fallback.innerHTML = `
<div style="background:var(--red-bg);color:var(--red);padding:10px;border-radius:8px;margin-bottom:10px;font-size:13px;">
<strong>Camera unavailable</strong><br>
${extraMsg}
</div>
<div style="font-size:12px;color:var(--text2);margin-bottom:6px;">Enter ID manually:</div>
<input type="text" id="manualBarcodeInput" class="input-field" placeholder="Connect ID or barcode..." onkeypress="if(event.key==='Enter')handleManualBarcode()">
<button class="btn btn-primary btn-sm" onclick="handleManualBarcode()" style="margin-top:6px;width:100%;">Search</button>
<button class="btn btn-outline btn-sm" onclick="startScanning()" style="margin-top:6px;width:100%;">Try camera again</button>
`;
setTimeout(() => document.getElementById('manualBarcodeInput')?.focus(), 100);
}
}
function stopScanning() {
scanningActive = false;
if (codeReader) {
@@ -3085,9 +3104,10 @@
function resetBarcodeScanner() {
// Reset the scan result UI and restart barcode scanner
document.getElementById('scanResult').style.display = 'none';
document.getElementById('scanResult').innerHTML = '';
document.getElementById('checkinCard').style.display = 'none';
const sr = document.getElementById('scanResult');
if (sr) { sr.style.display = 'none'; sr.innerHTML = ''; }
const cc = document.getElementById('checkinCard');
if (cc) cc.style.display = 'none';
setScanStatus('Ready — scan another barcode', 'success');
stopScanning();
// Re-show the camera placeholder
@@ -3096,7 +3116,8 @@
ph.style.display = 'block';
ph.innerHTML = '<span class="cam-icon">' + gi('📷') + '</span><div class="cam-hint">Tap to start camera</div>';
}
document.getElementById('cameraVideo').style.display = 'none';
const cv = document.getElementById('cameraVideo');
if (cv) cv.style.display = 'none';
const fallback = document.getElementById('manualSearchFallback');
if (fallback) fallback.style.display = 'none';
scanningActive = false;
@@ -3108,10 +3129,12 @@
function resetOcrScanner() {
// Reset the OCR result UI and restart OCR camera
stopOcrCamera();
document.getElementById('ocrResult').style.display = 'none';
document.getElementById('ocrResult').innerHTML = '';
document.getElementById('ocrGpsBadge').style.display = 'none';
document.getElementById('ocrCameraArea').style.display = 'block';
const or = document.getElementById('ocrResult');
if (or) { or.style.display = 'none'; or.innerHTML = ''; }
const og = document.getElementById('ocrGpsBadge');
if (og) og.style.display = 'none';
const oca = document.getElementById('ocrCameraArea');
if (oca) oca.style.display = 'block';
setOcrStatus('Point camera at the machine sticker and tap capture', 'success');
const ph = document.getElementById('ocrPlaceholder');
if (ph) {
@@ -3161,6 +3184,9 @@
</div>
<div style="font-size:12px;color:var(--text3);margin-top:8px;">
Try OCR scanning the sticker, or search in the Assets tab.
</div>
<div style="margin-top:10px;">
<button class="btn btn-primary btn-sm" onclick="resetBarcodeScanner()" style="width:100%;">Scan New</button>
</div>`;
}