diff --git a/index.html b/index.html
index 8661424..2adf6a7 100644
--- a/index.html
+++ b/index.html
@@ -1016,8 +1016,10 @@
-
-
+
+
@@ -1039,7 +1041,9 @@
-
+
diff --git a/script.js b/script.js
index 98c3852..90c33b7 100644
--- a/script.js
+++ b/script.js
@@ -3129,7 +3129,7 @@ function renderIpam() {
${esc(e.verkko || '-')}${drillBtn} |
${esc(e.nimi || '-')} |
- ${e.vlan_id ? '' + e.vlan_id + '' : '-'} |
+ ${vlanRefHtml(e.vlan_id)} |
${e.site_name ? esc(e.site_name) : '—'} |
${tilaLabel[e.tila] || e.tila} |
${esc(e.asiakas || '-')} |
@@ -3168,11 +3168,10 @@ function renderIpamVlans(query) {
const tilaClass = { vapaa: 'ipam-tila-vapaa', varattu: 'ipam-tila-varattu', reserved: 'ipam-tila-reserved' };
const tilaLabel = { vapaa: 'Vapaa', varattu: 'Varattu', reserved: 'Reserved' };
- if (vlans.length === 0 && !query) {
- tbody.innerHTML = '';
- if (section) section.style.display = 'none';
+ if (section) section.style.display = '';
+ if (vlans.length === 0) {
+ tbody.innerHTML = '| Ei VLANeja vielä. |
';
} else {
- if (section) section.style.display = '';
tbody.innerHTML = vlans.map(e => `
| ${e.vlan_id || '-'} |
${esc(e.verkko || '-')} |
@@ -3189,6 +3188,33 @@ function renderIpamVlans(query) {
document.getElementById('ipam-vlan-count').textContent = vlans.length + ' VLANia';
}
+// --- VLAN-viite apufunktio ---
+function vlanRefHtml(vlanId) {
+ if (!vlanId) return '—';
+ const vl = ipamData.find(v => v.tyyppi === 'vlan' && String(v.vlan_id) === String(vlanId));
+ const label = vl ? esc(vl.nimi) : '';
+ return `${vlanId}${label ? ` ${label}` : ''}`;
+}
+
+// --- VLAN-dropdown populointi ---
+function populateVlanDropdown(selectedVlanId) {
+ const sel = document.getElementById('ipam-form-vlan');
+ const vlans = ipamData.filter(e => e.tyyppi === 'vlan').sort((a, b) => (a.vlan_id || 0) - (b.vlan_id || 0));
+ sel.innerHTML = '' +
+ vlans.map(v => ``).join('');
+}
+
+// --- Asiakas-dropdown populointi ---
+async function populateIpamCustomerDropdown(selectedName) {
+ if (!customers || customers.length === 0) {
+ try { customers = await apiCall('customers'); } catch(e) {}
+ }
+ const sel = document.getElementById('ipam-form-asiakas');
+ const sorted = [...customers].sort((a, b) => (a.nimi || '').localeCompare(b.nimi || ''));
+ sel.innerHTML = '' +
+ sorted.map(c => ``).join('');
+}
+
// --- Toggle & Drill ---
function ipamToggle(id) {
if (ipamExpandedIds.has(id)) ipamExpandedIds.delete(id);
@@ -3225,14 +3251,14 @@ async function editIpam(id) {
document.getElementById('ipam-form-id').value = e.id;
document.getElementById('ipam-form-tyyppi').value = e.tyyppi || 'ip';
document.getElementById('ipam-form-verkko').value = e.verkko || '';
- document.getElementById('ipam-form-vlan').value = e.vlan_id || '';
document.getElementById('ipam-form-nimi').value = e.nimi || '';
document.getElementById('ipam-form-tila').value = e.tila || 'vapaa';
- document.getElementById('ipam-form-asiakas').value = e.asiakas || '';
document.getElementById('ipam-form-lisatiedot').value = e.lisatiedot || '';
+ populateVlanDropdown(e.vlan_id || '');
+ await populateIpamCustomerDropdown(e.asiakas || '');
await loadIpamSitesDropdown();
document.getElementById('ipam-form-site').value = e.site_id || '';
- document.getElementById('ipam-modal-title').textContent = 'Muokkaa IPAM-merkintää';
+ document.getElementById('ipam-modal-title').textContent = e.tyyppi === 'vlan' ? 'Muokkaa VLANia' : 'Muokkaa verkkoa / IP:tä';
document.getElementById('ipam-modal').style.display = 'flex';
}
@@ -3248,6 +3274,8 @@ document.getElementById('btn-add-ipam')?.addEventListener('click', async () => {
document.getElementById('ipam-form-id').value = '';
document.getElementById('ipam-form').reset();
document.getElementById('ipam-form-tyyppi').value = 'subnet';
+ populateVlanDropdown('');
+ await populateIpamCustomerDropdown('');
await loadIpamSitesDropdown();
document.getElementById('ipam-modal-title').textContent = 'Lisää verkko / IP';
document.getElementById('ipam-modal').style.display = 'flex';
@@ -3257,6 +3285,8 @@ document.getElementById('btn-add-vlan')?.addEventListener('click', async () => {
document.getElementById('ipam-form-id').value = '';
document.getElementById('ipam-form').reset();
document.getElementById('ipam-form-tyyppi').value = 'vlan';
+ populateVlanDropdown('');
+ await populateIpamCustomerDropdown('');
await loadIpamSitesDropdown();
document.getElementById('ipam-modal-title').textContent = 'Lisää VLAN';
document.getElementById('ipam-modal').style.display = 'flex';