html += '
'; // Reports To section if (w.manager_name || w.supervisor_name) { html += '
'; } html += '
| Name | Issuer | Issue Date | Expiry | Status | |
|---|---|---|---|---|---|
| ' + esc(cert.name) + ' | ' + esc(cert.issuer||'—') + ' | '; html += '' + (cert.issue_date ? new Date(cert.issue_date).toLocaleDateString() : '—') + ' | '; html += '' + (cert.expiry_date ? new Date(cert.expiry_date).toLocaleDateString() : '—') + ' | '; html += '' + certBadge(cert.expiry_date) + ' | '; html += '
'; main.innerHTML = html; } let editingCertId = null; function openCertModal(cert) { editingCertId = cert ? cert.id : null; document.getElementById("cert-modal").style.display = "flex"; document.getElementById("cert-modal-title").textContent = cert ? "Edit Certification" : "Add Certification"; document.getElementById("cert-name").value = cert ? cert.name : ""; document.getElementById("cert-issuer").value = cert ? (cert.issuer||"") : ""; document.getElementById("cert-number").value = cert ? (cert.certificate_number||"") : ""; document.getElementById("cert-issue-date").value = cert ? (cert.issue_date ? cert.issue_date.substring(0,10) : "") : ""; document.getElementById("cert-expiry-date").value = cert ? (cert.expiry_date ? cert.expiry_date.substring(0,10) : "") : ""; } function closeCertModal() { document.getElementById("cert-modal").style.display = "none"; editingCertId = null; } async function editCert(id) { const certs = await apiGet("/my-certifications").catch(() => []); const cert = (Array.isArray(certs) ? certs : []).find(c => c.id === id); if (cert) openCertModal(cert); } async function saveCert() { const body = { name: document.getElementById("cert-name").value.trim(), issuer: document.getElementById("cert-issuer").value.trim() || null, certificate_number: document.getElementById("cert-number").value.trim() || null, issue_date: document.getElementById("cert-issue-date").value || null, expiry_date: document.getElementById("cert-expiry-date").value || null }; if (!body.name) { toast("Certification name is required", "danger"); return; } try { if (editingCertId) { await api("/api/my-certifications/" + editingCertId, { method: "PATCH", body: JSON.stringify(body) }); toast("Certification updated"); } else { await api("/api/my-certifications", { method: "POST", body: JSON.stringify(body) }); toast("Certification added"); } closeCertModal(); loadMyProfile(); } catch(e) { toast(e.message, "danger"); } }