Sep 15 - Update the check-in pages, employee id field limited to 4 digits/characters
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
let isSubmitting = false;
|
||||
let currentTime = new Date();
|
||||
|
||||
// Employee IDs are at most 4 digits. Keep in sync with the maxlength on
|
||||
// #employee_id, EMPLOYEE_ID_MAX_DIGITS in qr_destination.html and
|
||||
// CHECKIN_EMPLOYEE_ID_MAX_DIGITS in routes/qr_codes.py.
|
||||
const QR_EMPLOYEE_ID_MAX_DIGITS = 4;
|
||||
|
||||
// Camera verification variables
|
||||
let cameraStream = null;
|
||||
let capturedPhotoData = null;
|
||||
@@ -97,7 +102,8 @@ function loadLastStaffId() {
|
||||
try {
|
||||
const saved = localStorage.getItem("qr_last_staff_id");
|
||||
const digitsOnly = (saved || "").replace(/[^0-9]/g, "");
|
||||
if (digitsOnly.length >= 2) {
|
||||
// Longer stored IDs are not filled in: cutting them would be another employee
|
||||
if (digitsOnly.length >= 2 && digitsOnly.length <= QR_EMPLOYEE_ID_MAX_DIGITS) {
|
||||
return digitsOnly;
|
||||
}
|
||||
return null;
|
||||
@@ -135,9 +141,9 @@ function initializeForm() {
|
||||
// Add real-time Employee ID validation
|
||||
const employeeIdInput = document.getElementById("employee_id");
|
||||
if (employeeIdInput) {
|
||||
// Employee ID is numeric only — strip anything else as it is typed
|
||||
// Employee ID is numeric only, at most 4 digits — strip anything else as it is typed
|
||||
employeeIdInput.addEventListener("input", function () {
|
||||
const digitsOnly = this.value.replace(/[^0-9]/g, "");
|
||||
const digitsOnly = this.value.replace(/[^0-9]/g, "").slice(0, QR_EMPLOYEE_ID_MAX_DIGITS);
|
||||
if (this.value !== digitsOnly) {
|
||||
this.value = digitsOnly;
|
||||
}
|
||||
@@ -275,6 +281,15 @@ function proceedWithCheckin() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Refuse rather than truncate: a cut-down ID is a different employee
|
||||
if (employeeId.length > QR_EMPLOYEE_ID_MAX_DIGITS) {
|
||||
showCustomStatusMessage(
|
||||
"Employee ID must be 4 digits or fewer / El ID de empleado debe tener 4 dígitos o menos",
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the staff ID for future use
|
||||
saveLastStaffId(employeeId);
|
||||
|
||||
@@ -324,6 +339,16 @@ function submitCheckin() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (employeeId.length > QR_EMPLOYEE_ID_MAX_DIGITS) {
|
||||
showCustomStatusMessage(
|
||||
"Employee ID must be 4 digits or fewer / El ID de empleado debe tener 4 dígitos o menos",
|
||||
"error"
|
||||
);
|
||||
isSubmitting = false;
|
||||
updateSubmitButton(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const workTypeField = document.getElementById("work_type");
|
||||
const workType = workTypeField ? workTypeField.value.trim() : "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user