2024-11-11 04:13:57 -07:00
|
|
|
export function initAdminUserListSearchForm(): void {
|
2021-10-14 20:35:26 -06:00
|
|
|
const searchForm = window.config.pageData.adminUserListSearchForm;
|
2021-10-12 12:11:35 -06:00
|
|
|
if (!searchForm) return;
|
|
|
|
|
2024-11-11 04:13:57 -07:00
|
|
|
const form = document.querySelector<HTMLFormElement>('#user-list-search-form');
|
2024-02-13 07:13:06 -07:00
|
|
|
if (!form) return;
|
2021-10-12 12:11:35 -06:00
|
|
|
|
2024-02-13 07:13:06 -07:00
|
|
|
for (const button of form.querySelectorAll(`button[name=sort][value="${searchForm.SortType}"]`)) {
|
|
|
|
button.classList.add('active');
|
|
|
|
}
|
2021-10-12 12:11:35 -06:00
|
|
|
|
|
|
|
if (searchForm.StatusFilterMap) {
|
|
|
|
for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) {
|
|
|
|
if (!v) continue;
|
2024-11-11 04:13:57 -07:00
|
|
|
for (const input of form.querySelectorAll<HTMLInputElement>(`input[name="status_filter[${k}]"][value="${v}"]`)) {
|
2024-02-13 07:13:06 -07:00
|
|
|
input.checked = true;
|
|
|
|
}
|
2021-10-12 12:11:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-11 04:13:57 -07:00
|
|
|
for (const radio of form.querySelectorAll<HTMLInputElement>('input[type=radio]')) {
|
2024-02-13 07:13:06 -07:00
|
|
|
radio.addEventListener('click', () => {
|
|
|
|
form.submit();
|
|
|
|
});
|
|
|
|
}
|
2021-10-12 12:11:35 -06:00
|
|
|
|
2024-11-11 04:13:57 -07:00
|
|
|
const resetButtons = form.querySelectorAll<HTMLAnchorElement>('.j-reset-status-filter');
|
2024-02-13 07:13:06 -07:00
|
|
|
for (const button of resetButtons) {
|
|
|
|
button.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
2024-11-11 04:13:57 -07:00
|
|
|
for (const input of form.querySelectorAll<HTMLInputElement>('input[type=radio]')) {
|
2024-02-13 07:13:06 -07:00
|
|
|
if (input.name.startsWith('status_filter[')) {
|
|
|
|
input.checked = false;
|
|
|
|
}
|
2021-10-12 12:11:35 -06:00
|
|
|
}
|
2024-02-13 07:13:06 -07:00
|
|
|
form.submit();
|
2021-10-12 12:11:35 -06:00
|
|
|
});
|
2024-02-13 07:13:06 -07:00
|
|
|
}
|
2021-10-12 12:11:35 -06:00
|
|
|
}
|