diff --git a/testTaskGate.ps1 b/testTaskGate.ps1 index 43279aa..4925888 100644 --- a/testTaskGate.ps1 +++ b/testTaskGate.ps1 @@ -500,40 +500,50 @@ $style = @' }); - // ======================================================================= - // Fetch Sites Handler - // ======================================================================= - async function fetchSites() { - const pwd = document.getElementById("Password").value; - if (!pwd) { alert("Please enter the password."); return; } + // ======================================================================= + // Fetch Sites Handler + // ======================================================================= + async function fetchSites() { + const pwd = document.getElementById("Password").value; + if (!pwd) { + alert("Please enter the password."); + return; + } - try { + const dropdown = document.getElementById("dattoDropdown"); + dropdown.innerHTML = ''; + + try { const resp = await fetch("/getpw", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ password: pwd }) + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ password: pwd }) }); + if (!resp.ok) throw("HTTP " + resp.status); const sites = await resp.json(); - const dd = document.getElementById("dattoDropdown"); - dd.innerHTML = ""; // clear old - sites.forEach(s => { - const opt = document.createElement("option"); - opt.value = s.UID; - opt.text = s.Name; - dd.appendChild(opt); + dropdown.innerHTML = ''; // clear the loading message + + sites.forEach(site => { + const option = document.createElement("option"); + option.value = site.UID; + option.textContent = site.Name; + dropdown.appendChild(option); }); + document.getElementById("dattoRmmContainer").style.display = "block"; - } - catch (e) { + } + catch (e) { console.error(e); + dropdown.innerHTML = ''; alert("Failed to fetch sites. Check password and try again."); - } + } } + async function triggerInstall() { for (const t of tasks) { const cb = document.getElementById(t.id); @@ -602,18 +612,14 @@ $htmlTemplate = @" - -