WIP: device löschen

This commit is contained in:
2026-02-13 11:55:18 +01:00
parent 0a7505416e
commit 39f7f9b733
6 changed files with 182 additions and 19 deletions

View File

@@ -24,6 +24,40 @@ if ($deviceId > 0) {
$isEdit = !empty($device);
$pageTitle = $isEdit ? "Gerät bearbeiten: " . htmlspecialchars($device['name']) : "Neues Gerät";
$dependencyCounts = [
'port_count' => 0,
'module_count' => 0,
'connection_count' => 0
];
if ($isEdit) {
$dependencyCounts = $sql->single(
"SELECT
(
SELECT COUNT(*)
FROM device_ports dp
WHERE dp.device_id = ?
) AS port_count,
(
SELECT COUNT(*)
FROM device_port_modules dpm
JOIN device_ports dp2 ON dp2.id = dpm.device_port_id
WHERE dp2.device_id = ?
) AS module_count,
(
SELECT COUNT(*)
FROM connections c
WHERE (c.port_a_type = 'device' AND c.port_a_id IN (
SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = ?
))
OR (c.port_b_type = 'device' AND c.port_b_id IN (
SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = ?
))
) AS connection_count",
"iiii",
[$deviceId, $deviceId, $deviceId, $deviceId]
) ?: $dependencyCounts;
}
// =========================
// Optionen laden
@@ -133,7 +167,7 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
<button type="submit" class="button button-primary">Speichern</button>
<a href="?module=devices&action=list" class="button">Abbrechen</a>
<?php if ($isEdit): ?>
<a href="#" class="button button-danger" onclick="confirmDelete(<?php echo $deviceId; ?>)">Löschen</a>
<a href="?module=devices&action=delete&id=<?php echo (int)$deviceId; ?>" class="button button-danger" onclick="return confirmDelete(event, <?php echo (int)$deviceId; ?>, <?php echo (int)$dependencyCounts['connection_count']; ?>, <?php echo (int)$dependencyCounts['port_count']; ?>, <?php echo (int)$dependencyCounts['module_count']; ?>)">Löschen</a>
<?php endif; ?>
</fieldset>
@@ -233,9 +267,37 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
</style>
<script>
function confirmDelete(id) {
if (confirm('Dieses Gerät wirklich löschen?')) {
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id);
function confirmDelete(event, id, connectionCount, portCount, moduleCount) {
if (event && typeof event.preventDefault === 'function') {
event.preventDefault();
}
if (confirm('Dieses Gerät wirklich löschen?')) {
const hasDependencies = (connectionCount > 0) || (portCount > 0) || (moduleCount > 0);
if (hasDependencies) {
const details = [];
if (connectionCount > 0) {
details.push(connectionCount + ' Verbindungen');
}
if (portCount > 0) {
details.push(portCount + ' Ports');
}
if (moduleCount > 0) {
details.push(moduleCount + ' Port-Module');
}
const dependencyMessage = 'Es gibt abhängige Daten (' + details.join(', ') + '). Diese auch löschen?';
if (!confirm(dependencyMessage)) {
return false;
}
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id) + '&force=1';
return false;
}
window.location.href = '?module=devices&action=delete&id=' + encodeURIComponent(id);
return false;
}
return false;
}
</script>