feat: silent success scan, error beep on fail and duplicate
This commit is contained in:
@@ -247,6 +247,7 @@ function processSmartScan(barcode, confirm = false) {
|
||||
|
||||
// --- 1. HANDLE DUPLICATE CONFIRMATION ---
|
||||
if (data.needs_confirmation) {
|
||||
playErrorBeep();
|
||||
isSmartScan = true;
|
||||
currentDupKeyValue = barcode;
|
||||
if (data.duplicate_status === 'dup_same_session') {
|
||||
@@ -296,27 +297,23 @@ function processSmartScan(barcode, confirm = false) {
|
||||
}
|
||||
|
||||
// --- 3. STANDARD SUCCESS/FAIL ---
|
||||
if(smartInput) {
|
||||
smartInput.value = '';
|
||||
smartInput.focus();
|
||||
}
|
||||
feedbackArea.style.display = 'block';
|
||||
|
||||
if (data.success) {
|
||||
feedbackArea.style.background = 'rgba(40, 167, 69, 0.2)';
|
||||
feedbackArea.style.border = '1px solid #28a745';
|
||||
feedbackText.style.color = '#28a745';
|
||||
feedbackText.textContent = data.message;
|
||||
if (data.detail_id && data.data) {
|
||||
addScanToList(data.detail_id, data.data, data.data.duplicate_status);
|
||||
}
|
||||
setTimeout(() => feedbackArea.style.display = 'none', 1000);
|
||||
}
|
||||
else {
|
||||
feedbackArea.style.display = 'none';
|
||||
if(smartInput) {
|
||||
smartInput.value = '';
|
||||
smartInput.focus();
|
||||
}
|
||||
} else {
|
||||
playErrorBeep();
|
||||
feedbackArea.style.display = 'block';
|
||||
feedbackArea.style.background = 'rgba(220, 53, 69, 0.2)';
|
||||
feedbackArea.style.border = '1px solid #dc3545';
|
||||
feedbackText.style.color = '#dc3545';
|
||||
feedbackText.textContent = data.message;
|
||||
if(smartInput) smartInput.focus();
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -324,7 +321,7 @@ function processSmartScan(barcode, confirm = false) {
|
||||
console.error(err); // Log it, don't popup alert to annoy user
|
||||
});
|
||||
}
|
||||
// Function to handle the "Save" click from the Details Modal
|
||||
|
||||
// Function to handle the "Save" click from the Details Modal
|
||||
function saveSmartScanData() {
|
||||
// 1. Validate we have the original barcode
|
||||
@@ -380,6 +377,25 @@ function resetSmartScan() {
|
||||
document.getElementById('smartScanner').focus();
|
||||
document.getElementById('routerFeedback').style.display = 'none';
|
||||
}
|
||||
// --- ERROR BEEP ---
|
||||
function playErrorBeep() {
|
||||
try {
|
||||
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const oscillator = ctx.createOscillator();
|
||||
const gainNode = ctx.createGain();
|
||||
oscillator.connect(gainNode);
|
||||
gainNode.connect(ctx.destination);
|
||||
oscillator.type = 'square';
|
||||
oscillator.frequency.setValueAtTime(520, ctx.currentTime);
|
||||
gainNode.gain.setValueAtTime(0.3, ctx.currentTime);
|
||||
gainNode.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.4);
|
||||
oscillator.start(ctx.currentTime);
|
||||
oscillator.stop(ctx.currentTime + 0.4);
|
||||
} catch(e) {
|
||||
console.warn('Audio not available:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Standard variables
|
||||
let currentDupKeyValue = '';
|
||||
let currentDuplicateStatus = '';
|
||||
|
||||
Reference in New Issue
Block a user