97 lines
3.5 KiB
JavaScript
97 lines
3.5 KiB
JavaScript
(() => {
|
|
function postDelete(url) {
|
|
return fetch(url, {
|
|
method: 'POST',
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
|
}).then((response) => response.json());
|
|
}
|
|
|
|
function handleLocationDelete(id) {
|
|
if (!confirm('Diesen Standort wirklich loeschen?')) {
|
|
return;
|
|
}
|
|
postDelete('?module=locations&action=delete&id=' + encodeURIComponent(id))
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => alert('Loeschen fehlgeschlagen'));
|
|
}
|
|
|
|
function handleBuildingDelete(id) {
|
|
if (!confirm('Dieses Gebaeude wirklich loeschen? Alle Stockwerke werden geloescht.')) {
|
|
return;
|
|
}
|
|
postDelete('?module=buildings&action=delete&id=' + encodeURIComponent(id))
|
|
.then((data) => {
|
|
if (data && (data.success || data.status === 'ok')) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && (data.message || data.error)) ? (data.message || data.error) : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => alert('Loeschen fehlgeschlagen'));
|
|
}
|
|
|
|
function handleFloorDelete(id) {
|
|
if (!confirm('Dieses Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
|
|
return;
|
|
}
|
|
postDelete('?module=floors&action=delete&id=' + encodeURIComponent(id))
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => alert('Loeschen fehlgeschlagen'));
|
|
}
|
|
|
|
function handleRoomDelete(id) {
|
|
if (!confirm('Diesen Raum wirklich loeschen? Zugeordnete Dosen werden mitgeloescht.')) {
|
|
return;
|
|
}
|
|
postDelete('?module=rooms&action=delete&id=' + encodeURIComponent(id))
|
|
.then((data) => {
|
|
if (data && data.success) {
|
|
window.location.reload();
|
|
return;
|
|
}
|
|
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
|
})
|
|
.catch(() => alert('Loeschen fehlgeschlagen'));
|
|
}
|
|
|
|
function bindDeleteButtons() {
|
|
document.querySelectorAll('.js-delete-location').forEach((button) => {
|
|
button.addEventListener('click', () => {
|
|
handleLocationDelete(Number(button.dataset.locationId || 0));
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.js-delete-building').forEach((button) => {
|
|
button.addEventListener('click', () => {
|
|
handleBuildingDelete(Number(button.dataset.buildingId || 0));
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.js-delete-floor').forEach((button) => {
|
|
button.addEventListener('click', () => {
|
|
handleFloorDelete(Number(button.dataset.floorId || 0));
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.js-delete-room').forEach((button) => {
|
|
button.addEventListener('click', () => {
|
|
handleRoomDelete(Number(button.dataset.roomId || 0));
|
|
});
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', bindDeleteButtons);
|
|
})();
|