aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/admin-users.js
blob: b01c66afe265ebe080d90930fd182e89c316db65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export function initAdminUserListSearchForm() {
  const searchForm = window.config.PageData.adminUserListSearchForm;
  if (!searchForm) return;

  const $form = $('#user-list-search-form');
  if (!$form.length) return;

  $form.find(`button[name=sort][value=${searchForm.SortType}]`).addClass('active');

  if (searchForm.StatusFilterMap) {
    for (const [k, v] of Object.entries(searchForm.StatusFilterMap)) {
      if (!v) continue;
      $form.find(`input[name="status_filter[${k}]"][value=${v}]`).prop('checked', true);
    }
  }

  $form.find(`input[type=radio]`).click(() => {
    $form.submit();
    return false;
  });

  $form.find('.j-reset-status-filter').click(() => {
    $form.find(`input[type=radio]`).each((_, e) => {
      const $e = $(e);
      if ($e.attr('name').startsWith('status_filter[')) {
        $e.prop('checked', false);
      }
    });
    $form.submit();
    return false;
  });
}