Fix multi-deletion of DHCP leases

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2024-06-03 09:38:56 +02:00
parent 75f54ff76a
commit 2d12a28a56
2 changed files with 26 additions and 14 deletions

View File

@@ -163,7 +163,7 @@ function deleteLease() {
function delLease(ip) {
utils.disableAll();
utils.showAlert("info", "", "Deleting lease...");
const toast = utils.showAlert("info", "", "Deleting lease...", ip, null);
$.ajax({
url: "/api/dhcp/leases/" + encodeURIComponent(ip),
@@ -172,10 +172,10 @@ function delLease(ip) {
.done(function (response) {
utils.enableAll();
if (response === undefined) {
utils.showAlert("success", "far fa-trash-alt", "Successfully deleted lease", "");
utils.showAlert("success", "far fa-trash-alt", "Successfully deleted lease", ip, toast);
dhcpLeaesTable.ajax.reload(null, false);
} else {
utils.showAlert("error", "", "Error while deleting lease: " + ip, response.lease);
utils.showAlert("error", "", "Error while deleting lease: " + ip, response.lease, toast);
}
// Clear selection after deletion
@@ -184,7 +184,7 @@ function delLease(ip) {
})
.fail(function (jqXHR, exception) {
utils.enableAll();
utils.showAlert("error", "", "Error while deleting lease: " + ip, jqXHR.responseText);
utils.showAlert("error", "", "Error while deleting lease: " + ip, jqXHR.responseText, toast);
console.log(exception); // eslint-disable-line no-console
});
}

View File

@@ -84,7 +84,7 @@ function padNumber(num) {
}
var showAlertBox = null;
function showAlert(type, icon, title, message) {
function showAlert(type, icon, title, message, toast) {
const options = {
title: "&nbsp;<strong>" + escapeHtml(title) + "</strong><br>",
message: escapeHtml(message),
@@ -138,16 +138,28 @@ function showAlert(type, icon, title, message) {
return;
}
if (type === "info") {
// Create a new notification for info boxes
showAlertBox = $.notify(options, settings);
} else if (showAlertBox !== null) {
// Update existing notification for other boxes (if available)
showAlertBox.update(options);
showAlertBox.update(settings);
if (toast === undefined) {
if (type === "info") {
// Create a new notification for info boxes
showAlertBox = $.notify(options, settings);
return showAlertBox;
} else if (showAlertBox !== null) {
// Update existing notification for other boxes (if available)
showAlertBox.update(options);
showAlertBox.update(settings);
return showAlertBox;
} else {
// Create a new notification for other boxes if no previous info box exists
return $.notify(options, settings);
}
} else if (toast === null) {
// Always create a new toast
return $.notify(options, settings);
} else {
// Create a new notification for other boxes if no previous info box exists
$.notify(options, settings);
// Update existing toast
toast.update(options);
toast.update(settings);
return toast;
}
}