Public PPR submission
This commit is contained in:
@@ -33,6 +33,30 @@ async def lookup_aircraft_by_registration(
|
||||
return aircraft_list
|
||||
|
||||
|
||||
@router.get("/public/lookup/{registration}", response_model=List[AircraftSchema])
|
||||
async def public_lookup_aircraft_by_registration(
|
||||
registration: str,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Public lookup aircraft by registration (clean match).
|
||||
Removes non-alphanumeric characters from input for matching.
|
||||
No authentication required.
|
||||
"""
|
||||
# Clean the input registration (remove non-alphanumeric characters)
|
||||
clean_input = ''.join(c for c in registration if c.isalnum()).upper()
|
||||
|
||||
if len(clean_input) < 4:
|
||||
return []
|
||||
|
||||
# Query aircraft table using clean_reg column
|
||||
aircraft_list = db.query(Aircraft).filter(
|
||||
Aircraft.clean_reg.like(f"{clean_input}%")
|
||||
).limit(10).all()
|
||||
|
||||
return aircraft_list
|
||||
|
||||
|
||||
@router.get("/search", response_model=List[AircraftSchema])
|
||||
async def search_aircraft(
|
||||
q: Optional[str] = Query(None, description="Search query for registration, type, or manufacturer"),
|
||||
|
||||
@@ -69,3 +69,38 @@ async def search_airports(
|
||||
).limit(limit).all()
|
||||
|
||||
return airports
|
||||
|
||||
|
||||
@router.get("/public/lookup/{code_or_name}", response_model=List[AirportSchema])
|
||||
async def public_lookup_airport_by_code_or_name(
|
||||
code_or_name: str,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Public lookup airport by ICAO code or name.
|
||||
If input is 4 characters and all uppercase letters, treat as ICAO code.
|
||||
Otherwise, search by name.
|
||||
No authentication required.
|
||||
"""
|
||||
clean_input = code_or_name.strip().upper()
|
||||
|
||||
if len(clean_input) < 2:
|
||||
return []
|
||||
|
||||
# Check if input looks like an ICAO code (4 letters)
|
||||
if len(clean_input) == 4 and clean_input.isalpha():
|
||||
# Exact ICAO match first
|
||||
airport = db.query(Airport).filter(Airport.icao == clean_input).first()
|
||||
if airport:
|
||||
return [airport]
|
||||
# Then search ICAO codes that start with input
|
||||
airports = db.query(Airport).filter(
|
||||
Airport.icao.like(clean_input + "%")
|
||||
).limit(5).all()
|
||||
return airports
|
||||
else:
|
||||
# Search by name (case-insensitive partial match)
|
||||
airports = db.query(Airport).filter(
|
||||
Airport.name.ilike("%" + code_or_name + "%")
|
||||
).limit(10).all()
|
||||
return airports
|
||||
@@ -56,6 +56,31 @@ async def create_ppr(
|
||||
return ppr
|
||||
|
||||
|
||||
@router.post("/public", response_model=PPR)
|
||||
async def create_public_ppr(
|
||||
request: Request,
|
||||
ppr_in: PPRCreate,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""Create a new PPR record (public endpoint, no authentication required)"""
|
||||
client_ip = get_client_ip(request)
|
||||
# For public submissions, use a default created_by or None
|
||||
ppr = crud_ppr.create(db, obj_in=ppr_in, created_by="public", user_ip=client_ip)
|
||||
|
||||
# Send real-time update via WebSocket
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "ppr_created",
|
||||
"data": {
|
||||
"id": ppr.id,
|
||||
"ac_reg": ppr.ac_reg,
|
||||
"status": ppr.status.value
|
||||
}
|
||||
})
|
||||
|
||||
return ppr
|
||||
|
||||
|
||||
@router.get("/{ppr_id}", response_model=PPR)
|
||||
async def get_ppr(
|
||||
ppr_id: int,
|
||||
|
||||
587
web/ppr.html
Normal file
587
web/ppr.html
Normal file
@@ -0,0 +1,587 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Swansea PPR Request</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;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>✈️ Swansea Airport PPR Request</h1>
|
||||
<p>Please fill out the form below to submit a Prior Permission Required (PPR) request for Swansea Airport.</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>
|
||||
<input type="datetime-local" id="eta" name="eta" required>
|
||||
</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>
|
||||
<option value="FULL">Full Tanks</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>
|
||||
<input type="datetime-local" id="etd" name="etd">
|
||||
</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 Successfully!</h3>
|
||||
<p>Your Prior Permission Required request has been submitted and will be reviewed by airport operations. You will receive confirmation via email if provided.</p>
|
||||
<p><strong>Please note:</strong> This is not confirmation of approval. Airport operations will contact you if additional information is required.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Success Notification -->
|
||||
<div id="notification" class="notification"></div>
|
||||
|
||||
<script>
|
||||
// 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');
|
||||
}, 10);
|
||||
|
||||
// Hide after 5 seconds
|
||||
setTimeout(() => {
|
||||
notification.classList.remove('show');
|
||||
}, 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/v1/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');
|
||||
|
||||
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/v1/airport/public/lookup/${query.toUpperCase()}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data && data.length > 0) {
|
||||
const airport = data[0];
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="lookup-match">
|
||||
${airport.icao}/${airport.iata || ''} - ${airport.name}, ${airport.country}
|
||||
</div>
|
||||
`;
|
||||
} 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');
|
||||
|
||||
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/v1/airport/public/lookup/${query.toUpperCase()}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data && data.length > 0) {
|
||||
const airport = data[0];
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="lookup-match">
|
||||
${airport.icao}/${airport.iata || ''} - ${airport.name}, ${airport.country}
|
||||
</div>
|
||||
`;
|
||||
} 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);
|
||||
}
|
||||
|
||||
// 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' || key === 'etd') {
|
||||
// Convert datetime-local to ISO string
|
||||
pprData[key] = new Date(value).toISOString();
|
||||
} else {
|
||||
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/v1/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!');
|
||||
} 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);
|
||||
} finally {
|
||||
// Hide loading
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
document.getElementById('submit-btn').disabled = false;
|
||||
document.getElementById('submit-btn').textContent = 'Submit PPR Request';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user