location list fix
This commit is contained in:
78
app/assets/js/locations-list.js
Normal file
78
app/assets/js/locations-list.js
Normal file
@@ -0,0 +1,78 @@
|
||||
(() => {
|
||||
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() {
|
||||
if (confirm('Dieses Gebaeude wirklich loeschen? Alle Stockwerke werden geloescht.')) {
|
||||
alert('Loeschen noch nicht implementiert');
|
||||
}
|
||||
}
|
||||
|
||||
function handleFloorDelete() {
|
||||
if (confirm('Dieses Stockwerk wirklich loeschen? Alle Raeume und Racks werden geloescht.')) {
|
||||
alert('Loeschen noch nicht implementiert');
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
})();
|
||||
Reference in New Issue
Block a user