gitlab-org--gitlab-foss/app/assets/javascripts/filtered_search/dropdown_non_user.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

import createFlash from '~/flash';
import { __ } from '~/locale';
import Ajax from '../droplab/plugins/ajax';
import Filter from '../droplab/plugins/filter';
2018-02-21 20:22:56 +00:00
import DropdownUtils from './dropdown_utils';
import FilteredSearchDropdown from './filtered_search_dropdown';
2016-12-14 03:55:25 +00:00
2018-02-21 20:22:56 +00:00
export default class DropdownNonUser extends FilteredSearchDropdown {
constructor(options = {}) {
const { input, endpoint, symbol, preprocessing } = options;
super(options);
this.symbol = symbol;
this.config = {
Ajax: {
endpoint,
method: 'setData',
loadingTemplate: this.loadingTemplate,
preprocessing,
onError() {
createFlash({
message: __('An error occurred fetching the dropdown data.'),
});
2016-12-09 17:44:09 +00:00
},
},
Filter: {
2018-02-21 20:22:56 +00:00
filterFunction: DropdownUtils.filterWithSymbol.bind(null, this.symbol, input),
template: 'title',
},
};
}
2016-12-02 22:43:15 +00:00
itemClicked(e) {
super.itemClicked(e, (selected) => {
const title = selected.querySelector('.js-data-value').innerText.trim();
2018-02-21 20:22:56 +00:00
return `${this.symbol}${DropdownUtils.getEscapedText(title)}`;
});
}
2016-12-02 22:43:15 +00:00
renderContent(forceShowList = false) {
this.droplab.changeHookList(this.hookId, this.dropdown, [Ajax, Filter], this.config);
super.renderContent(forceShowList);
}
2016-12-09 17:44:09 +00:00
init() {
this.droplab.addHook(this.input, this.dropdown, [Ajax, Filter], this.config).init();
2016-12-02 22:43:15 +00:00
}
}