in ui/changes/src/common.js [2466:2576]
export async function setupOptions(callback) {
await buildMetabugsDropdown(callback);
await buildProductsSelect();
await buildTeamsSelect();
await buildComponentsSelect();
await populateVersions();
await buildTypesSelect();
await buildSeveritiesSelect();
setTableHeaderHandlers(callback);
await setTableToggleHandler(callback);
const url = new URL(location.href);
for (const optionName in options) {
let optionType = getOptionType(optionName);
let elem = document.getElementById(optionName);
if (!elem) {
continue;
}
let queryValues = url.searchParams.getAll(optionName);
if (optionType === "text") {
if (queryValues.length != 0) {
elem.value = queryValues[0];
}
await setOption(optionName, elem.value, false);
elem.addEventListener("change", async function () {
if (!(await setOption(optionName, elem.value))) {
await callback();
}
});
} else if (optionType === "checkbox") {
if (queryValues.length != 0) {
elem.checked = queryValues[0] != "0" && queryValues[0] != "false";
}
await setOption(optionName, elem.checked, false);
elem.onchange = async function () {
if (!(await setOption(optionName, elem.checked))) {
await callback();
}
};
} else if (optionType === "select") {
if (queryValues.length != 0) {
for (const option of elem.options) {
option.selected = queryValues.includes(option.value);
}
}
let value = [];
for (let option of elem.options) {
if (option.selected) {
value.push(option.value);
}
}
await setOption(optionName, value, false);
elem.onchange = async function () {
let value = [];
for (let option of elem.options) {
if (option.selected) {
value.push(option.value);
}
}
if (!(await setOption(optionName, value))) {
await callback();
}
};
} else if (optionType === "radio") {
if (queryValues.length != 0) {
for (const radio of document.querySelectorAll(
`input[name=${optionName}]`
)) {
radio.checked = radio.value == queryValues[0];
}
}
for (const radio of document.querySelectorAll(
`input[name=${optionName}]`
)) {
if (radio.checked) {
await setOption(optionName, radio.value, false);
}
}
elem.onchange = async function () {
let waitDependent = false;
for (const radio of document.querySelectorAll(
`input[name=${optionName}]`
)) {
if (radio.checked) {
waitDependent |= await setOption(optionName, radio.value);
}
}
if (!waitDependent) {
await callback();
}
};
} else {
throw new Error("Unexpected option type.");
}
}
}