Update samy.js

This commit is contained in:
2025-12-01 02:53:27 -05:00
parent 59afd9687d
commit 5553b86156

69
samy.js
View File

@@ -260,6 +260,9 @@ async function fetchSites() {
} }
} }
// =======================================================================
// Run Selected (main trigger)
// =======================================================================
// ======================================================================= // =======================================================================
// Run Selected (main trigger) // Run Selected (main trigger)
// ======================================================================= // =======================================================================
@@ -273,11 +276,23 @@ async function triggerInstall() {
if (statusBox) statusBox.innerHTML = ""; if (statusBox) statusBox.innerHTML = "";
try { try {
// Figure out which standard tasks are checked
const checkedTasks = tasks.filter((t) => { const checkedTasks = tasks.filter((t) => {
const cb = document.getElementById(t.id); const cb = document.getElementById(t.id);
return cb && cb.checked; return cb && cb.checked;
}); });
setTotalTaskCount(checkedTasks.length);
// Rename checkbox / textbox
const renameCB = document.getElementById("chkRenameComputer");
const newNameInput = document.getElementById("txtNewComputerName");
// Count how many "extra" tasks (rename) were doing
let extraTasks = 0;
if (renameCB && renameCB.checked) {
extraTasks = 1; // treat rename as one task in the progress counter
}
setTotalTaskCount(checkedTasks.length + extraTasks);
// 1. DattoRMM first // 1. DattoRMM first
const dattoCB = document.getElementById("installDattoRMM"); const dattoCB = document.getElementById("installDattoRMM");
@@ -329,13 +344,48 @@ async function triggerInstall() {
console.error(`Error running ${t.id}:`, e); console.error(`Error running ${t.id}:`, e);
} }
} }
// 4. Rename computer (LAST)
if (renameCB && renameCB.checked && newNameInput) {
const newName = newNameInput.value.trim();
// Same basic rules youll enforce server-side
const nameIsValid =
newName.length > 0 &&
newName.length <= 15 &&
/^[A-Za-z0-9-]+$/.test(newName);
if (!nameIsValid) {
alert(
"Invalid computer name. Must be 115 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) { } catch (e) {
console.error("triggerInstall fatal error:", e); console.error("triggerInstall fatal error:", e);
} finally { } finally {
runBtn.disabled = false; runBtn.disabled = false;
if (totalTasks > 0) { if (totalTasks > 0) {
console.info(`[Info] All tasks completed (${completedTasks}/${totalTasks})`); console.info(
`[Info] All tasks completed (${completedTasks}/${totalTasks})`
);
} }
// Best-effort notification to the server
try { try {
await fetch("/tasksCompleted", { method: "POST" }); await fetch("/tasksCompleted", { method: "POST" });
} catch (err) { } catch (err) {
@@ -344,6 +394,7 @@ async function triggerInstall() {
} }
} }
// ======================================================================= // =======================================================================
// Shutdown handler (Exit button & window close) // Shutdown handler (Exit button & window close)
// ======================================================================= // =======================================================================
@@ -382,6 +433,20 @@ document.addEventListener("DOMContentLoaded", () => {
updateVisibility(); updateVisibility();
}); });
// NEW: Rename computer checkbox -> show/hide text box
const renameCheckbox = document.getElementById("chkRenameComputer");
const renameBlock = document.getElementById("renameComputerBlock");
if (renameCheckbox && renameBlock) {
function updateRenameVisibility() {
renameBlock.style.display = renameCheckbox.checked ? "block" : "none";
}
renameCheckbox.addEventListener("change", updateRenameVisibility);
// Ensure correct initial state on load
updateRenameVisibility();
}
// Tagline rotation // Tagline rotation
const taglines = [ const taglines = [
"Fast deployments, no monkey business.", "Fast deployments, no monkey business.",