Update samy.js
This commit is contained in:
69
samy.js
69
samy.js
@@ -260,6 +260,9 @@ async function fetchSites() {
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// Run Selected (main trigger)
|
||||
// =======================================================================
|
||||
// =======================================================================
|
||||
// Run Selected (main trigger)
|
||||
// =======================================================================
|
||||
@@ -273,11 +276,23 @@ async function triggerInstall() {
|
||||
if (statusBox) statusBox.innerHTML = "";
|
||||
|
||||
try {
|
||||
// Figure out which standard tasks are checked
|
||||
const checkedTasks = tasks.filter((t) => {
|
||||
const cb = document.getElementById(t.id);
|
||||
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) we’re 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
|
||||
const dattoCB = document.getElementById("installDattoRMM");
|
||||
@@ -329,13 +344,48 @@ async function triggerInstall() {
|
||||
console.error(`Error running ${t.id}:`, e);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Rename computer (LAST)
|
||||
if (renameCB && renameCB.checked && newNameInput) {
|
||||
const newName = newNameInput.value.trim();
|
||||
|
||||
// Same basic rules you’ll 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 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})`);
|
||||
console.info(
|
||||
`[Info] All tasks completed (${completedTasks}/${totalTasks})`
|
||||
);
|
||||
}
|
||||
|
||||
// Best-effort notification to the server
|
||||
try {
|
||||
await fetch("/tasksCompleted", { method: "POST" });
|
||||
} catch (err) {
|
||||
@@ -344,6 +394,7 @@ async function triggerInstall() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// Shutdown handler (Exit button & window close)
|
||||
// =======================================================================
|
||||
@@ -382,6 +433,20 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
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
|
||||
const taglines = [
|
||||
"Fast deployments, no monkey business.",
|
||||
|
||||
Reference in New Issue
Block a user