|
document.addEventListener('DOMContentLoaded', () => { |
|
|
|
|
|
const workerUrl = 'https://form-handler-worker.aiagents.workers.dev/'; |
|
|
|
|
|
const submissionForm = document.getElementById('vessel-exchange-form'); |
|
const lookupForm = document.getElementById('deal-lookup-form'); |
|
const adminForm = document.getElementById('admin-action-form'); |
|
|
|
const showSubmissionButton = document.getElementById('show-submission-button'); |
|
const submissionModal = document.getElementById('submission-modal'); |
|
const dealModal = document.getElementById('deal-modal'); |
|
|
|
const lookupContainer = document.getElementById('lookup-container'); |
|
const lookupInput = document.getElementById('lookup-deal-id'); |
|
|
|
const submissionStatus = document.getElementById('status-message'); |
|
const adminStatus = document.getElementById('admin-status-message'); |
|
|
|
|
|
|
|
|
|
if (showSubmissionButton) { |
|
showSubmissionButton.addEventListener('click', () => { |
|
submissionModal.classList.remove('hidden'); |
|
}); |
|
} |
|
|
|
|
|
[submissionModal, dealModal].forEach(modal => { |
|
if (modal) { |
|
modal.querySelector('.modal-close').addEventListener('click', () => closeModal(modal)); |
|
modal.addEventListener('click', (event) => { |
|
if (event.target === modal) closeModal(modal); |
|
}); |
|
} |
|
}); |
|
|
|
|
|
if (submissionForm) submissionForm.addEventListener('submit', handleFormSubmit); |
|
if (lookupForm) lookupForm.addEventListener('submit', handleLookupSubmit); |
|
|
|
|
|
if (adminForm) { |
|
document.getElementById('admin-approve-button').addEventListener('click', () => handleAdminClick('approve')); |
|
document.getElementById('admin-decline-button').addEventListener('click', () => handleAdminClick('decline')); |
|
} |
|
|
|
|
|
|
|
async function handleFormSubmit(event) { |
|
|
|
} |
|
|
|
|
|
async function handleLookupSubmit(event) { |
|
event.preventDefault(); |
|
if (!lookupInput.value) { |
|
alert('Please enter a Deal ID.'); |
|
return; |
|
} |
|
try { |
|
const response = await fetch(`${workerUrl}?deal_id=${lookupInput.value}`); |
|
const result = await response.json(); |
|
if (!response.ok) throw new Error(result.error || 'Deal not found.'); |
|
|
|
|
|
openDealInfoModal(result); |
|
|
|
} catch (error) { |
|
alert(error.message); |
|
} |
|
} |
|
|
|
async function handleAdminClick(action) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
function openDealInfoModal(dealData) { |
|
|
|
document.getElementById('modal-deal-id').textContent = dealData.deal_id; |
|
document.getElementById('modal-owner-name').textContent = dealData.owner_name; |
|
document.getElementById('modal-contact-email').textContent = dealData.contact_email; |
|
document.getElementById('modal-contact-phone').textContent = dealData.contact_phone || 'N/A'; |
|
document.getElementById('modal-year-built').textContent = dealData.year_built || 'N/A'; |
|
document.getElementById('modal-gross-tonnage').textContent = dealData.gross_tonnage || 'N/A'; |
|
document.getElementById('modal-token-amount').textContent = dealData.token_amount; |
|
document.getElementById('modal-vessel-description').textContent = dealData.vessel_description || 'No description provided.'; |
|
|
|
|
|
const statusBadge = document.getElementById('modal-status-badge'); |
|
statusBadge.textContent = dealData.status; |
|
statusBadge.className = `badge ${dealData.status || 'active'}`; |
|
|
|
|
|
dealModal.classList.remove('hidden'); |
|
} |
|
|
|
function closeModal(modalElement) { |
|
modalElement.classList.add('hidden'); |
|
} |
|
|
|
|
|
}); |