From 8bae897a51c6572732698518eb059be1cb77ea1c Mon Sep 17 00:00:00 2001 From: Nguyen Ngo Date: Fri, 8 Aug 2025 14:56:59 -0400 Subject: [PATCH] Update saving last staff id --- static/js/qr_destination.js | 68 +++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/static/js/qr_destination.js b/static/js/qr_destination.js index 045e1ce..435fc54 100644 --- a/static/js/qr_destination.js +++ b/static/js/qr_destination.js @@ -57,16 +57,11 @@ const translations = { document.addEventListener("DOMContentLoaded", function () { console.log("🎯 QR Destination page loaded"); - // Initialize language functionality + // CRITICAL: Initialize systems in correct order initializeLanguage(); - - // Initialize form handling + initializeStaffIdPersistence(); initializeForm(); - - // Initialize location services initializeLocation(); - - // Start real-time clock startClock(); // Add fade-in animation to elements @@ -77,6 +72,62 @@ document.addEventListener("DOMContentLoaded", function () { }, 100); }); +// ENHANCED STAFF ID PERSISTENCE FUNCTIONALITY +function initializeStaffIdPersistence() { + console.log("👤 Initializing staff ID persistence functionality"); + + // Load last staff ID from localStorage + lastStaffId = loadLastStaffId(); + if (lastStaffId) { + console.log(`📱 Found last staff ID: ${lastStaffId}`); + + // Automatically fill the last staff ID + const employeeIdInput = document.getElementById("employee_id"); + if (employeeIdInput) { + employeeIdInput.value = lastStaffId; + validateEmployeeId(); + console.log(`✅ Auto-filled staff ID: ${lastStaffId}`); + } + } else { + console.log("📱 No previous staff ID found"); + } +} + +function loadLastStaffId() { + try { + const saved = localStorage.getItem('qr_last_staff_id'); + if (saved && saved.trim().length >= 2) { + return saved.trim().toUpperCase(); + } + console.log("📱 No valid last staff ID found"); + return null; + } catch (error) { + console.error("❌ Error loading last staff ID from localStorage:", error); + return null; + } +} + +function saveLastStaffId(staffId) { + try { + if (!staffId || typeof staffId !== 'string' || staffId.trim().length < 2) { + console.log("⚠️ Invalid staff ID, not saving"); + return false; + } + + const cleanId = staffId.trim().toUpperCase(); + lastStaffId = cleanId; + + // Save to localStorage + localStorage.setItem('qr_last_staff_id', cleanId); + console.log(`💾 Last staff ID saved: ${cleanId}`); + + return true; + } catch (error) { + console.error("❌ Error saving last staff ID to localStorage:", error); + return false; + } +} + // ENHANCED FORM HANDLING FOR MULTIPLE CHECK-INS function initializeForm() { const form = document.getElementById("checkinForm"); @@ -123,6 +174,9 @@ function handleFormSubmit(event) { return; } + // Save the staff ID for future use + saveLastStaffId(employeeId); + // Show processing status showLocalizedStatusMessage("processing", "info");