forked from gitea/gitea
1
0
Fork 0

Remove jQuery from the user search form in admin page (#29151)

- Switched to plain JavaScript
- Tested the form and it works as before

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Yarden Shoham 2024-02-13 16:13:06 +02:00 committed by GitHub
parent 6fad2c8744
commit a8748eedae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 20 deletions

View File

@ -1,34 +1,39 @@
import $ from 'jquery';
export function initAdminUserListSearchForm() { export function initAdminUserListSearchForm() {
const searchForm = window.config.pageData.adminUserListSearchForm; const searchForm = window.config.pageData.adminUserListSearchForm;
if (!searchForm) return; if (!searchForm) return;
const $form = $('#user-list-search-form'); const form = document.querySelector('#user-list-search-form');
if (!$form.length) return; if (!form) return;
$form.find(`button[name=sort][value=${searchForm.SortType}]`).addClass('active'); for (const button of form.querySelectorAll(`button[name=sort][value="${searchForm.SortType}"]`)) {
button.classList.add('active');
}
if (searchForm.StatusFilterMap) { if (searchForm.StatusFilterMap) {
for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) { for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) {
if (!v) continue; if (!v) continue;
$form.find(`input[name="status_filter[${k}]"][value=${v}]`).prop('checked', true); for (const input of form.querySelectorAll(`input[name="status_filter[${k}]"][value="${v}"]`)) {
input.checked = true;
}
} }
} }
$form.find(`input[type=radio]`).on('click', () => { for (const radio of form.querySelectorAll('input[type=radio]')) {
$form.trigger('submit'); radio.addEventListener('click', () => {
return false; form.submit();
});
$form.find('.j-reset-status-filter').on('click', () => {
$form.find(`input[type=radio]`).each((_, e) => {
const $e = $(e);
if ($e.attr('name').startsWith('status_filter[')) {
$e.prop('checked', false);
}
}); });
$form.trigger('submit'); }
return false;
}); const resetButtons = form.querySelectorAll('.j-reset-status-filter');
for (const button of resetButtons) {
button.addEventListener('click', (e) => {
e.preventDefault();
for (const input of form.querySelectorAll('input[type=radio]')) {
if (input.name.startsWith('status_filter[')) {
input.checked = false;
}
}
form.submit();
});
}
} }