gitlab-org--gitlab-foss/app/assets/javascripts/filtered_search/dropdown_user.js.es6

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-12-02 21:04:10 +00:00
/*= require filtered_search/filtered_search_dropdown */
2016-12-14 03:55:25 +00:00
/* global droplabAjaxFilter */
2016-12-13 14:52:43 +00:00
(() => {
2016-12-12 00:05:55 +00:00
class DropdownUser extends gl.FilteredSearchDropdown {
2017-01-05 19:56:23 +00:00
constructor(droplab, dropdown, input, filter) {
super(droplab, dropdown, input, filter);
2016-12-09 17:44:09 +00:00
this.config = {
droplabAjaxFilter: {
endpoint: '/autocomplete/users.json',
searchKey: 'search',
params: {
per_page: 20,
active: true,
2016-12-10 19:47:36 +00:00
project_id: this.getProjectId(),
2016-12-09 17:44:09 +00:00
current_user: true,
},
searchValueFunction: this.getSearchInput.bind(this),
loadingTemplate: this.loadingTemplate,
2016-12-12 00:05:55 +00:00
},
2016-12-09 17:44:09 +00:00
};
2016-12-02 21:04:10 +00:00
}
itemClicked(e) {
2016-12-13 14:52:43 +00:00
super.itemClicked(e,
selected => selected.querySelector('.dropdown-light-content').innerText.trim());
2016-12-02 21:04:10 +00:00
}
2016-12-09 19:17:19 +00:00
renderContent(forceShowList = false) {
2016-12-09 17:44:09 +00:00
this.droplab.changeHookList(this.hookId, this.dropdown, [droplabAjaxFilter], this.config);
2016-12-09 19:17:19 +00:00
super.renderContent(forceShowList);
2016-12-02 21:04:10 +00:00
}
2016-12-12 00:11:58 +00:00
getProjectId() {
return this.input.getAttribute('data-project-id');
}
2016-12-09 17:44:09 +00:00
getSearchInput() {
const query = gl.DropdownUtils.getSearchInput(this.input);
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(query);
return lastToken.value || '';
2016-12-09 17:44:09 +00:00
}
2016-12-12 16:28:22 +00:00
init() {
2016-12-09 17:44:09 +00:00
this.droplab.addHook(this.input, this.dropdown, [droplabAjaxFilter], this.config).init();
}
2016-12-02 21:04:10 +00:00
}
2016-12-13 14:52:43 +00:00
window.gl = window.gl || {};
gl.DropdownUser = DropdownUser;
})();