Files
veripath/web/assets/js/main.js
T

87 lines
4.2 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
// Evidence Governance Toggle Logic
const approveBtn = document.getElementById('approve-btn');
const rejectBtn = document.getElementById('reject-btn');
const agentBadge = document.getElementById('agent-badge');
const finalBadge = document.getElementById('final-badge');
const statusText = document.getElementById('review-status');
if (approveBtn && rejectBtn) {
// Human Approves the Finding
approveBtn.addEventListener('click', () => {
agentBadge.className = 'badge-tier2 line-through opacity-50';
finalBadge.className = 'badge-tier1';
finalBadge.textContent = 'Tier 1 Verified (Human Approved)';
statusText.textContent = 'SUCCESS: Finding verified by human analyst. Promoted to Tier 1.';
statusText.className = 'text-green-400 text-sm mb-6 font-mono font-bold';
disableButtons();
});
// Human Rejects the Finding (Triggers the Fallback Protocol)
rejectBtn.addEventListener('click', () => {
agentBadge.className = 'badge-tier2';
finalBadge.className = 'badge-tier2';
finalBadge.textContent = 'Tier 2: Indicative (Fallback Applied)';
statusText.textContent = 'FALLBACK: Tier 1 rejected. Defaulted to Tier 2 as per governance protocol.';
statusText.className = 'text-yellow-400 text-sm mb-6 font-mono font-bold';
disableButtons();
});
}
function disableButtons() {
approveBtn.disabled = true;
rejectBtn.disabled = true;
approveBtn.classList.add('opacity-50', 'cursor-not-allowed');
rejectBtn.classList.add('opacity-50', 'cursor-not-allowed');
}
// --- COLD AUDIT FORM LOGIC (REAL BACKEND) ---
const auditForm = document.getElementById('audit-form');
if (auditForm) {
auditForm.addEventListener('submit', async (e) => {
e.preventDefault();
const submitBtn = document.getElementById('submit-btn');
const formStatus = document.getElementById('form-status');
submitBtn.disabled = true;
submitBtn.textContent = 'Transmitting...';
submitBtn.classList.add('opacity-75', 'cursor-not-allowed');
formStatus.classList.add('hidden');
const formData = new FormData(auditForm);
const payload = Object.fromEntries(formData.entries());
// 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.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.';
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.disabled = false;
submitBtn.classList.remove('opacity-75', 'cursor-not-allowed');
}
});
}
});