local-flights #5

Merged
jamesp merged 37 commits from local-flights into main 2025-12-20 12:29:32 -05:00
Showing only changes of commit 97517777df - Show all commits

View File

@@ -394,15 +394,12 @@
<input type="text" id="local_out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleLocalOutToAirportLookup(this.value)" tabindex="3">
<div id="local-out-to-lookup-results"></div>
</div>
<div class="form-group" id="local-etd-group" style="display: none;">
<label for="local_etd">ETD (Estimated Time of Departure)</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="local_etd_date" name="etd_date" style="flex: 1;">
<select id="local_etd_time" name="etd_time" style="flex: 1;">
<div class="form-group">
<label for="local_etd_time">ETD (Estimated Time of Departure) *</label>
<select id="local_etd_time" name="etd_time" required>
<option value="">Select Time</option>
</select>
</div>
</div>
<div class="form-group full-width">
<label for="local_notes">Notes</label>
<textarea id="local_notes" name="notes" rows="3" placeholder="e.g., destination, any special requirements"></textarea>
@@ -2662,82 +2659,74 @@
const destGroup = document.getElementById('departure-destination-group');
const destInput = document.getElementById('local_out_to');
const destLabel = document.getElementById('departure-destination-label');
const etdGroup = document.getElementById('local-etd-group');
if (flightType === 'DEPARTURE') {
destGroup.style.display = 'block';
destInput.required = true;
destLabel.textContent = 'Destination Airport *';
etdGroup.style.display = 'block';
} else {
destGroup.style.display = 'none';
destInput.required = false;
destInput.value = '';
destLabel.textContent = 'Destination Airport';
etdGroup.style.display = 'none';
document.getElementById('local_etd_date').value = '';
document.getElementById('local_etd_time').value = '';
}
// Populate ETD time slots
// Populate ETD time slots for all flight types
populateETDTimeSlots();
}
function getNearest15MinSlot() {
function getNext10MinuteSlot() {
const now = new Date();
const minutes = now.getMinutes();
const remainder = minutes % 15;
const roundedMinutes = remainder >= 7.5 ? minutes + (15 - remainder) : minutes - remainder;
const remainder = minutes % 10;
const future = new Date(now);
future.setMinutes(roundedMinutes === 60 ? 0 : roundedMinutes);
if (roundedMinutes === 60) {
future.setHours(future.getHours() + 1);
const next = new Date(now);
if (remainder === 0) {
// Already on a 10-minute boundary, use this time
next.setSeconds(0);
} else {
// Round up to next 10-minute boundary
next.setMinutes(minutes + (10 - remainder));
next.setSeconds(0);
}
return future;
return next;
}
function populateETDTimeSlots() {
const timeSelect = document.getElementById('local_etd_time');
const dateInput = document.getElementById('local_etd_date');
// Get the selected date or use today
let selectedDate = dateInput.value;
if (!selectedDate) {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
selectedDate = `${year}-${month}-${day}`;
dateInput.value = selectedDate;
}
// Clear and repopulate
timeSelect.innerHTML = '<option value="">Select Time</option>';
const future = getNearest15MinSlot();
const selectedDateTime = new Date(selectedDate + 'T00:00:00');
// Get the next 10-minute slot
const defaultTime = getNext10MinuteSlot();
const defaultHour = defaultTime.getHours();
const defaultMinute = defaultTime.getMinutes();
// If selected date is today, start from nearest 15-min slot; otherwise start from 06:00
let startHour = selectedDateTime.toDateString() === new Date().toDateString() ? future.getHours() : 6;
let startMinute = selectedDateTime.toDateString() === new Date().toDateString() ? future.getMinutes() : 0;
// Generate 10-minute slots from next slot to 22:00
let currentHour = defaultHour;
let currentMinute = defaultMinute;
// Generate 15-minute slots from start time to 22:00
for (let hour = startHour; hour < 24; hour++) {
for (let minute = (hour === startHour ? startMinute : 0); minute < 60; minute += 15) {
const timeStr = `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`;
// Generate 10-minute slots from start time to 22:00
while (currentHour < 24) {
const timeStr = `${String(currentHour).padStart(2, '0')}:${String(currentMinute).padStart(2, '0')}`;
const option = document.createElement('option');
option.value = timeStr;
option.textContent = timeStr;
// Auto-select the nearest slot for today
if (selectedDateTime.toDateString() === new Date().toDateString() &&
hour === future.getHours() && minute === future.getMinutes()) {
// Auto-select the next 10-minute slot
if (currentHour === defaultHour && currentMinute === defaultMinute) {
option.selected = true;
}
timeSelect.appendChild(option);
// Move to next 10-minute interval
currentMinute += 10;
if (currentMinute >= 60) {
currentMinute -= 60;
currentHour += 1;
}
}
}
@@ -2943,12 +2932,15 @@
// Skip the hidden id field and empty values
if (key === 'id') return;
// Handle date/time combination for ETD (departures)
if (key === 'etd_date' || key === 'etd_time') {
if (!flightData.etd && formData.get('etd_date') && formData.get('etd_time')) {
const dateStr = formData.get('etd_date');
const timeStr = formData.get('etd_time');
flightData.etd = new Date(`${dateStr}T${timeStr}`).toISOString();
// Handle time-only ETD (always today)
if (key === 'etd_time') {
if (value.trim()) {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const dateStr = `${year}-${month}-${day}`;
flightData.etd = new Date(`${dateStr}T${value}`).toISOString();
}
return;
}