Add/Update web/assets/js/main.js (Batch 4: real audit API backend + fetch wiring; port 8199 to avoid Gitea 3000 collision)
This commit is contained in:
+30
-6
@@ -35,7 +35,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
rejectBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
rejectBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- COLD AUDIT FORM LOGIC ---
|
// --- COLD AUDIT FORM LOGIC (REAL BACKEND) ---
|
||||||
const auditForm = document.getElementById('audit-form');
|
const auditForm = document.getElementById('audit-form');
|
||||||
if (auditForm) {
|
if (auditForm) {
|
||||||
auditForm.addEventListener('submit', async (e) => {
|
auditForm.addEventListener('submit', async (e) => {
|
||||||
@@ -46,18 +46,42 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
submitBtn.disabled = true;
|
submitBtn.disabled = true;
|
||||||
submitBtn.textContent = 'Transmitting...';
|
submitBtn.textContent = 'Transmitting...';
|
||||||
submitBtn.classList.add('opacity-75', 'cursor-not-allowed');
|
submitBtn.classList.add('opacity-75', 'cursor-not-allowed');
|
||||||
|
formStatus.classList.add('hidden');
|
||||||
|
|
||||||
// Mocking the POST to Formspree / VPS Endpoint (74.208.111.99)
|
const formData = new FormData(auditForm);
|
||||||
// In production, replace this setTimeout with a real fetch() POST
|
const payload = Object.fromEntries(formData.entries());
|
||||||
setTimeout(() => {
|
|
||||||
|
// API endpoint. Default: same-origin /api/audit (routed to the
|
||||||
|
// Node backend by Caddy on the VPS) — avoids mixed-content/CORS.
|
||||||
|
// Direct IP alt (local test / no proxy): http://74.208.111.99:8199/api/audit
|
||||||
|
const API_URL = (typeof window.DOP_API_URL !== 'undefined')
|
||||||
|
? window.DOP_API_URL
|
||||||
|
: '/api/audit';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(API_URL, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
formStatus.className = 'mt-4 p-4 rounded border text-sm border-green-300 bg-green-50 text-green-800';
|
formStatus.className = 'mt-4 p-4 rounded border text-sm border-green-300 bg-green-50 text-green-800';
|
||||||
formStatus.innerHTML = '<strong>Protocol Initiated:</strong> Your Layer 1a Cold Audit request has been received. A human analyst will review your entity footprint within 24 hours.';
|
formStatus.innerHTML = '<strong>Protocol Initiated:</strong> Your Layer 1a Cold Audit request has been received. A human analyst will review your entity footprint within 24 hours.';
|
||||||
formStatus.classList.remove('hidden');
|
|
||||||
auditForm.reset();
|
auditForm.reset();
|
||||||
|
} else {
|
||||||
|
throw new Error(result.message || 'Transmission failed');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
formStatus.className = 'mt-4 p-4 rounded border text-sm border-red-300 bg-red-50 text-red-800';
|
||||||
|
formStatus.innerHTML = `<strong>Transmission Error:</strong> ${error.message}. Please try again or contact us directly.`;
|
||||||
|
} finally {
|
||||||
|
formStatus.classList.remove('hidden');
|
||||||
submitBtn.textContent = 'Initiate Audit';
|
submitBtn.textContent = 'Initiate Audit';
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
submitBtn.classList.remove('opacity-75', 'cursor-not-allowed');
|
submitBtn.classList.remove('opacity-75', 'cursor-not-allowed');
|
||||||
}, 1500);
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user