IP Manager überarbeitet
This commit is contained in:
@@ -15,9 +15,17 @@ window.loadResources = async function(){
|
||||
let ips = ""
|
||||
|
||||
if(Array.isArray(r.ips)){
|
||||
ips = r.ips.map(ip =>
|
||||
"<span class='ip'>" + (ip.type || "") + " " + ip.ip + "</span>"
|
||||
).join("")
|
||||
ips = r.ips.map(ip => {
|
||||
const cls = (ip.type || "").toLowerCase().includes("public")
|
||||
? "ip public"
|
||||
: "ip"
|
||||
|
||||
return "<span class='" + cls + "'>" +
|
||||
(ip.type || "") + " " + ip.ip +
|
||||
"</span>"
|
||||
|
||||
}).join("")
|
||||
|
||||
}
|
||||
|
||||
let domains = mappings
|
||||
@@ -163,3 +171,141 @@ window.loadCancelled = async function(){
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
window.saveIP = async function(){
|
||||
|
||||
const resourceId = document.getElementById("ip_resource_id").value
|
||||
|
||||
const ipField = document.getElementById("new_ip")
|
||||
const id = ipField.dataset.editId
|
||||
|
||||
const ip = ipField.value
|
||||
const type = document.getElementById("new_type").value
|
||||
const comment = document.getElementById("new_comment").value
|
||||
|
||||
if(id){
|
||||
// 🔥 UPDATE
|
||||
await api(API + "/ips/" + id, {
|
||||
method: "PUT",
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ip, type, comment})
|
||||
})
|
||||
|
||||
delete ipField.dataset.editId
|
||||
|
||||
}else{
|
||||
// 🔥 CREATE
|
||||
|
||||
try{
|
||||
const result = await api(API + "/ipcheck/" + ip)
|
||||
|
||||
if(result.length){
|
||||
if(!confirm("IP existiert bereits. Trotzdem speichern?")){
|
||||
return
|
||||
}
|
||||
}
|
||||
}catch(e){}
|
||||
|
||||
await api(API + "/resources/" + resourceId + "/ips", {
|
||||
method: "POST",
|
||||
headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ip, type, comment})
|
||||
})
|
||||
}
|
||||
|
||||
// Felder reset
|
||||
ipField.value = ""
|
||||
document.getElementById("new_type").value = ""
|
||||
document.getElementById("new_comment").value = ""
|
||||
|
||||
loadIPs(resourceId)
|
||||
loadResources()
|
||||
cancelIPEdit()
|
||||
}
|
||||
|
||||
|
||||
window.deleteIP = async function(id, resourceId){
|
||||
|
||||
if(!confirm("IP löschen?")) return
|
||||
|
||||
await api(API + "/ips/" + id, {
|
||||
method: "DELETE"
|
||||
})
|
||||
|
||||
loadIPs(resourceId) // Modal neu laden
|
||||
loadResources() // Tabelle aktualisieren
|
||||
|
||||
}
|
||||
|
||||
window.loadIPs = async function(resourceId){
|
||||
|
||||
const ips = await api(API + "/resources/" + resourceId + "/ips")
|
||||
|
||||
const container = document.getElementById("ipList")
|
||||
container.innerHTML = ""
|
||||
|
||||
ips.forEach(ip => {
|
||||
|
||||
// ✅ HIER rein!
|
||||
const cls = (ip.type || "").toLowerCase().includes("public")
|
||||
? "ip public"
|
||||
: "ip"
|
||||
|
||||
const div = document.createElement("div")
|
||||
|
||||
div.innerHTML = `
|
||||
<span class="${cls}">
|
||||
${ip.ip} (${ip.type || ""}) ${ip.comment || ""}
|
||||
</span>
|
||||
|
||||
<button onclick="editIP(${ip.id}, '${ip.ip}', '${ip.type || ""}', '${ip.comment || ""}')">
|
||||
Edit
|
||||
</button>
|
||||
|
||||
<button onclick="deleteIP(${ip.id}, ${resourceId})">
|
||||
Delete
|
||||
</button>
|
||||
`
|
||||
|
||||
container.appendChild(div)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.editIP = function(id, ip, type, comment){
|
||||
|
||||
document.getElementById("new_ip").value = ip
|
||||
document.getElementById("new_type").value = type
|
||||
document.getElementById("new_comment").value = comment
|
||||
|
||||
document.getElementById("new_ip").dataset.editId = id
|
||||
|
||||
// 👇 UX Highlight + Fokus
|
||||
document.getElementById("ipForm").classList.add("edit-mode")
|
||||
document.getElementById("ipSaveBtn").innerText = "Update"
|
||||
document.getElementById("ipCancelBtn").style.display = "inline-block"
|
||||
|
||||
document.getElementById("new_ip").focus() // 👈 HIER
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
window.cancelIPEdit = function(){
|
||||
|
||||
const ipField = document.getElementById("new_ip")
|
||||
|
||||
delete ipField.dataset.editId
|
||||
|
||||
ipField.value = ""
|
||||
document.getElementById("new_type").value = ""
|
||||
document.getElementById("new_comment").value = ""
|
||||
|
||||
document.getElementById("ipForm").classList.remove("edit-mode")
|
||||
document.getElementById("ipSaveBtn").innerText = "Add"
|
||||
document.getElementById("ipCancelBtn").style.display = "none"
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user