2017-06-27 18:37:30 +00:00
|
|
|
import { addClassIfElementExists } from '../lib/utils/dom_utils';
|
2018-11-15 15:27:38 +00:00
|
|
|
import DropdownAjaxFilter from './dropdown_ajax_filter';
|
2016-12-14 03:55:25 +00:00
|
|
|
|
2018-11-15 15:27:38 +00:00
|
|
|
export default class DropdownUser extends DropdownAjaxFilter {
|
2017-07-20 19:17:34 +00:00
|
|
|
constructor(options = {}) {
|
2018-11-15 15:27:38 +00:00
|
|
|
super({
|
|
|
|
...options,
|
2020-11-06 03:09:19 +00:00
|
|
|
endpoint: `${gon.relative_url_root || ''}/-/autocomplete/users.json`,
|
2018-11-15 15:27:38 +00:00
|
|
|
symbol: '@',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ajaxFilterConfig() {
|
|
|
|
return {
|
|
|
|
...super.ajaxFilterConfig(),
|
|
|
|
params: {
|
|
|
|
active: true,
|
|
|
|
group_id: this.getGroupId(),
|
|
|
|
project_id: this.getProjectId(),
|
|
|
|
current_user: true,
|
2019-05-22 03:08:30 +00:00
|
|
|
...this.projectOrGroupId(),
|
2018-11-15 15:27:38 +00:00
|
|
|
},
|
|
|
|
onLoadingFinished: () => {
|
|
|
|
this.hideCurrentUser();
|
2017-04-17 07:01:11 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2016-12-07 18:51:25 +00:00
|
|
|
|
2017-06-02 07:42:18 +00:00
|
|
|
hideCurrentUser() {
|
2017-06-27 18:37:30 +00:00
|
|
|
addClassIfElementExists(this.dropdown.querySelector('.js-current-user'), 'hidden');
|
2017-06-02 07:42:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 12:15:07 +00:00
|
|
|
getGroupId() {
|
|
|
|
return this.input.getAttribute('data-group-id');
|
|
|
|
}
|
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
getProjectId() {
|
|
|
|
return this.input.getAttribute('data-project-id');
|
|
|
|
}
|
2019-05-22 03:08:30 +00:00
|
|
|
|
|
|
|
projectOrGroupId() {
|
|
|
|
const projectId = this.getProjectId();
|
|
|
|
const groupId = this.getGroupId();
|
|
|
|
if (groupId) {
|
|
|
|
return {
|
|
|
|
group_id: groupId,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
project_id: projectId,
|
|
|
|
};
|
|
|
|
}
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|