32 строки
958 B
JavaScript
32 строки
958 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")
|
|
});
|
|
|
|
d.querySelector(".js-server-form-on-submit").addEventListener("submit", e=>{
|
|
let check_ip = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
let ip = e.target.ip;
|
|
if (!check_ip.exec(ip.value)){
|
|
e.preventDefault()
|
|
ip.focus()
|
|
}
|
|
}); |