Update script.js
Browse files
script.js
CHANGED
@@ -1,133 +1,18 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
const
|
11 |
-
|
12 |
-
|
13 |
-
const modal = document.getElementById('deal-modal');
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
// 1. Handle New Deal Submissions
|
18 |
-
if (submissionForm) {
|
19 |
-
submissionForm.addEventListener('submit', handleFormSubmit);
|
20 |
-
}
|
21 |
-
|
22 |
-
// 2. Handle Deal Status Lookups
|
23 |
-
if (lookupForm) {
|
24 |
-
lookupForm.addEventListener('submit', handleLookupSubmit);
|
25 |
-
}
|
26 |
-
|
27 |
-
// 3. Handle Admin Actions
|
28 |
-
if (adminForm) {
|
29 |
-
document.getElementById('admin-approve-button').addEventListener('click', () => handleAdminClick('approve'));
|
30 |
-
document.getElementById('admin-decline-button').addEventListener('click', () => handleAdminClick('decline'));
|
31 |
-
}
|
32 |
-
|
33 |
-
// 4. Handle Modal Closing
|
34 |
-
if (modal) {
|
35 |
-
document.getElementById('modal-close-button').addEventListener('click', closeModal);
|
36 |
-
modal.addEventListener('click', (event) => {
|
37 |
-
if (event.target === modal) closeModal();
|
38 |
-
});
|
39 |
-
}
|
40 |
-
|
41 |
-
// --- HANDLER FUNCTIONS ---
|
42 |
-
|
43 |
-
async function handleFormSubmit(event) {
|
44 |
-
event.preventDefault();
|
45 |
-
const submitButton = document.getElementById('submit-button');
|
46 |
-
submitButton.disabled = true;
|
47 |
-
submissionStatus.className = 'status';
|
48 |
-
submissionStatus.textContent = 'Submitting...';
|
49 |
-
submissionStatus.style.display = 'block';
|
50 |
-
|
51 |
-
try {
|
52 |
-
const formData = new FormData(submissionForm);
|
53 |
-
const response = await fetch(workerUrl, { method: 'POST', body: formData });
|
54 |
-
const result = await response.json();
|
55 |
-
if (!response.ok) throw new Error(result.error || `Server responded with status ${response.status}`);
|
56 |
-
|
57 |
-
showSuccess(submissionStatus, `Success! Your Deal ID is: ${result.deal_id}`);
|
58 |
-
submissionForm.reset();
|
59 |
-
} catch (error) {
|
60 |
-
showError(submissionStatus, error.message);
|
61 |
-
} finally {
|
62 |
-
submitButton.disabled = false;
|
63 |
-
}
|
64 |
-
}
|
65 |
-
|
66 |
-
async function handleLookupSubmit(event) {
|
67 |
-
event.preventDefault();
|
68 |
-
const dealId = document.getElementById('lookup-deal-id').value;
|
69 |
-
if (!dealId) return;
|
70 |
-
|
71 |
-
try {
|
72 |
-
const response = await fetch(`${workerUrl}?deal_id=${dealId}`, { method: 'GET' });
|
73 |
-
const result = await response.json();
|
74 |
-
if (!response.ok) throw new Error(result.error || 'Failed to fetch deal.');
|
75 |
-
|
76 |
-
openModal(result);
|
77 |
-
} catch (error) {
|
78 |
-
alert(`Error: ${error.message}`);
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
async function handleAdminClick(action) {
|
83 |
-
const dealId = document.getElementById('admin-deal-id').value;
|
84 |
-
if (!dealId) {
|
85 |
-
showError(adminStatus, 'Please enter a Deal ID.');
|
86 |
-
return;
|
87 |
-
}
|
88 |
-
|
89 |
-
const formData = new FormData();
|
90 |
-
formData.append('action', action);
|
91 |
-
formData.append('deal_id', dealId);
|
92 |
-
|
93 |
-
try {
|
94 |
-
const response = await fetch(workerUrl, { method: 'POST', body: formData });
|
95 |
-
const result = await response.json();
|
96 |
-
if (!response.ok) throw new Error(result.error || `Server responded with status ${response.status}`);
|
97 |
-
|
98 |
-
showSuccess(adminStatus, result.message);
|
99 |
-
} catch (error) {
|
100 |
-
showError(adminStatus, error.message);
|
101 |
-
}
|
102 |
-
}
|
103 |
-
|
104 |
-
// --- MODAL & UI FUNCTIONS ---
|
105 |
-
|
106 |
-
function openModal(dealData) {
|
107 |
-
document.getElementById('modal-deal-id').textContent = dealData.deal_id;
|
108 |
-
document.getElementById('modal-owner-name').textContent = dealData.owner_name;
|
109 |
-
document.getElementById('modal-token-amount').textContent = dealData.token_amount;
|
110 |
-
|
111 |
-
const statusBadge = document.getElementById('modal-status-badge');
|
112 |
-
statusBadge.textContent = dealData.status;
|
113 |
-
statusBadge.className = `badge ${dealData.status}`; // e.g., "badge accepted"
|
114 |
-
|
115 |
-
modal.classList.remove('hidden');
|
116 |
-
}
|
117 |
-
|
118 |
-
function closeModal() {
|
119 |
-
modal.classList.add('hidden');
|
120 |
-
}
|
121 |
-
|
122 |
-
function showSuccess(element, message) {
|
123 |
-
element.className = 'status success';
|
124 |
-
element.textContent = message;
|
125 |
-
element.style.display = 'block';
|
126 |
-
}
|
127 |
-
|
128 |
-
function showError(element, message) {
|
129 |
-
element.className = 'status error';
|
130 |
-
element.textContent = `Error: ${message}`;
|
131 |
-
element.style.display = 'block';
|
132 |
-
}
|
133 |
-
});
|
|
|
1 |
+
// Replace the old openModal function in your script.js file
|
2 |
+
function openModal(dealData) {
|
3 |
+
// Populate all the new fields
|
4 |
+
document.getElementById('modal-deal-id').textContent = dealData.deal_id;
|
5 |
+
document.getElementById('modal-owner-name').textContent = dealData.owner_name;
|
6 |
+
document.getElementById('modal-contact-email').textContent = dealData.contact_email;
|
7 |
+
document.getElementById('modal-contact-phone').textContent = dealData.contact_phone || 'N/A';
|
8 |
+
document.getElementById('modal-year-built').textContent = dealData.year_built || 'N/A';
|
9 |
+
document.getElementById('modal-gross-tonnage').textContent = dealData.gross_tonnage || 'N/A';
|
10 |
+
document.getElementById('modal-token-amount').textContent = dealData.token_amount;
|
11 |
+
document.getElementById('modal-vessel-description').textContent = dealData.vessel_description || 'No description provided.';
|
12 |
|
13 |
+
const statusBadge = document.getElementById('modal-status-badge');
|
14 |
+
statusBadge.textContent = dealData.status;
|
15 |
+
statusBadge.className = `badge ${dealData.status}`; // e.g., "badge accepted"
|
|
|
16 |
|
17 |
+
modal.classList.remove('hidden');
|
18 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|