Update samy.js
This commit is contained in:
85
samy.js
85
samy.js
@@ -459,6 +459,7 @@ async function installSelectedPrinters() {
|
|||||||
// =======================================================================
|
// =======================================================================
|
||||||
// Run Selected (main trigger)
|
// Run Selected (main trigger)
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|
||||||
async function triggerInstall() {
|
async function triggerInstall() {
|
||||||
const runBtn = document.querySelector(".run-button");
|
const runBtn = document.querySelector(".run-button");
|
||||||
if (!runBtn) return;
|
if (!runBtn) return;
|
||||||
@@ -469,46 +470,41 @@ async function triggerInstall() {
|
|||||||
if (statusBox) statusBox.innerHTML = "";
|
if (statusBox) statusBox.innerHTML = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Figure out which standard tasks are checked
|
// Grab special-case elements ONCE
|
||||||
|
const dattoCB = document.getElementById("installDattoRMM");
|
||||||
|
const svsCB = document.getElementById("installSVSMSPModule");
|
||||||
|
const renameCB = document.getElementById("renameComputer");
|
||||||
|
const newNameInput = document.getElementById("txtNewComputerName");
|
||||||
|
|
||||||
|
// Standard tasks are all tasks EXCEPT special-case ones
|
||||||
const checkedTasks = tasks.filter((t) => {
|
const checkedTasks = tasks.filter((t) => {
|
||||||
if (["installDattoRMM", "installSVSMSPModule", "renameComputer"].includes(t.id)) return false;
|
if (["installDattoRMM", "installSVSMSPModule", "renameComputer"].includes(t.id)) return false;
|
||||||
const cb = document.getElementById(t.id);
|
const cb = document.getElementById(t.id);
|
||||||
return cb && cb.checked;
|
return cb && cb.checked;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rename checkbox / textbox
|
// Count special-case tasks
|
||||||
const renameCB = document.getElementById("renameComputer");
|
|
||||||
const newNameInput = document.getElementById("txtNewComputerName");
|
|
||||||
|
|
||||||
// Count special-case tasks (handled outside the main loop)
|
|
||||||
let specialTasks = 0;
|
let specialTasks = 0;
|
||||||
|
|
||||||
const dattoCB = document.getElementById("installDattoRMM");
|
|
||||||
if (dattoCB && dattoCB.checked) specialTasks++;
|
if (dattoCB && dattoCB.checked) specialTasks++;
|
||||||
|
|
||||||
const svsCB = document.getElementById("installSVSMSPModule");
|
|
||||||
if (svsCB && svsCB.checked) specialTasks++;
|
if (svsCB && svsCB.checked) specialTasks++;
|
||||||
|
|
||||||
// Rename is also a special-case task
|
const extraTasks = (renameCB && renameCB.checked) ? 1 : 0;
|
||||||
const renameCB = document.getElementById("renameComputer");
|
|
||||||
let extraTasks = 0;
|
|
||||||
if (renameCB && renameCB.checked) extraTasks = 1;
|
|
||||||
|
|
||||||
if ((checkedTasks.length + specialTasks + extraTasks) === 0) {
|
const total = checkedTasks.length + specialTasks + extraTasks;
|
||||||
|
|
||||||
|
if (total === 0) {
|
||||||
alert("Please select at least one task.");
|
alert("Please select at least one task.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTotalTaskCount(total);
|
||||||
|
|
||||||
setTotalTaskCount(checkedTasks.length + specialTasks + extraTasks);
|
// 1) DattoRMM first
|
||||||
|
|
||||||
|
|
||||||
// 1. DattoRMM first
|
|
||||||
const dattoCB = document.getElementById("installDattoRMM");
|
|
||||||
if (dattoCB && dattoCB.checked) {
|
if (dattoCB && dattoCB.checked) {
|
||||||
const sub = Array.from(
|
const sub = Array.from(
|
||||||
document.querySelectorAll(".sub-option-installDattoRMM:checked")
|
document.querySelectorAll(".sub-option-installDattoRMM:checked")
|
||||||
).map((x) => x.value);
|
).map((x) => x.value);
|
||||||
|
|
||||||
const dropdown = document.getElementById("dattoDropdown");
|
const dropdown = document.getElementById("dattoDropdown");
|
||||||
const uid = dropdown?.value;
|
const uid = dropdown?.value;
|
||||||
const name = dropdown?.selectedOptions?.[0]?.text || "Datto";
|
const name = dropdown?.selectedOptions?.[0]?.text || "Datto";
|
||||||
@@ -531,8 +527,7 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. SVSMSP module second
|
// 2) SVSMSP module second
|
||||||
const svsCB = document.getElementById("installSVSMSPModule");
|
|
||||||
if (svsCB && svsCB.checked) {
|
if (svsCB && svsCB.checked) {
|
||||||
try {
|
try {
|
||||||
await fetch("/installSVSMSPModule", { method: "GET" });
|
await fetch("/installSVSMSPModule", { method: "GET" });
|
||||||
@@ -543,7 +538,7 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Remaining tasks
|
// 3) Remaining tasks
|
||||||
for (const t of tasks) {
|
for (const t of tasks) {
|
||||||
if (["installDattoRMM", "installSVSMSPModule", "renameComputer"].includes(t.id)) continue;
|
if (["installDattoRMM", "installSVSMSPModule", "renameComputer"].includes(t.id)) continue;
|
||||||
|
|
||||||
@@ -559,54 +554,14 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Rename computer (LAST)
|
// 4) Rename computer (LAST)
|
||||||
if (renameCB && renameCB.checked && newNameInput) {
|
if (renameCB && renameCB.checked && newNameInput) {
|
||||||
const newName = newNameInput.value.trim();
|
const newName = newNameInput.value.trim();
|
||||||
|
|
||||||
// Same basic rules you'll enforce server-side
|
|
||||||
const nameIsValid =
|
const nameIsValid =
|
||||||
newName.length > 0 &&
|
newName.length > 0 &&
|
||||||
newName.length <= 15 &&
|
newName.length <= 15 &&
|
||||||
/^[A-Za-z0-9-]+$/.test(newName);
|
/^[A-Za-z]()
|
||||||
|
|
||||||
if (!nameIsValid) {
|
|
||||||
alert(
|
|
||||||
"Invalid computer name. Must be 1-15 characters and only letters, numbers, and hyphens."
|
|
||||||
);
|
|
||||||
// still mark it as a failed task so progress reaches 100%
|
|
||||||
logProgress("Rename computer", false);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
await fetch("/renameComputer", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ newName }),
|
|
||||||
});
|
|
||||||
logProgress("Rename computer", true);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error calling /renameComputer:", e);
|
|
||||||
logProgress("Rename computer", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("triggerInstall fatal error:", e);
|
|
||||||
} finally {
|
|
||||||
runBtn.disabled = false;
|
|
||||||
if (totalTasks > 0) {
|
|
||||||
console.info(
|
|
||||||
`[Info] All tasks completed (${completedTasks}/${totalTasks})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Best-effort notification to the server
|
|
||||||
try {
|
|
||||||
await fetch("/tasksCompleted", { method: "POST" });
|
|
||||||
} catch (err) {
|
|
||||||
console.warn("Could not notify server about completion:", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user