Naive redirect implementation
This commit is contained in:
parent
af41b8e10b
commit
6861a549ac
2 changed files with 26 additions and 4 deletions
|
@ -28,7 +28,9 @@
|
|||
<br>
|
||||
<button onclick="showAddInstanceDialog()">Add an instance</button>
|
||||
</div>
|
||||
<div class="half-width"></div>
|
||||
<div class="half-width">
|
||||
<button id="redirect">Redirect</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { initializeAddInstanceFlow } from "./add_instance_flow.mjs";
|
||||
import { findDialogOrFail, findFormOrFail } from "./dom.mjs";
|
||||
import { findButtonOrFail, findDialogOrFail, findFormOrFail, findInputOrFail } from "./dom.mjs";
|
||||
import knownSoftware from "./known_software.mjs";
|
||||
import storageManager from "./storage_manager.mjs";
|
||||
|
||||
const radioButtonName = "instanceSelect";
|
||||
|
||||
export function getMainDialog(): HTMLDialogElement {
|
||||
return document.getElementById('mainDialog') as HTMLDialogElement;
|
||||
}
|
||||
|
@ -10,6 +12,7 @@ export function getMainDialog(): HTMLDialogElement {
|
|||
const detailsDialog = findDialogOrFail(document.body, "#instanceDetails");
|
||||
const addDialog = findDialogOrFail(document.body, "#addInstance");
|
||||
const instanceSelectForm = findFormOrFail(document.body, "#instanceSelectForm");
|
||||
const redirectButton = findButtonOrFail(document.body, "#redirect");
|
||||
|
||||
export const {
|
||||
showAddInstanceDialog,
|
||||
|
@ -23,8 +26,9 @@ function createInstanceSelectOptions() {
|
|||
div.setAttribute("x-option", instance.origin);
|
||||
const radio = document.createElement("input");
|
||||
radio.id = instance.origin;
|
||||
radio.value = instance.origin;
|
||||
radio.type = "radio";
|
||||
radio.name = "instanceSelect";
|
||||
radio.name = radioButtonName;
|
||||
const label = document.createElement("label");
|
||||
label.htmlFor = instance.origin;
|
||||
label.innerText = instance.name + " ";
|
||||
|
@ -44,8 +48,24 @@ function createInstanceSelectOptions() {
|
|||
instanceSelectForm.appendChild(div);
|
||||
}
|
||||
const firstInput = instanceSelectForm.querySelector("input");
|
||||
if (firstInput) firstInput.checked = true;
|
||||
if (firstInput) {
|
||||
firstInput.checked = true;
|
||||
redirectButton.disabled = false;
|
||||
} else {
|
||||
redirectButton.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
createInstanceSelectOptions();
|
||||
storageManager.addSaveCallback(createInstanceSelectOptions);
|
||||
|
||||
function redirect() {
|
||||
// Can be assumed to not fail because the button is disabled if there are no options and the first one is selected by default
|
||||
const option = findInputOrFail(instanceSelectForm, `input[name="${radioButtonName}"]:checked`).value;
|
||||
const url = URL.parse(option)!;
|
||||
const currentURL = URL.parse(location.href)!;
|
||||
url.pathname = currentURL.pathname.replace(/\/.*?\//, "/");
|
||||
location.href = url.toString();
|
||||
}
|
||||
|
||||
redirectButton.addEventListener("click", e => redirect());
|
||||
|
|
Loading…
Add table
Reference in a new issue