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

62 lines
1.9 KiB
JavaScript
Raw Normal View History

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';
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,
loadingTemplate: this.loadingTemplate,
2016-12-09 17:44:09 +00:00
}
};
2016-12-02 21:04:10 +00:00
}
itemClicked(e) {
const dataValueSet = this.setDataValueIfSelected(e.detail.selected);
if (!dataValueSet) {
const username = e.detail.selected.querySelector('.dropdown-light-content').innerText.trim();
gl.FilteredSearchManager.addWordToInput(this.getSelectedText(username));
}
this.dismissDropdown(!dataValueSet);
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-09 17:44:09 +00:00
getSearchInput() {
const query = document.querySelector('.filtered-search').value;
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
2016-12-09 17:44:09 +00:00
const valueWithoutColon = value.slice(1);
const hasPrefix = valueWithoutColon[0] === '@';
const valueWithoutPrefix = valueWithoutColon.slice(1);
2016-12-09 17:44:09 +00:00
if (hasPrefix) {
return valueWithoutPrefix;
} else {
return valueWithoutColon;
}
}
2016-12-09 17:44:09 +00:00
configure() {
this.droplab.addHook(this.input, this.dropdown, [droplabAjaxFilter], this.config).init();
}
2016-12-02 21:04:10 +00:00
}
global.DropdownAssignee = DropdownAssignee;
})(window.gl || (window.gl = {}));