badping_nagios_better/public/assets/js/script.js

32 строки
958 B
JavaScript
Исходник Обычный вид История

2019-11-11 22:45:36 +00:00
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)
});
};
2019-11-12 07:31:30 +00:00
d.querySelectorAll(".js-group-btn-delete").forEach(v => {
2019-11-11 22:45:36 +00:00
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")
2019-11-12 07:31:30 +00:00
});
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()
}
2019-11-11 22:45:36 +00:00
});