mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-31 07:12:23 -07:00
BE+FE: work on bulk deleting devices and code cleanup #1493
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -1,21 +1,5 @@
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function askDeleteDevice() {
|
||||
|
||||
mac = getMac()
|
||||
|
||||
// Ask delete device
|
||||
showModalWarning(
|
||||
getString("DevDetail_button_Delete"),
|
||||
getString("DevDetail_button_Delete_ask"),
|
||||
getString('Gen_Cancel'),
|
||||
getString('Gen_Delete'),
|
||||
'deleteDevice');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function askDelDevDTInline(mac) {
|
||||
function askDeleteDeviceByMac(mac) {
|
||||
|
||||
// only try getting mac from URL if not supplied - used in inline buttons on in the my devices listing pages
|
||||
if(isEmpty(mac))
|
||||
@@ -31,34 +15,9 @@ function askDelDevDTInline(mac) {
|
||||
() => deleteDeviceByMac(mac))
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function deleteDevice() {
|
||||
// Check MAC
|
||||
mac = getMac()
|
||||
|
||||
const apiBase = getApiBase();
|
||||
const apiToken = getSetting("API_TOKEN");
|
||||
const url = `${apiBase}/device/${mac}/delete`;
|
||||
|
||||
$.ajax({
|
||||
url,
|
||||
method: "DELETE",
|
||||
headers: { "Authorization": `Bearer ${apiToken}` },
|
||||
success: function(response) {
|
||||
showMessage(response.success ? "Device deleted successfully" : (response.error || "Unknown error"));
|
||||
updateApi("devices,appevents");
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("Error deleting device:", status, error);
|
||||
showMessage("Error: " + (xhr.responseJSON?.error || error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function deleteDeviceByMac(mac) {
|
||||
// only try getting mac from URL if not supplied - used in inline buttons on in teh my devices listing pages
|
||||
// only try getting mac from URL if not supplied - used in inline buttons on in the my devices listing pages
|
||||
if(isEmpty(mac))
|
||||
{
|
||||
mac = getMac()
|
||||
|
||||
Reference in New Issue
Block a user