2017-01-13 15:30:40 +00:00
|
|
|
require('./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: {
|
2017-01-30 21:02:19 +00:00
|
|
|
endpoint: `${gon.relative_url_root || ''}/autocomplete/users.json`,
|
2016-12-09 17:44:09 +00:00
|
|
|
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,
|
|
|
|
},
|
2016-12-13 03:07:42 +00:00
|
|
|
searchValueFunction: this.getSearchInput.bind(this),
|
2016-12-10 21:40:12 +00:00
|
|
|
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-07 18:51:25 +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() {
|
2017-01-20 15:09:36 +00:00
|
|
|
const query = gl.DropdownUtils.getSearchInput(this.input);
|
2016-12-17 19:22:00 +00:00
|
|
|
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(query);
|
2017-01-27 19:22:12 +00:00
|
|
|
let value = lastToken.value || '';
|
2016-12-07 18:51:25 +00:00
|
|
|
|
2017-01-27 19:22:12 +00:00
|
|
|
// Removes the first character if it is a quotation so that we can search
|
|
|
|
// with multiple words
|
|
|
|
if (value[0] === '"' || value[0] === '\'') {
|
|
|
|
value = value.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2016-12-09 17:44:09 +00:00
|
|
|
}
|
2016-12-07 18:51:25 +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-07 18:51:25 +00:00
|
|
|
}
|
2016-12-02 21:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 14:52:43 +00:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
gl.DropdownUser = DropdownUser;
|
|
|
|
})();
|