- Consent giving UI introduced

- Possibility to view the document version the consent is given to
- Blocking functionality is no valid consent
This commit is contained in:
Josako
2025-10-15 18:35:28 +02:00
parent 3ea3a06de6
commit eeb76d57b7
22 changed files with 803 additions and 126 deletions

View File

@@ -0,0 +1,53 @@
// Centralized consent viewer JS
// Attaches a single delegated click handler to load consent markdown fragments
(function() {
function initConsentViewer() {
const viewerSection = document.getElementById('consent-viewer-section');
const viewer = document.getElementById('consent-document-viewer');
const vType = document.getElementById('viewer-type');
const vVer = document.getElementById('viewer-version');
const loading = document.getElementById('viewer-loading');
if (!viewerSection || !viewer) {
// Page without consent viewer; do nothing
return;
}
document.addEventListener('click', async function(e) {
const btn = e.target.closest('.btn-view-consent');
if (!btn) return;
e.preventDefault();
const url = btn.getAttribute('data-url');
const type = btn.getAttribute('data-consent-type') || '';
const version = btn.getAttribute('data-version') || '';
if (!url) {
console.warn('Consent viewer: data-url missing on button');
return;
}
try {
viewerSection.style.display = 'block';
if (vType) vType.textContent = type;
if (vVer) vVer.textContent = version;
if (loading) loading.style.display = 'block';
viewer.innerHTML = '';
const resp = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
const html = await resp.text();
viewer.innerHTML = html;
} catch (e) {
viewer.innerHTML = '<div class="alert alert-danger">Failed to load document.</div>';
} finally {
if (loading) loading.style.display = 'none';
viewerSection.scrollIntoView({ behavior: 'smooth' });
}
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initConsentViewer);
} else {
initConsentViewer();
}
})();