feat: complete package 2 delete flows and package 3 port management
This commit is contained in:
@@ -2,12 +2,19 @@
|
||||
/**
|
||||
* app/modules/connections/delete.php
|
||||
*
|
||||
* Loescht eine Verbindung und leitet zur Liste zurueck.
|
||||
* Loescht eine Verbindung (AJAX-POST bevorzugt, GET-Fallback fuer Redirects).
|
||||
*/
|
||||
|
||||
$connectionId = (int)($_GET['id'] ?? $_POST['id'] ?? 0);
|
||||
$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST';
|
||||
$connectionId = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
|
||||
|
||||
if ($connectionId <= 0) {
|
||||
if ($isPost) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Ungueltige Verbindungs-ID']);
|
||||
exit;
|
||||
}
|
||||
$_SESSION['error'] = 'Ungueltige Verbindungs-ID';
|
||||
header('Location: ?module=connections&action=list');
|
||||
exit;
|
||||
@@ -20,6 +27,12 @@ $connection = $sql->single(
|
||||
);
|
||||
|
||||
if (!$connection) {
|
||||
if ($isPost) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'message' => 'Verbindung nicht gefunden']);
|
||||
exit;
|
||||
}
|
||||
$_SESSION['error'] = 'Verbindung nicht gefunden';
|
||||
header('Location: ?module=connections&action=list');
|
||||
exit;
|
||||
@@ -31,6 +44,17 @@ $rows = $sql->set(
|
||||
[$connectionId]
|
||||
);
|
||||
|
||||
if ($isPost) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
if ($rows > 0) {
|
||||
echo json_encode(['success' => true, 'message' => 'Verbindung geloescht']);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Verbindung konnte nicht geloescht werden']);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($rows > 0) {
|
||||
$_SESSION['success'] = 'Verbindung geloescht';
|
||||
} else {
|
||||
|
||||
@@ -335,11 +335,12 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st
|
||||
<a href="<?php echo htmlspecialchars($buildListUrl(['connection_id' => $connId])); ?>" class="button button-small">Details</a>
|
||||
<a href="?module=connections&action=edit&id=<?php echo $connId; ?>" class="button button-small">Bearbeiten</a>
|
||||
<a href="?module=connections&action=swap&id=<?php echo $connId; ?>" class="button button-small" onclick="return confirm('Von/Nach fuer diese Verbindung vertauschen?');">Von/Nach tauschen</a>
|
||||
<a href="?module=connections&action=delete&id=<?php echo $connId; ?>" class="button button-small button-danger"
|
||||
data-confirm-delete="true"
|
||||
data-confirm-message="Diese Verbindung wirklich loeschen?">
|
||||
<button
|
||||
type="button"
|
||||
class="button button-small button-danger js-connection-delete"
|
||||
data-connection-id="<?php echo $connId; ?>">
|
||||
Loeschen
|
||||
</a>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -382,7 +383,12 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st
|
||||
<div class="sidebar-actions">
|
||||
<a href="?module=connections&action=edit&id=<?php echo $selectedConnId; ?>" class="button button-small">Bearbeiten</a>
|
||||
<a href="?module=connections&action=swap&id=<?php echo $selectedConnId; ?>" class="button button-small" onclick="return confirm('Von/Nach fuer diese Verbindung vertauschen?');">Tauschen</a>
|
||||
<a href="?module=connections&action=delete&id=<?php echo $selectedConnId; ?>" class="button button-small button-danger" data-confirm-delete="true" data-confirm-message="Diese Verbindung wirklich loeschen?">Loeschen</a>
|
||||
<button
|
||||
type="button"
|
||||
class="button button-small button-danger js-connection-delete"
|
||||
data-connection-id="<?php echo $selectedConnId; ?>">
|
||||
Loeschen
|
||||
</button>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p><em>Keine Verbindung ausgewaehlt.</em></p>
|
||||
@@ -474,3 +480,35 @@ $buildListUrl = static function (array $extra = []) use ($search, $deviceId): st
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.js-connection-delete').forEach((button) => {
|
||||
button.addEventListener('click', () => {
|
||||
const id = Number(button.dataset.connectionId || '0');
|
||||
if (id <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm('Diese Verbindung wirklich loeschen?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('?module=connections&action=delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: 'id=' + encodeURIComponent(id)
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data && data.success) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => alert('Loeschen fehlgeschlagen'));
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user