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,
|
2016-12-10 21:40:12 +00:00
|
|
|
loadingTemplate: this.loadingTemplate,
|
2016-12-09 17:44:09 +00:00
|
|
|
}
|
|
|
|
};
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-09 19:15:09 +00:00
|
|
|
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-07 18:51:25 +00:00
|
|
|
|
2016-12-09 17:44:09 +00:00
|
|
|
getSearchInput() {
|
|
|
|
const query = document.querySelector('.filtered-search').value;
|
2016-12-07 18:51:25 +00:00
|
|
|
const { value } = gl.FilteredSearchTokenizer.getLastTokenObject(query);
|
2016-12-09 17:44:09 +00:00
|
|
|
const valueWithoutColon = value.slice(1);
|
|
|
|
const hasPrefix = valueWithoutColon[0] === '@';
|
2016-12-07 18:51:25 +00:00
|
|
|
const valueWithoutPrefix = valueWithoutColon.slice(1);
|
|
|
|
|
2016-12-09 17:44:09 +00:00
|
|
|
if (hasPrefix) {
|
|
|
|
return valueWithoutPrefix;
|
|
|
|
} else {
|
|
|
|
return valueWithoutColon;
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 18:51:25 +00:00
|
|
|
|
2016-12-09 17:44:09 +00:00
|
|
|
configure() {
|
|
|
|
this.droplab.addHook(this.input, this.dropdown, [droplabAjaxFilter], this.config).init();
|
2016-12-07 18:51:25 +00:00
|
|
|
}
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
global.DropdownAssignee = DropdownAssignee;
|
|
|
|
})(window.gl || (window.gl = {}));
|