summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/filtered_search/dropdown_user.js
blob: f1e7be6bde1c0ac5d6cd6e5cda706856524ad659 (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
33
34
35
36
37
38
39
import { addClassIfElementExists } from '../lib/utils/dom_utils';
import DropdownAjaxFilter from './dropdown_ajax_filter';

export default class DropdownUser extends DropdownAjaxFilter {
  constructor(options = {}) {
    super({
      ...options,
      endpoint: '/autocomplete/users.json',
      symbol: '@',
    });
  }

  ajaxFilterConfig() {
    return {
      ...super.ajaxFilterConfig(),
      params: {
        active: true,
        group_id: this.getGroupId(),
        project_id: this.getProjectId(),
        current_user: true,
      },
      onLoadingFinished: () => {
        this.hideCurrentUser();
      },
    };
  }

  hideCurrentUser() {
    addClassIfElementExists(this.dropdown.querySelector('.js-current-user'), 'hidden');
  }

  getGroupId() {
    return this.input.getAttribute('data-group-id');
  }

  getProjectId() {
    return this.input.getAttribute('data-project-id');
  }
}