2025-01-14 10:49:44 +01:00
|
|
|
// This file handles the "Confirm instance details" dialog
|
|
|
|
|
2025-01-14 14:52:31 +01:00
|
|
|
import { findButtonOrFail, findFormOrFail, findImageOrFail, findInputOrFail, findSelectOrFail } from "./dom.mjs";
|
2025-01-14 10:49:44 +01:00
|
|
|
import knownSoftware from "./known_software.mjs";
|
|
|
|
|
|
|
|
const blankImage = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
|
|
|
|
2025-01-14 13:24:45 +01:00
|
|
|
export function initializeInstanceDetailsDialog(
|
|
|
|
dialog: HTMLDialogElement,
|
|
|
|
callback: (
|
|
|
|
instanceName: string,
|
|
|
|
instanceHost: string,
|
|
|
|
instanceHostSecure: boolean,
|
|
|
|
instanceSoftware: string,
|
|
|
|
instanceIcon: string | null
|
|
|
|
) => void
|
|
|
|
): {
|
2025-01-14 10:49:44 +01:00
|
|
|
showInstanceDetailsDialog: () => void,
|
|
|
|
hideInstanceDetailsDialog: () => void,
|
|
|
|
populateInstanceDetailsDialog: (
|
|
|
|
instanceNameValue: string,
|
2025-01-14 13:10:29 +01:00
|
|
|
instanceHostValue: string,
|
|
|
|
instanceHostSecureValue: boolean,
|
2025-01-14 10:49:44 +01:00
|
|
|
instanceSoftwareValue: string,
|
|
|
|
instanceIconValue: string | null
|
2025-01-14 13:24:45 +01:00
|
|
|
) => void
|
2025-01-14 10:49:44 +01:00
|
|
|
} {
|
|
|
|
const showInstanceDetailsDialog = () => dialog.showModal();
|
|
|
|
const hideInstanceDetailsDialog = () => dialog.close();
|
|
|
|
|
2025-01-14 14:52:31 +01:00
|
|
|
const form = findFormOrFail(dialog, ".instanceDetailsForm");
|
|
|
|
const instanceName = findInputOrFail(form, "#instanceName");
|
|
|
|
const instanceHost = findInputOrFail(form, "#instanceHost");
|
|
|
|
const instanceHostSecure = findInputOrFail(form, "#instanceHostSecure");
|
|
|
|
const instanceSoftware = findSelectOrFail(form, "#instanceSoftware");
|
|
|
|
const instanceIcon = findImageOrFail(form, "#instanceIcon");
|
|
|
|
const closeButton = findButtonOrFail(form, ".close");
|
2025-01-14 10:49:44 +01:00
|
|
|
|
|
|
|
for (const [name, software] of Object.entries(knownSoftware.software)) {
|
|
|
|
const option = new Option(software.name, name);
|
|
|
|
instanceSoftware.appendChild(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
instanceIcon.src = blankImage;
|
|
|
|
|
|
|
|
const populateInstanceDetailsDialog = (
|
|
|
|
instanceNameValue: string,
|
2025-01-14 13:10:29 +01:00
|
|
|
instanceHostValue: string,
|
|
|
|
instanceHostSecureValue: boolean,
|
2025-01-14 10:49:44 +01:00
|
|
|
instanceSoftwareValue: string,
|
|
|
|
instanceIconValue: string | null
|
|
|
|
) => {
|
|
|
|
instanceName.value = instanceNameValue;
|
2025-01-14 13:10:29 +01:00
|
|
|
instanceHost.value = instanceHostValue;
|
|
|
|
instanceHostSecure.checked = instanceHostSecureValue;
|
2025-01-14 10:49:44 +01:00
|
|
|
instanceSoftware.value = instanceSoftwareValue;
|
2025-01-31 15:58:10 +01:00
|
|
|
instanceIcon.src = instanceIconValue ?? blankImage;
|
2025-01-14 10:49:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
form.addEventListener("submit", e => {
|
2025-01-14 13:24:45 +01:00
|
|
|
callback(
|
|
|
|
instanceName.value,
|
|
|
|
instanceHost.value,
|
|
|
|
instanceHostSecure.checked,
|
|
|
|
instanceSoftware.value,
|
2025-01-31 15:58:10 +01:00
|
|
|
instanceIcon.src
|
2025-01-14 13:24:45 +01:00
|
|
|
);
|
2025-01-14 10:49:44 +01:00
|
|
|
form.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
closeButton.addEventListener("click", e => {
|
|
|
|
instanceIcon.src = blankImage;
|
|
|
|
hideInstanceDetailsDialog();
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
showInstanceDetailsDialog,
|
|
|
|
hideInstanceDetailsDialog,
|
|
|
|
populateInstanceDetailsDialog
|
|
|
|
};
|
|
|
|
}
|