893 lines
36 KiB
HTML
893 lines
36 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Swansea PPR</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background-color: #f5f5f5;
|
|
color: #333;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 2rem auto;
|
|
padding: 2rem;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
margin-bottom: 2rem;
|
|
padding-bottom: 1rem;
|
|
border-bottom: 2px solid #3498db;
|
|
}
|
|
|
|
.header h1 {
|
|
color: #2c3e50;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.header p {
|
|
color: #666;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.form-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.form-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.form-group.full-width {
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.form-group label {
|
|
font-weight: 600;
|
|
margin-bottom: 0.3rem;
|
|
color: #555;
|
|
}
|
|
|
|
.form-group input, .form-group select, .form-group textarea {
|
|
padding: 0.6rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
|
|
outline: none;
|
|
border-color: #3498db;
|
|
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
|
|
}
|
|
|
|
.required::after {
|
|
content: " *";
|
|
color: #e74c3c;
|
|
}
|
|
|
|
.form-actions {
|
|
display: flex;
|
|
gap: 1rem;
|
|
justify-content: center;
|
|
padding-top: 1rem;
|
|
border-top: 1px solid #eee;
|
|
margin-top: 2rem;
|
|
}
|
|
|
|
.btn {
|
|
padding: 0.8rem 2rem;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
transition: all 0.3s ease;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: #3498db;
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #2980b9;
|
|
}
|
|
|
|
.btn-success {
|
|
background-color: #27ae60;
|
|
color: white;
|
|
}
|
|
|
|
.btn-success:hover {
|
|
background-color: #229954;
|
|
}
|
|
|
|
.notification {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
background-color: #27ae60;
|
|
color: white;
|
|
padding: 12px 20px;
|
|
border-radius: 5px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
|
|
z-index: 10000;
|
|
opacity: 0;
|
|
transform: translateY(-20px);
|
|
transition: all 0.3s ease;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.notification.show {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.notification.error {
|
|
background-color: #e74c3c;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.spinner {
|
|
border: 3px solid #f3f3f3;
|
|
border-top: 3px solid #3498db;
|
|
border-radius: 50%;
|
|
width: 30px;
|
|
height: 30px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 1rem;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.success-message {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 2rem;
|
|
background-color: #d4edda;
|
|
border: 1px solid #c3e6cb;
|
|
border-radius: 4px;
|
|
color: #155724;
|
|
margin-top: 2rem;
|
|
}
|
|
|
|
.airport-lookup-results {
|
|
margin-top: 0.5rem;
|
|
padding: 0.5rem;
|
|
background-color: #f8f9fa;
|
|
border-radius: 4px;
|
|
font-size: 0.9rem;
|
|
min-height: 20px;
|
|
border: 1px solid #e9ecef;
|
|
}
|
|
|
|
.aircraft-lookup-results {
|
|
margin-top: 0.5rem;
|
|
padding: 0.5rem;
|
|
background-color: #f8f9fa;
|
|
border-radius: 4px;
|
|
font-size: 0.9rem;
|
|
min-height: 20px;
|
|
border: 1px solid #e9ecef;
|
|
}
|
|
|
|
.lookup-match {
|
|
padding: 0.3rem;
|
|
background-color: #e8f5e8;
|
|
border: 1px solid #c3e6c3;
|
|
border-radius: 4px;
|
|
font-family: 'Courier New', monospace;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.lookup-no-match {
|
|
color: #6c757d;
|
|
font-style: italic;
|
|
}
|
|
|
|
.lookup-searching {
|
|
color: #007bff;
|
|
}
|
|
|
|
.aircraft-list {
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 4px;
|
|
background-color: white;
|
|
}
|
|
|
|
.aircraft-option {
|
|
padding: 0.5rem;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s ease;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.aircraft-option:hover {
|
|
background-color: #f8f9fa;
|
|
}
|
|
|
|
.aircraft-option:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.aircraft-code {
|
|
font-family: 'Courier New', monospace;
|
|
font-weight: bold;
|
|
color: #495057;
|
|
}
|
|
|
|
.aircraft-details {
|
|
color: #6c757d;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
/* Mobile responsive styles */
|
|
@media (max-width: 768px) {
|
|
.container {
|
|
margin: 1rem auto;
|
|
padding: 1rem;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 1.3rem;
|
|
}
|
|
|
|
.header p {
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.form-grid {
|
|
grid-template-columns: 1fr; /* Single column on mobile */
|
|
gap: 0.8rem;
|
|
}
|
|
|
|
.form-group input, .form-group select, .form-group textarea {
|
|
padding: 0.7rem;
|
|
font-size: 1rem; /* Prevent zoom on iOS */
|
|
}
|
|
|
|
.form-actions {
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 1rem;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.notification {
|
|
font-size: 0.9rem;
|
|
padding: 1rem;
|
|
}
|
|
|
|
.success-message {
|
|
padding: 1.5rem;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
.loading {
|
|
padding: 2rem;
|
|
}
|
|
|
|
.airport-lookup-results, .aircraft-lookup-results {
|
|
max-height: 200px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.aircraft-option, .airport-option {
|
|
padding: 0.8rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
}
|
|
|
|
/* Extra small screens */
|
|
@media (max-width: 480px) {
|
|
.container {
|
|
margin: 0.5rem;
|
|
padding: 0.8rem;
|
|
}
|
|
|
|
.header {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.form-grid {
|
|
gap: 0.6rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>✈️ PPR Request</h1>
|
|
<p>Please fill out the form below to submit a PPR request for Swansea Airport.</p>
|
|
<p>Note that this is a new form, and is under test. Please email james.pattinson@sasalliance.org if you have any issues with the form.</p>
|
|
</div>
|
|
|
|
<form id="ppr-form">
|
|
<div class="form-grid">
|
|
<div class="form-group">
|
|
<label for="ac_reg" class="required">Aircraft Registration</label>
|
|
<input type="text" id="ac_reg" name="ac_reg" required oninput="handleAircraftLookup(this.value)">
|
|
<div id="aircraft-lookup-results" class="aircraft-lookup-results"></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="ac_type" class="required">Aircraft Type</label>
|
|
<input type="text" id="ac_type" name="ac_type" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="ac_call">Callsign</label>
|
|
<input type="text" id="ac_call" name="ac_call" placeholder="If different from registration">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="captain" class="required">Captain/Pilot Name</label>
|
|
<input type="text" id="captain" name="captain" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="in_from" class="required">Arriving From</label>
|
|
<input type="text" id="in_from" name="in_from" required placeholder="ICAO Code or Airport Name" oninput="handleArrivalAirportLookup(this.value)">
|
|
<div id="arrival-airport-lookup-results" class="airport-lookup-results"></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="eta" class="required">Estimated Time of Arrival (Local Time)</label>
|
|
<div style="display: flex; gap: 0.5rem;">
|
|
<input type="date" id="eta-date" name="eta-date" required style="flex: 1;">
|
|
<select id="eta-time" name="eta-time" required style="flex: 1;">
|
|
<option value="">Select Time</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="pob_in" class="required">Persons on Board (Arrival)</label>
|
|
<input type="number" id="pob_in" name="pob_in" required min="1">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="fuel">Fuel Required</label>
|
|
<select id="fuel" name="fuel">
|
|
<option value="">None</option>
|
|
<option value="100LL">100LL</option>
|
|
<option value="JET A1">JET A1</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="out_to">Departing To</label>
|
|
<input type="text" id="out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleDepartureAirportLookup(this.value)">
|
|
<div id="departure-airport-lookup-results" class="airport-lookup-results"></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="etd">Estimated Time of Departure (Local Time)</label>
|
|
<div style="display: flex; gap: 0.5rem;">
|
|
<input type="date" id="etd-date" name="etd-date" style="flex: 1;">
|
|
<select id="etd-time" name="etd-time" style="flex: 1;">
|
|
<option value="">Select Time</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="pob_out">Persons on Board (Departure)</label>
|
|
<input type="number" id="pob_out" name="pob_out" min="1">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email Address</label>
|
|
<input type="email" id="email" name="email">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="phone">Phone Number</label>
|
|
<input type="tel" id="phone" name="phone">
|
|
</div>
|
|
<div class="form-group full-width">
|
|
<label for="notes">Additional Notes</label>
|
|
<textarea id="notes" name="notes" rows="4" placeholder="Any special requirements, handling instructions, or additional information..."></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary" id="submit-btn">
|
|
Submit PPR Request
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
Submitting your PPR request...
|
|
</div>
|
|
|
|
<div class="success-message" id="success-message">
|
|
<h3>PPR Request Submitted.</h3>
|
|
<p>Your PPR request has been submitted. You will receive confirmation via email if provided.</p>
|
|
<p><strong>Please note:</strong> PPR requests are accepted by default. We will contact you if additional information is required. Remember to check NOTAMs before your flight.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Success Notification -->
|
|
<div id="notification" class="notification"></div>
|
|
|
|
<script src="/config.js"></script>
|
|
<script>
|
|
// API base URL for iframe embedding - loaded from config.js or fallback
|
|
console.log('=== PPR Config Debug ===');
|
|
console.log('window.PPR_CONFIG:', window.PPR_CONFIG);
|
|
console.log('window.PPR_CONFIG.apiBase:', window.PPR_CONFIG?.apiBase);
|
|
|
|
const API_BASE = (window.PPR_CONFIG && window.PPR_CONFIG.apiBase) || '/api/v1';
|
|
|
|
console.log('Final API_BASE:', API_BASE);
|
|
console.log('Source:', window.PPR_CONFIG?.apiBase ? 'config.js' : 'fallback');
|
|
console.log('=======================');
|
|
|
|
// Track if user has manually edited ETD
|
|
let etdManuallyEdited = false;
|
|
|
|
// Function to update ETD based on ETA (2 hours later)
|
|
function updateETDFromETA() {
|
|
// Only auto-update if user hasn't manually edited ETD
|
|
if (etdManuallyEdited) {
|
|
return;
|
|
}
|
|
|
|
const etaDate = document.getElementById('eta-date').value;
|
|
const etaTime = document.getElementById('eta-time').value;
|
|
|
|
if (etaDate && etaTime) {
|
|
// Parse ETA
|
|
const eta = new Date(`${etaDate}T${etaTime}`);
|
|
|
|
// Calculate ETD (2 hours after ETA)
|
|
const etd = new Date(eta.getTime() + 2 * 60 * 60 * 1000);
|
|
|
|
// Format ETD
|
|
const etdDateStr = `${etd.getFullYear()}-${String(etd.getMonth() + 1).padStart(2, '0')}-${String(etd.getDate()).padStart(2, '0')}`;
|
|
const etdTimeStr = `${String(etd.getHours()).padStart(2, '0')}:${String(etd.getMinutes()).padStart(2, '0')}`;
|
|
|
|
// Update ETD fields
|
|
document.getElementById('etd-date').value = etdDateStr;
|
|
document.getElementById('etd-time').value = etdTimeStr;
|
|
}
|
|
}
|
|
|
|
// Function to mark ETD as manually edited
|
|
function markETDAsManuallyEdited() {
|
|
etdManuallyEdited = true;
|
|
}
|
|
|
|
// Iframe resizing functionality
|
|
function sendHeightToParent() {
|
|
const height = document.body.scrollHeight || document.documentElement.scrollHeight;
|
|
if (window.parent !== window) {
|
|
window.parent.postMessage({
|
|
type: 'setHeight',
|
|
height: height + 20 // Add some padding
|
|
}, '*');
|
|
}
|
|
}
|
|
|
|
// Send height on load and resize
|
|
window.addEventListener('load', function() {
|
|
sendHeightToParent();
|
|
// Also send height after any content changes
|
|
setTimeout(sendHeightToParent, 100);
|
|
});
|
|
|
|
window.addEventListener('resize', sendHeightToParent);
|
|
|
|
// Initialize time dropdowns
|
|
function initializeTimeDropdowns() {
|
|
const timeSelects = ['eta-time', 'etd-time'];
|
|
|
|
timeSelects.forEach(selectId => {
|
|
const select = document.getElementById(selectId);
|
|
// Clear existing options except the first one
|
|
select.innerHTML = '<option value="">Select Time</option>';
|
|
|
|
// Add time options in 15-minute intervals
|
|
for (let hour = 0; hour < 24; hour++) {
|
|
for (let minute = 0; minute < 60; minute += 15) {
|
|
const timeString = `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
|
|
const option = document.createElement('option');
|
|
option.value = timeString;
|
|
option.textContent = timeString;
|
|
select.appendChild(option);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Notification system
|
|
function showNotification(message, isError = false) {
|
|
const notification = document.getElementById('notification');
|
|
notification.textContent = message;
|
|
notification.className = 'notification' + (isError ? ' error' : '');
|
|
|
|
// Show notification
|
|
setTimeout(() => {
|
|
notification.classList.add('show');
|
|
// Update iframe height when notification appears
|
|
setTimeout(sendHeightToParent, 50);
|
|
}, 10);
|
|
|
|
// Hide after 5 seconds
|
|
setTimeout(() => {
|
|
notification.classList.remove('show');
|
|
// Update iframe height when notification disappears
|
|
setTimeout(sendHeightToParent, 50);
|
|
}, 5000);
|
|
}
|
|
|
|
// Aircraft lookup
|
|
let aircraftLookupTimeout;
|
|
async function handleAircraftLookup(registration) {
|
|
clearTimeout(aircraftLookupTimeout);
|
|
const resultsDiv = document.getElementById('aircraft-lookup-results');
|
|
const regField = document.getElementById('ac_reg');
|
|
|
|
if (!registration || registration.length < 4) {
|
|
resultsDiv.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
resultsDiv.innerHTML = '<span class="lookup-searching">Searching...</span>';
|
|
|
|
aircraftLookupTimeout = setTimeout(async () => {
|
|
try {
|
|
const response = await fetch(`${API_BASE}/aircraft/public/lookup/${registration.toUpperCase()}`);
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
if (data && data.length > 0) {
|
|
if (data.length === 1) {
|
|
// Single match - auto-populate the registration field
|
|
const aircraft = data[0];
|
|
regField.value = aircraft.registration || registration.toUpperCase();
|
|
resultsDiv.innerHTML = `
|
|
<div class="lookup-match">
|
|
${aircraft.registration || registration.toUpperCase()} - ${aircraft.type_code || 'Unknown'} ${aircraft.model ? `(${aircraft.model})` : ''}
|
|
</div>
|
|
`;
|
|
// Auto-fill aircraft type if not already filled
|
|
if (!document.getElementById('ac_type').value) {
|
|
document.getElementById('ac_type').value = aircraft.type_code || '';
|
|
}
|
|
} else if (data.length <= 10) {
|
|
// Multiple matches - show as clickable list
|
|
resultsDiv.innerHTML = `
|
|
<div class="aircraft-list">
|
|
${data.map(aircraft => `
|
|
<div class="aircraft-option" onclick="selectAircraft('${aircraft.registration || registration.toUpperCase()}', '${aircraft.type_code || ''}')">
|
|
<div class="aircraft-code">${aircraft.registration || registration.toUpperCase()}</div>
|
|
<div class="aircraft-details">${aircraft.type_code || 'Unknown'} ${aircraft.model ? `(${aircraft.model})` : ''}</div>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
`;
|
|
} else {
|
|
// Too many matches
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">Too many matches, please be more specific</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">No aircraft found with this registration</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
} catch (error) {
|
|
console.error('Aircraft lookup error:', error);
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
}, 500);
|
|
}
|
|
|
|
function selectAircraft(registration, typeCode) {
|
|
document.getElementById('ac_reg').value = registration;
|
|
// Always update the aircraft type when a specific aircraft is selected
|
|
document.getElementById('ac_type').value = typeCode;
|
|
document.getElementById('aircraft-lookup-results').innerHTML = '';
|
|
// Remove focus from the field to hide the dropdown
|
|
document.getElementById('ac_reg').blur();
|
|
}
|
|
|
|
// Clear aircraft lookup results when input loses focus
|
|
document.getElementById('ac_reg').addEventListener('blur', function() {
|
|
// Delay clearing to allow click events on options
|
|
setTimeout(() => {
|
|
document.getElementById('aircraft-lookup-results').innerHTML = '';
|
|
}, 150);
|
|
});
|
|
|
|
// Airport lookup functions
|
|
let arrivalAirportLookupTimeout;
|
|
async function handleArrivalAirportLookup(query) {
|
|
clearTimeout(arrivalAirportLookupTimeout);
|
|
const resultsDiv = document.getElementById('arrival-airport-lookup-results');
|
|
const inputField = document.getElementById('in_from');
|
|
|
|
if (!query || query.length < 2) {
|
|
resultsDiv.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
resultsDiv.innerHTML = '<span class="lookup-searching">Searching...</span>';
|
|
|
|
arrivalAirportLookupTimeout = setTimeout(async () => {
|
|
try {
|
|
const response = await fetch(`${API_BASE}/airport/public/lookup/${query.toUpperCase()}`);
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
if (data && data.length > 0) {
|
|
if (data.length === 1) {
|
|
// Single match - show as clickable option
|
|
const airport = data[0];
|
|
resultsDiv.innerHTML = `
|
|
<div class="aircraft-list">
|
|
<div class="aircraft-option" onclick="selectAirport('in_from', '${airport.icao}')">
|
|
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
|
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
} else if (data.length <= 10) {
|
|
// Multiple matches - show as clickable list
|
|
resultsDiv.innerHTML = `
|
|
<div class="aircraft-list">
|
|
${data.map(airport => `
|
|
<div class="aircraft-option" onclick="selectAirport('in_from', '${airport.icao}')">
|
|
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
|
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
`;
|
|
} else {
|
|
// Too many matches
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">Too many matches, please be more specific</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">No airport found</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
} catch (error) {
|
|
console.error('Arrival airport lookup error:', error);
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
}, 500);
|
|
}
|
|
|
|
let departureAirportLookupTimeout;
|
|
async function handleDepartureAirportLookup(query) {
|
|
clearTimeout(departureAirportLookupTimeout);
|
|
const resultsDiv = document.getElementById('departure-airport-lookup-results');
|
|
const inputField = document.getElementById('out_to');
|
|
|
|
if (!query || query.length < 2) {
|
|
resultsDiv.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
resultsDiv.innerHTML = '<span class="lookup-searching">Searching...</span>';
|
|
|
|
departureAirportLookupTimeout = setTimeout(async () => {
|
|
try {
|
|
const response = await fetch(`${API_BASE}/airport/public/lookup/${query.toUpperCase()}`);
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
if (data && data.length > 0) {
|
|
if (data.length === 1) {
|
|
// Single match - show as clickable option
|
|
const airport = data[0];
|
|
resultsDiv.innerHTML = `
|
|
<div class="aircraft-list">
|
|
<div class="aircraft-option" onclick="selectAirport('out_to', '${airport.icao}')">
|
|
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
|
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
} else if (data.length <= 10) {
|
|
// Multiple matches - show as clickable list
|
|
resultsDiv.innerHTML = `
|
|
<div class="aircraft-list">
|
|
${data.map(airport => `
|
|
<div class="aircraft-option" onclick="selectAirport('out_to', '${airport.icao}')">
|
|
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
|
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
`;
|
|
} else {
|
|
// Too many matches
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">Too many matches, please be more specific</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '<span class="lookup-no-match">No airport found</span>';
|
|
}
|
|
} else {
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
} catch (error) {
|
|
console.error('Departure airport lookup error:', error);
|
|
resultsDiv.innerHTML = '';
|
|
}
|
|
}, 500);
|
|
}
|
|
|
|
function selectAirport(fieldId, icaoCode) {
|
|
document.getElementById(fieldId).value = icaoCode;
|
|
// Clear the results
|
|
const resultsDivId = fieldId === 'in_from' ? 'arrival-airport-lookup-results' : 'departure-airport-lookup-results';
|
|
document.getElementById(resultsDivId).innerHTML = '';
|
|
// Remove focus from the field to hide the dropdown
|
|
document.getElementById(fieldId).blur();
|
|
}
|
|
|
|
// Clear airport lookup results when input loses focus
|
|
document.getElementById('in_from').addEventListener('blur', function() {
|
|
setTimeout(() => {
|
|
document.getElementById('arrival-airport-lookup-results').innerHTML = '';
|
|
}, 150);
|
|
});
|
|
|
|
document.getElementById('out_to').addEventListener('blur', function() {
|
|
setTimeout(() => {
|
|
document.getElementById('departure-airport-lookup-results').innerHTML = '';
|
|
}, 150);
|
|
});
|
|
|
|
// Form submission
|
|
document.getElementById('ppr-form').addEventListener('submit', async function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
const pprData = {};
|
|
|
|
formData.forEach((value, key) => {
|
|
if (value.trim() !== '') {
|
|
if (key === 'pob_in' || key === 'pob_out') {
|
|
pprData[key] = parseInt(value);
|
|
} else if (key === 'eta-date' && formData.get('eta-time')) {
|
|
// Combine date and time for ETA
|
|
const dateStr = formData.get('eta-date');
|
|
const timeStr = formData.get('eta-time');
|
|
pprData.eta = new Date(`${dateStr}T${timeStr}`).toISOString();
|
|
} else if (key === 'etd-date' && formData.get('etd-time')) {
|
|
// Combine date and time for ETD
|
|
const dateStr = formData.get('etd-date');
|
|
const timeStr = formData.get('etd-time');
|
|
pprData.etd = new Date(`${dateStr}T${timeStr}`).toISOString();
|
|
} else if (key !== 'eta-time' && key !== 'etd-time') {
|
|
// Skip the time fields as they're handled above
|
|
pprData[key] = value;
|
|
}
|
|
}
|
|
});
|
|
|
|
// Show loading
|
|
document.getElementById('loading').style.display = 'block';
|
|
document.getElementById('submit-btn').disabled = true;
|
|
document.getElementById('submit-btn').textContent = 'Submitting...';
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE}/pprs/public`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(pprData)
|
|
});
|
|
|
|
if (response.ok) {
|
|
const result = await response.json();
|
|
console.log('PPR submitted successfully:', result);
|
|
|
|
// Hide form and show success message
|
|
document.getElementById('ppr-form').style.display = 'none';
|
|
document.getElementById('success-message').style.display = 'block';
|
|
|
|
showNotification('PPR request submitted successfully!');
|
|
// Update iframe height after content change
|
|
setTimeout(sendHeightToParent, 100);
|
|
} else {
|
|
const errorData = await response.json().catch(() => ({}));
|
|
throw new Error(errorData.detail || `Submission failed: ${response.status}`);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error submitting PPR:', error);
|
|
showNotification(`Error submitting PPR: ${error.message}`, true);
|
|
// Update iframe height after showing error
|
|
setTimeout(sendHeightToParent, 100);
|
|
} finally {
|
|
// Hide loading
|
|
document.getElementById('loading').style.display = 'none';
|
|
document.getElementById('submit-btn').disabled = false;
|
|
document.getElementById('submit-btn').textContent = 'Submit PPR Request';
|
|
}
|
|
});
|
|
|
|
// Set default date and time values
|
|
function setDefaultDateTime() {
|
|
const now = new Date();
|
|
// Round up to the next hour
|
|
const nextHour = new Date(now);
|
|
nextHour.setHours(now.getHours() + 1, 0, 0, 0);
|
|
|
|
// ETD is 2 hours after ETA
|
|
const etd = new Date(nextHour);
|
|
etd.setHours(nextHour.getHours() + 2);
|
|
|
|
// Format date and time for separate inputs
|
|
function formatDate(date) {
|
|
const year = date.getFullYear();
|
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
const day = String(date.getDate()).padStart(2, '0');
|
|
return `${year}-${month}-${day}`;
|
|
}
|
|
|
|
function formatTime(date) {
|
|
const hours = String(date.getHours()).padStart(2, '0');
|
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
return `${hours}:${minutes}`;
|
|
}
|
|
|
|
// Set ETA to next hour
|
|
document.getElementById('eta-date').value = formatDate(nextHour);
|
|
document.getElementById('eta-time').value = formatTime(nextHour);
|
|
|
|
// Set ETD to one hour after ETA
|
|
document.getElementById('etd-date').value = formatDate(etd);
|
|
document.getElementById('etd-time').value = formatTime(etd);
|
|
}
|
|
|
|
// Initialize the page when DOM is loaded
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
initializeTimeDropdowns();
|
|
setDefaultDateTime();
|
|
|
|
// Add event listeners to ETA fields to auto-update ETD
|
|
document.getElementById('eta-date').addEventListener('change', updateETDFromETA);
|
|
document.getElementById('eta-time').addEventListener('change', updateETDFromETA);
|
|
|
|
// Add event listeners to ETD fields to mark as manually edited
|
|
document.getElementById('etd-date').addEventListener('change', markETDAsManuallyEdited);
|
|
document.getElementById('etd-time').addEventListener('change', markETDAsManuallyEdited);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |