/* ========================= RESOURCE MODAL ========================= */ window.openCreate = function(){ document.getElementById("modalTitle").innerText = "Create Resource" document.getElementById("resource_id").value = "" document.querySelectorAll("#resourceModal input, #resourceModal textarea") .forEach(e => e.value = "") document.getElementById("status").value = "aktiv" openModal("resourceModal") } window.openEdit = function(resource){ document.getElementById("modalTitle").innerText="Edit Resource" document.getElementById("resource_id").value=resource.id Object.keys(resource).forEach(k=>{ const el=document.getElementById(k) if(el) el.value=resource[k] || "" }) document.getElementById("resourceModal").style.display="block" } window.closeModal = function(){ closeModalById("resourceModal") } window.openServerDetail = async function(resource){ const mappings = await api(API+"/domainmap") const subs = await api(API+"/subdomains") let html = ` Name: ${resource.name}
Produkt: ${resource.produkt || ""}
Provider: ${resource.provider || ""}
Provider Name: ${resource.providername || ""}

System
CPU: ${resource.cpu || ""}
RAM: ${resource.ram || ""}
Disk: ${resource.disk || ""}
OS: ${resource.os || ""}

IPs
` // IPs if(Array.isArray(resource.ips)){ resource.ips.forEach(ip=>{ html += `
${ip.type || ""} ${ip.ip}
` }) } // Domains html += `
Domains
` const domains = mappings.filter(m => m.resource_id == resource.id) domains.forEach(d=>{ html += `
🌐 ${d.domain_name}
` // Subdomains dazu subs.forEach(s => { if(s.domain_name === d.domain_name){ html += `
↳ ${s.subdomain}.${s.domain_name}
` } }) }) // Zusatzinfos html += `
Bestelldatum: ${resource.bestelldatum || ""}
Kündbar ab: ${resource.kuendbar_ab || ""}

Bemerkung
${resource.bemerkung || ""} ` document.getElementById("serverDetailContent").innerHTML = html document.getElementById("serverDetailModal").style.display="block" } window.closeServerDetail = function(){ document.getElementById("serverDetailModal").style.display="none" } /* ========================= DOMAIN MODAL ========================= */ window.openDomainCreate = function(){ document.getElementById("domainModalTitle").innerText = "Create Domain" document.getElementById("domainModalMeta").innerText = "Neue Domain anlegen" document.getElementById("domain_id").value = "" document.getElementById("domain_name").value = "" document.getElementById("domain_provider").value = "" document.getElementById("domain_ip").value = "" document.getElementById("domain_cost").value = "" document.getElementById("domain_notes").value = "" document.getElementById("domainSaveBtn").innerText = "Create" openModal("domainModal") document.getElementById("domain_name").focus() } window.openDomainEdit = function(d){ document.getElementById("domainModalTitle").innerText="Edit Domain" document.getElementById("domainModalMeta").innerText=d.domain_name || "" document.getElementById("domain_id").value=d.id document.getElementById("domain_name").value=d.domain_name || "" document.getElementById("domain_provider").value=d.provider || "" document.getElementById("domain_ip").value=d.ip_address || "" document.getElementById("domain_cost").value=d.yearly_cost || "" document.getElementById("domain_notes").value=d.notes || "" document.getElementById("domainSaveBtn").innerText = "Update" document.getElementById("domainModal").style.display="block" document.getElementById("domain_name").focus() } window.closeDomainModal = function(){ closeModalById("domainModal") } /* ========================= SUBDOMAIN MODAL ========================= */ window.openSubCreate = function(domainId){ const domains = window.domainList || [] const domain = domains.find(d => d.id == domainId) const domainName = domain?.domain_name || "Unbekannte Domain" document.getElementById("sub_id").value = "" // RESET !! document.getElementById("sub_domain_id").value = domainId document.getElementById("sub_name").value = "" document.getElementById("sub_ip").value = domain?.ip_address || "" document.querySelector("#subdomainModal h3").innerText = "Subdomain erstellen" document.getElementById("subdomainModalMeta").innerText = "Fuer " + domainName document.getElementById("subdomainSaveBtn").innerText = "Create" document.getElementById("subdomainModal").style.display="block" document.getElementById("sub_name").focus() } window.closeSubModal = function(){ closeModalById("subdomainModal") } window.openSubEdit = function(s){ const fullName = s.subdomain + "." + s.domain_name document.getElementById("sub_id").value = s.id document.getElementById("sub_domain_id").value = s.domain_id document.getElementById("sub_name").value = s.subdomain document.getElementById("sub_ip").value = s.ip_address document.querySelector("#subdomainModal h3").innerText = "Subdomain bearbeiten" document.getElementById("subdomainModalMeta").innerText = fullName document.getElementById("subdomainSaveBtn").innerText = "Update" document.getElementById("subdomainModal").style.display="block" document.getElementById("sub_name").focus() } /* ========================= IP MODAL ========================= */ window.openIPManager = function(resourceId){ document.getElementById("ip_resource_id").value = resourceId openModal("ipModal") loadIPs(resourceId) } window.closeIPModal = function(){ closeModalById("ipModal") } /*======================== Neu Global Modal =========================*/ window.openModal = function(id){ document.getElementById(id).style.display = "block" } window.closeModalById = function(id){ const el = document.getElementById(id) if(el){ el.style.display = "none" } } document.addEventListener("keydown", function(e){ if(e.key === "Escape"){ document.querySelectorAll(".modal").forEach(m => { m.style.display = "none" }) } }) window.addEventListener("click", function(e){ document.querySelectorAll(".modal").forEach(m => { if(e.target === m){ m.style.display = "none" } }) })