Send the address path with the key setup and point to the settings when it is locked (section 25)
This commit is contained in:
1 parent
52588d66a5
commit
5c4b0e5c4c
1 file changed
+18
-3
+18
-3
@@ -11,6 +11,7 @@ function slot(number) {
|
|||||||
return {
|
return {
|
||||||
name: form.querySelector(`[name="key_${number}_name"]`),
|
name: form.querySelector(`[name="key_${number}_name"]`),
|
||||||
type: form.querySelector(`[name="key_${number}_type"]`),
|
type: form.querySelector(`[name="key_${number}_type"]`),
|
||||||
|
addressPath: form.querySelector(`[name="key_${number}_address_path"]`),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,11 +19,12 @@ function fillSlot(number, key) {
|
|||||||
const fields = slot(number);
|
const fields = slot(number);
|
||||||
fields.name.value = key.name;
|
fields.name.value = key.name;
|
||||||
fields.type.value = key.type;
|
fields.type.value = key.type;
|
||||||
|
fields.addressPath.value = key.address_path || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function lockForm() {
|
function lockForm() {
|
||||||
// The names and the types are locked once the setup is saved, so nothing on
|
// The setup is written once, so nothing on the page can change it afterwards
|
||||||
// the page can change them afterwards (section 23.2).
|
// (sections 23.2 and 25.1).
|
||||||
for (const field of form.querySelectorAll("input, select, button")) {
|
for (const field of form.querySelectorAll("input, select, button")) {
|
||||||
field.disabled = true;
|
field.disabled = true;
|
||||||
}
|
}
|
||||||
@@ -36,11 +38,24 @@ function collectSetup() {
|
|||||||
key_number: number,
|
key_number: number,
|
||||||
name: fields.name.value.trim(),
|
name: fields.name.value.trim(),
|
||||||
type: fields.type.value,
|
type: fields.type.value,
|
||||||
|
address_path: fields.addressPath.value.trim(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { keys: entries };
|
return { keys: entries };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showLockedState() {
|
||||||
|
// The type and the address path are locked with the setup, while the name is
|
||||||
|
// only a label that the settings may change (sections 25.1 and 25.2).
|
||||||
|
const note = document.createElement("span");
|
||||||
|
note.textContent = "The key setup is already saved. The type and the address path are locked; the key names can be changed in the settings. ";
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.className = "back-link";
|
||||||
|
link.href = "/settings";
|
||||||
|
link.textContent = "Open settings";
|
||||||
|
status.replaceChildren(note, link);
|
||||||
|
}
|
||||||
|
|
||||||
async function loadSetup() {
|
async function loadSetup() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/setup", { headers: { Accept: "application/json" } });
|
const response = await fetch("/api/setup", { headers: { Accept: "application/json" } });
|
||||||
@@ -55,7 +70,7 @@ async function loadSetup() {
|
|||||||
// The stored keys arrive in key order, so the slot number is their index.
|
// The stored keys arrive in key order, so the slot number is their index.
|
||||||
(setup.keys || []).forEach((key, index) => fillSlot(index + 1, key));
|
(setup.keys || []).forEach((key, index) => fillSlot(index + 1, key));
|
||||||
lockForm();
|
lockForm();
|
||||||
status.textContent = "The key setup is already saved. The names and the types are locked.";
|
showLockedState();
|
||||||
} catch {
|
} catch {
|
||||||
lockForm();
|
lockForm();
|
||||||
status.textContent = "The key setup could not be loaded. Reload the page or contact the service administrator.";
|
status.textContent = "The key setup could not be loaded. Reload the page or contact the service administrator.";
|
||||||
|
|||||||
Reference in new issue
Block a user