2016-12-02 21:04:10 +00:00
|
|
|
/* eslint-disable no-param-reassign */
|
|
|
|
/*= require filtered_search/filtered_search_dropdown */
|
|
|
|
|
|
|
|
((global) => {
|
|
|
|
class DropdownAssignee extends gl.FilteredSearchDropdown {
|
2016-12-08 21:36:54 +00:00
|
|
|
constructor(droplab, dropdown, input) {
|
|
|
|
super(droplab, dropdown, input);
|
2016-12-02 21:04:10 +00:00
|
|
|
this.listId = 'js-dropdown-assignee';
|
|
|
|
}
|
|
|
|
|
|
|
|
itemClicked(e) {
|
2016-12-05 22:05:30 +00:00
|
|
|
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
|
|
|
|
|
|
|
|
if (!dataValueSet) {
|
2016-12-05 22:36:05 +00:00
|
|
|
const username = e.detail.selected.querySelector('.dropdown-light-content').innerText.trim();
|
|
|
|
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(username));
|
2016-12-05 22:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.dismissDropdown();
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderContent() {
|
2016-12-08 21:36:54 +00:00
|
|
|
// TODO: Pass elements instead of querySelectors
|
|
|
|
this.droplab.changeHookList(this.hookId, '#js-dropdown-assignee', [droplabAjax], {
|
|
|
|
droplabAjax: {
|
|
|
|
endpoint: '/autocomplete/users.json?search=&per_page=20&active=true&project_id=2&group_id=&skip_ldap=&todo_filter=&todo_state_filter=¤t_user=true&push_code_to_protected_branches=&author_id=&skip_users=',
|
|
|
|
method: 'setData',
|
|
|
|
}
|
|
|
|
});
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
2016-12-07 18:51:25 +00:00
|
|
|
|
|
|
|
filterMethod(item, query) {
|
|
|
|
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
|
|
|
|
const valueWithoutColon = value.slice(1).toLowerCase();
|
|
|
|
const valueWithoutPrefix = valueWithoutColon.slice(1);
|
|
|
|
|
|
|
|
const username = item.username.toLowerCase();
|
|
|
|
const name = item.name.toLowerCase();
|
|
|
|
|
|
|
|
const noUsernameMatch = username.indexOf(valueWithoutPrefix) === -1 && username.indexOf(valueWithoutColon) === -1;
|
|
|
|
const noNameMatch = name.indexOf(valueWithoutColon) === -1;
|
|
|
|
|
|
|
|
item.droplab_hidden = noUsernameMatch && noNameMatch;
|
|
|
|
return item;
|
|
|
|
}
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
global.DropdownAssignee = DropdownAssignee;
|
|
|
|
})(window.gl || (window.gl = {}));
|