23 строки
671 B
JavaScript
23 строки
671 B
JavaScript
|
let d = document;
|
||
|
let removeModel = (id, url) => {
|
||
|
let formData = new FormData();
|
||
|
formData.append("id", id || 0);
|
||
|
let xhr = new XMLHttpRequest();
|
||
|
xhr.open("POST", url);
|
||
|
xhr.send(formData);
|
||
|
xhr.onload = () => location.reload();
|
||
|
};
|
||
|
let deleteEvent = (v, message, url) => {
|
||
|
v.addEventListener("click", e => {
|
||
|
if (confirm(message))
|
||
|
removeModel(e.target.dataset.id, url)
|
||
|
});
|
||
|
};
|
||
|
|
||
|
d.querySelectorAll('.js-group-btn-delete').forEach(v => {
|
||
|
deleteEvent(v, "You're sure to delete this group?", "/groups/delete")
|
||
|
});
|
||
|
|
||
|
d.querySelectorAll(".js-server-btn-delete").forEach(v => {
|
||
|
deleteEvent(v, "You're sure to delete this server?", "/servers/delete")
|
||
|
});
|