debug: add logging and robust init to app.js

This commit is contained in:
SW 2026-10-01 15:06:58 +02:00
parent a0ca704ac1
commit 4917bba468

View file

@ -1,7 +1,10 @@
document.addEventListener('DOMContentLoaded', function () { function initApp() {
console.log('sub-aligator app.js initialized');
// Open allocation modal // Open allocation modal
document.querySelectorAll('.allocate-btn').forEach(function (btn) { document.querySelectorAll('.allocate-btn').forEach(function (btn) {
btn.addEventListener('click', function () { btn.addEventListener('click', function () {
console.log('allocate-btn clicked', btn.dataset);
openAllocateModal(btn); openAllocateModal(btn);
}); });
}); });
@ -43,13 +46,23 @@ document.addEventListener('DOMContentLoaded', function () {
event.stopPropagation(); event.stopPropagation();
}); });
}); });
}); }
async function openAllocateModal(btn) { async function openAllocateModal(btn) {
const slug = btn.dataset.slug; const slug = btn.dataset.slug;
const name = btn.dataset.name; const name = btn.dataset.name;
const select = document.getElementById('prefix-' + slug); const select = document.getElementById('prefix-' + slug);
const prefixLength = select ? select.value : ''; let prefixLength = '';
if (select && select.value) {
prefixLength = select.value;
} else if (select && select.options.length > 0) {
prefixLength = select.options[0].value;
} else {
prefixLength = '24';
}
console.log('openAllocateModal', { slug: slug, name: name, prefixLength: prefixLength });
document.getElementById('modal-pool-slug').value = slug; document.getElementById('modal-pool-slug').value = slug;
document.getElementById('modal-prefix-length').value = prefixLength; document.getElementById('modal-prefix-length').value = prefixLength;
@ -72,8 +85,15 @@ async function openAllocateModal(btn) {
document.getElementById('modal-usable-hosts').textContent = usableHosts; document.getElementById('modal-usable-hosts').textContent = usableHosts;
document.getElementById('modal-warning').textContent = warning; document.getElementById('modal-warning').textContent = warning;
} catch (e) { } catch (e) {
console.error('preview fetch failed', e);
document.getElementById('modal-warning').textContent = 'Could not load preview.'; document.getElementById('modal-warning').textContent = 'Could not load preview.';
} }
document.getElementById('allocate-modal').style.display = 'flex'; document.getElementById('allocate-modal').style.display = 'flex';
} }
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initApp);
} else {
initApp();
}