feat: complete package 2 delete flows and package 3 port management
This commit is contained in:
@@ -25,6 +25,47 @@ if (!$exists) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$forceDelete = (int)($_POST['force'] ?? $_GET['force'] ?? 0) === 1;
|
||||
$dependencyCounts = $sql->single(
|
||||
"SELECT
|
||||
(SELECT COUNT(*) FROM rooms WHERE floor_id = ?) AS room_count,
|
||||
(SELECT COUNT(*) FROM racks WHERE floor_id = ?) AS rack_count,
|
||||
(SELECT COUNT(*) FROM floor_patchpanels WHERE floor_id = ?) AS patchpanel_count",
|
||||
"iii",
|
||||
[$id, $id, $id]
|
||||
);
|
||||
|
||||
$roomCount = (int)($dependencyCounts['room_count'] ?? 0);
|
||||
$rackCount = (int)($dependencyCounts['rack_count'] ?? 0);
|
||||
$patchpanelCount = (int)($dependencyCounts['patchpanel_count'] ?? 0);
|
||||
$hasDependencies = $roomCount > 0 || $rackCount > 0 || $patchpanelCount > 0;
|
||||
|
||||
if ($hasDependencies && !$forceDelete) {
|
||||
$parts = [];
|
||||
if ($roomCount > 0) {
|
||||
$parts[] = $roomCount . ' Raeume';
|
||||
}
|
||||
if ($rackCount > 0) {
|
||||
$parts[] = $rackCount . ' Racks';
|
||||
}
|
||||
if ($patchpanelCount > 0) {
|
||||
$parts[] = $patchpanelCount . ' Patchpanels';
|
||||
}
|
||||
|
||||
http_response_code(409);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'requires_force' => true,
|
||||
'message' => 'Beim Loeschen werden abhaengige Daten entfernt (' . implode(', ', $parts) . '). Fortfahren?',
|
||||
'dependencies' => [
|
||||
'rooms' => $roomCount,
|
||||
'racks' => $rackCount,
|
||||
'patchpanels' => $patchpanelCount
|
||||
]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $sql->set("DELETE FROM floors WHERE id = ?", "i", [$id]);
|
||||
if ($rows === false) {
|
||||
http_response_code(500);
|
||||
@@ -32,5 +73,13 @@ if ($rows === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Stockwerk geloescht']);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Stockwerk geloescht',
|
||||
'dependencies' => [
|
||||
'rooms' => $roomCount,
|
||||
'racks' => $rackCount,
|
||||
'patchpanels' => $patchpanelCount
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
@@ -233,11 +233,20 @@ $buildings = $sql->get("SELECT id, name FROM buildings ORDER BY name", "", []);
|
||||
|
||||
<script>
|
||||
function confirmDelete(id) {
|
||||
if (confirm('Dieses Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
|
||||
if (!confirm('Dieses Stockwerk wirklich loeschen?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestDelete = (forceDelete) => {
|
||||
const body = ['id=' + encodeURIComponent(id)];
|
||||
if (forceDelete) {
|
||||
body.push('force=1');
|
||||
}
|
||||
|
||||
fetch('?module=floors&action=delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: 'id=' + encodeURIComponent(id)
|
||||
body: body.join('&')
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
@@ -245,12 +254,22 @@ function confirmDelete(id) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data && data.requires_force) {
|
||||
if (confirm(data.message || 'Abhaengige Daten ebenfalls loeschen?')) {
|
||||
requestDelete(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => {
|
||||
alert('Loeschen fehlgeschlagen');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
requestDelete(false);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user