debug: add logging and robust init to app.js
This commit is contained in:
parent
a0ca704ac1
commit
4917bba468
1 changed files with 23 additions and 3 deletions
|
|
@ -1,7 +1,10 @@
|
|||
document.addEventListener('DOMContentLoaded', function () {
|
||||
function initApp() {
|
||||
console.log('sub-aligator app.js initialized');
|
||||
|
||||
// Open allocation modal
|
||||
document.querySelectorAll('.allocate-btn').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
console.log('allocate-btn clicked', btn.dataset);
|
||||
openAllocateModal(btn);
|
||||
});
|
||||
});
|
||||
|
|
@ -43,13 +46,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
event.stopPropagation();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function openAllocateModal(btn) {
|
||||
const slug = btn.dataset.slug;
|
||||
const name = btn.dataset.name;
|
||||
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-prefix-length').value = prefixLength;
|
||||
|
|
@ -72,8 +85,15 @@ async function openAllocateModal(btn) {
|
|||
document.getElementById('modal-usable-hosts').textContent = usableHosts;
|
||||
document.getElementById('modal-warning').textContent = warning;
|
||||
} catch (e) {
|
||||
console.error('preview fetch failed', e);
|
||||
document.getElementById('modal-warning').textContent = 'Could not load preview.';
|
||||
}
|
||||
|
||||
document.getElementById('allocate-modal').style.display = 'flex';
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initApp);
|
||||
} else {
|
||||
initApp();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue