diff --git a/app/assets/js/device-type-edit-form.js b/app/assets/js/device-type-edit-form.js new file mode 100644 index 0000000..57a785d --- /dev/null +++ b/app/assets/js/device-type-edit-form.js @@ -0,0 +1,88 @@ +(() => { + function addPortRow() { + const body = document.getElementById('port-definition-body'); + if (!body) { + return; + } + + const emptyRow = body.querySelector('tr td em'); + if (emptyRow) { + const emptyTableRow = emptyRow.closest('tr'); + if (emptyTableRow) { + emptyTableRow.remove(); + } + } + + const rowCount = body.querySelectorAll('tr').length; + const index = rowCount; + const number = rowCount + 1; + + const optionsTemplate = document.getElementById('port-type-options-template'); + const portTypeOptions = optionsTemplate + ? optionsTemplate.innerHTML + : ''; + + const row = document.createElement('tr'); + row.innerHTML = ` + ${number} + + + + + + + + + + + `; + + body.appendChild(row); + } + + function bindAddPortRowButton() { + const addButton = document.getElementById('add-port-row'); + if (!addButton || addButton.dataset.portRowBound === '1') { + return; + } + addButton.addEventListener('click', addPortRow); + addButton.dataset.portRowBound = '1'; + } + + function bindDeleteButton() { + const deleteButton = document.getElementById('device-type-delete'); + if (!deleteButton || deleteButton.dataset.deleteBound === '1') { + return; + } + + deleteButton.addEventListener('click', () => { + const id = Number(deleteButton.dataset.deviceTypeId || '0'); + if (id <= 0) { + return; + } + + if (window.confirm('Diesen Gerätetyp wirklich löschen? Alle zugeordneten Geräte werden angepasst.')) { + // TODO: Delete-Endpoint/Flow ist noch nicht implementiert. + window.alert('Löschen noch nicht implementiert'); + } + }); + + deleteButton.dataset.deleteBound = '1'; + } + + function init() { + bindAddPortRowButton(); + bindDeleteButton(); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', init); + } else { + init(); + } +})(); diff --git a/app/modules/device_types/edit.php b/app/modules/device_types/edit.php index fa4373a..981b826 100644 --- a/app/modules/device_types/edit.php +++ b/app/modules/device_types/edit.php @@ -304,6 +304,12 @@ $pageTitle = $isEdit ? "Gerätetyp bearbeiten: " . htmlspecialchars($deviceType[ +
@@ -319,73 +325,17 @@ $pageTitle = $isEdit ? "Gerätetyp bearbeiten: " . htmlspecialchars($deviceType[ Abbrechen - Löschen +
- - - - +