-
-
-
-
+
@@ -608,6 +681,7 @@
const API_BASE = window.location.origin + '/api/v1';
const STORAGE_RECENT_REGS_KEY = 'bookingPage_recentRegs';
const STORAGE_AIRCRAFT_TYPES_KEY = 'bookingPage_aircraftTypes';
+ const STORAGE_CALLSIGNS_KEY = 'bookingPage_callsigns';
const MAX_RECENT = 5;
// ==================== localStorage Management ====================
@@ -690,6 +764,43 @@
}
}
+ function cacheCallsign(registration, callsign) {
+ try {
+ if (!registration || !callsign || callsign.trim() === '') {
+ return;
+ }
+
+ const reg = registration.toUpperCase().trim();
+ const cs = callsign.toUpperCase().trim();
+ const stored = localStorage.getItem(STORAGE_CALLSIGNS_KEY);
+ let callsigns = stored ? JSON.parse(stored) : {};
+
+ callsigns[reg] = cs;
+ localStorage.setItem(STORAGE_CALLSIGNS_KEY, JSON.stringify(callsigns));
+ console.log('â
Cached callsign:', reg, '=', cs);
+ } catch (e) {
+ console.error('Error caching callsign:', e);
+ }
+ }
+
+ function getCachedCallsign(registration) {
+ try {
+ const reg = registration.toUpperCase().trim();
+ const stored = localStorage.getItem(STORAGE_CALLSIGNS_KEY);
+ if (!stored) {
+ return null;
+ }
+
+ const callsigns = JSON.parse(stored);
+ const callsign = callsigns[reg] || null;
+ console.log('đ Retrieved cached callsign for', reg, '=', callsign);
+ return callsign;
+ } catch (e) {
+ console.error('Error retrieving cached callsign:', e);
+ return null;
+ }
+ }
+
function applyRecentReg(registration, formType) {
const registerIdMap = {
'local': 'localReg',
@@ -705,8 +816,16 @@
'arrival': 'arrType'
};
+ const callsignIdMap = {
+ 'local': 'localCallsign',
+ 'circuits': 'circuitCallsign',
+ 'departure': 'depCallsign',
+ 'arrival': 'arrCallsign'
+ };
+
const regId = registerIdMap[formType];
const typeId = typeIdMap[formType];
+ const callsignId = callsignIdMap[formType];
console.log('đ applyRecentReg called - reg:', registration, 'form:', formType);
document.getElementById(regId).value = registration;
@@ -720,6 +839,13 @@
console.log('âšī¸ No cached type found');
}
+ // Restore cached callsign if available
+ const cachedCallsign = getCachedCallsign(registration);
+ if (cachedCallsign) {
+ console.log('âī¸ Applying cached callsign:', cachedCallsign);
+ document.getElementById(callsignId).value = cachedCallsign;
+ }
+
document.getElementById(regId).focus();
// Trigger the lookup
handleAircraftLookup(registration, formType);
@@ -780,24 +906,24 @@
}
function showMessage(message, isError = false) {
- const successEl = document.getElementById('successMessage');
- const errorEl = document.getElementById('errorMessage');
-
if (isError) {
+ const errorEl = document.getElementById('errorMessage');
errorEl.textContent = message;
errorEl.style.display = 'block';
- successEl.style.display = 'none';
+ // Auto-hide error after 5 seconds
+ setTimeout(() => {
+ errorEl.style.display = 'none';
+ }, 5000);
} else {
- successEl.textContent = message;
- successEl.style.display = 'block';
- errorEl.style.display = 'none';
+ // Show success modal instead
+ const modalMessage = document.getElementById('modalMessage');
+ modalMessage.textContent = message;
+ document.getElementById('successModal').classList.add('active');
}
+ }
- // Auto-hide after 5 seconds
- setTimeout(() => {
- successEl.style.display = 'none';
- errorEl.style.display = 'none';
- }, 5000);
+ function closeSuccessModal() {
+ document.getElementById('successModal').classList.remove('active');
}
async function handleSubmit(event, formType) {
@@ -816,6 +942,11 @@
console.log('đž Caching type on submit - reg:', data.registration, 'type:', data.type);
cacheAircraftType(data.registration, data.type);
}
+
+ // Cache the callsign if provided
+ if (data.callsign) {
+ cacheCallsign(data.registration, data.callsign);
+ }
}
// Set flight_type based on form type
@@ -830,8 +961,12 @@
const timeFields = ['etd', 'circuit_timestamp', 'eta'];
timeFields.forEach(field => {
if (data[field]) {
- // data[field] is in HH:MM format (time input)
- const datetime = new Date(`${today}T${data[field]}:00`);
+ let timeValue = data[field];
+ // Normalize 4-digit format (HHMM) to HH:MM
+ if (/^[0-9]{4}$/.test(timeValue)) {
+ timeValue = timeValue.slice(0, 2) + ':' + timeValue.slice(2);
+ }
+ const datetime = new Date(`${today}T${timeValue}:00`);
data[field] = datetime.toISOString();
}
});
@@ -869,7 +1004,7 @@
}
const result = await response.json();
- showMessage(`â
Success! Your booking has been submitted. Booking ID: ${result.id}`);
+ showMessage(`Thanks - Your booking has been submitted. Have a great flight!`);
form.reset();
} catch (error) {
console.error('Error:', error);
@@ -880,27 +1015,32 @@
}
// Set current time as default for time inputs
+ function formatTimeInput(input) {
+ let value = input.value.replace(/[^0-9]/g, '');
+
+ // Auto-format: if user types 1430, it becomes 14:30
+ if (value.length === 4) {
+ input.value = value.slice(0, 2) + ':' + value.slice(2);
+ } else if (value.length <= 2) {
+ input.value = value;
+ } else if (value.length === 3) {
+ input.value = value.slice(0, 2) + ':' + value.slice(2);
+ }
+ }
+
function setDefaultTimes() {
const now = new Date();
- const hours = String(now.getHours()).padStart(2, '0');
- const minutes = String(now.getMinutes()).padStart(2, '0');
- const timeValue = `${hours}:${minutes}`;
-
- // ETD fields should default to 15 minutes from now
- const futureTime = new Date(now.getTime() + 15 * 60000);
+ const futureTime = new Date(now.getTime() + 10 * 60000); // 10 minutes from now
const futureHours = String(futureTime.getHours()).padStart(2, '0');
const futureMinutes = String(futureTime.getMinutes()).padStart(2, '0');
const futureTimeValue = `${futureHours}:${futureMinutes}`;
- const etdFieldIds = ['localETD', 'circuitETD', 'depETD'];
+ const etdFieldIds = ['localETD', 'circuitETD', 'depETD', 'arrETA'];
- document.querySelectorAll('input[type="time"]').forEach(input => {
- if (!input.value) {
- if (etdFieldIds.includes(input.id)) {
- input.value = futureTimeValue;
- } else {
- input.value = timeValue;
- }
+ etdFieldIds.forEach(id => {
+ const input = document.getElementById(id);
+ if (input && !input.value) {
+ input.value = futureTimeValue;
}
});
}