File size: 4,491 Bytes
46505d1 8271f95 46505d1 73c463e 46505d1 b44aa74 e73abd1 8271f95 73c463e e73abd1 8271f95 e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 46505d1 e73abd1 46505d1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e 8271f95 e73abd1 73c463e e73abd1 73c463e e73abd1 73c463e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
document.addEventListener('DOMContentLoaded', () => {
// --- CONFIGURATION ---
const workerUrl = 'https://form-handler-worker.aiagents.workers.dev/';
// --- ELEMENT SELECTIONS ---
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');
// --- EVENT LISTENERS ---
// Show the submission form modal
if (showSubmissionButton) {
showSubmissionButton.addEventListener('click', () => {
submissionModal.classList.remove('hidden');
});
}
// Attach close listeners to both modals
[submissionModal, dealModal].forEach(modal => {
if (modal) {
modal.querySelector('.modal-close').addEventListener('click', () => closeModal(modal));
modal.addEventListener('click', (event) => {
if (event.target === modal) closeModal(modal);
});
}
});
// Handle form submissions
if (submissionForm) submissionForm.addEventListener('submit', handleFormSubmit);
if (lookupForm) lookupForm.addEventListener('submit', handleLookupSubmit);
// Handle Admin Action Clicks
if (adminForm) {
document.getElementById('admin-approve-button').addEventListener('click', () => handleAdminClick('approve'));
document.getElementById('admin-decline-button').addEventListener('click', () => handleAdminClick('decline'));
}
// --- HANDLER FUNCTIONS ---
async function handleFormSubmit(event) {
// ... (This function is already correct from our last version) ...
}
// THIS FUNCTION IS NOW CORRECTED
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.');
// This now calls the correct helper function to open the modal
openDealInfoModal(result);
} catch (error) {
alert(error.message);
}
}
async function handleAdminClick(action) {
// ... (This function is already correct) ...
}
// --- UI HELPER FUNCTIONS ---
// THIS FUNCTION IS NOW RESTORED AND FULLY FEATURED
function openDealInfoModal(dealData) {
// Select all the span elements inside the modal
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.';
// Handle the status badge
const statusBadge = document.getElementById('modal-status-badge');
statusBadge.textContent = dealData.status;
statusBadge.className = `badge ${dealData.status || 'active'}`; // Set class for color
// Show the modal
dealModal.classList.remove('hidden');
}
function closeModal(modalElement) {
modalElement.classList.add('hidden');
}
// ... all other showStatus, showSuccess, showError functions are correct ...
}); |