attempt to fix dattoRMM sub items

This commit is contained in:
2025-05-26 21:17:01 -04:00
parent a995b16e62
commit ac207c2e7c

View File

@@ -505,7 +505,13 @@ $style = @'
// ======================================================================= // =======================================================================
async function fetchSites() { async function fetchSites() {
const pwd = document.getElementById("Password").value; const pwd = document.getElementById("Password").value;
if (!pwd) { alert("Please enter the password."); return; } if (!pwd) {
alert("Please enter the password.");
return;
}
const dropdown = document.getElementById("dattoDropdown");
dropdown.innerHTML = '<option disabled selected>Loading sites...</option>';
try { try {
const resp = await fetch("/getpw", { const resp = await fetch("/getpw", {
@@ -513,27 +519,31 @@ $style = @'
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ password: pwd }) body: JSON.stringify({ password: pwd })
}); });
if (!resp.ok) throw("HTTP " + resp.status); if (!resp.ok) throw("HTTP " + resp.status);
const sites = await resp.json(); const sites = await resp.json();
const dd = document.getElementById("dattoDropdown"); dropdown.innerHTML = ''; // clear the loading message
dd.innerHTML = ""; // clear old
sites.forEach(s => { sites.forEach(site => {
const opt = document.createElement("option"); const option = document.createElement("option");
opt.value = s.UID; option.value = site.UID;
opt.text = s.Name; option.textContent = site.Name;
dd.appendChild(opt); dropdown.appendChild(option);
}); });
document.getElementById("dattoRmmContainer").style.display = "block"; document.getElementById("dattoRmmContainer").style.display = "block";
} }
catch (e) { catch (e) {
console.error(e); console.error(e);
dropdown.innerHTML = '<option disabled selected>Error loading sites</option>';
alert("Failed to fetch sites. Check password and try again."); alert("Failed to fetch sites. Check password and try again.");
} }
} }
async function triggerInstall() { async function triggerInstall() {
for (const t of tasks) { for (const t of tasks) {
const cb = document.getElementById(t.id); const cb = document.getElementById(t.id);
@@ -602,17 +612,13 @@ $htmlTemplate = @"
</div> </div>
<!-- 1) password & fetch button -->
<div id="PasswordContainer" style="margin-bottom:1em;">
<label for="Password">Password:</label>
<input type="password" id="Password" placeholder="Enter password" />
<button onclick="fetchSites()">Fetch Sites</button>
</div>
<!-- 2) Datto RMM dropdown (populated after fetch) --> <!-- 2) Datto RMM dropdown (populated after fetch) -->
<div id="dattoRmmContainer" style="display:none; margin-bottom:1em;"> <div id="dattoRmmContainer" style="display:none; margin-bottom:1em;">
<label for="dattoDropdown">Select Datto Site:</label> <label for="dattoDropdown">Select Datto Site:</label>
<select id="dattoDropdown"></select> <select id="dattoDropdown">
<option disabled selected hidden>Select a site...</option>
</select>
</div> </div>
<div id="offboardTab" class="tab-content"> <div id="offboardTab" class="tab-content">