debian-mirror-gitlab/app/assets/javascripts/filtered_search/dropdown_non_user.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* global Flash */
import Ajax from '~/droplab/plugins/ajax';
import Filter from '~/droplab/plugins/filter';
2017-09-10 17:25:29 +05:30
import './filtered_search_dropdown';
2017-08-17 22:00:37 +05:30
class DropdownNonUser extends gl.FilteredSearchDropdown {
2017-09-10 17:25:29 +05:30
constructor(options = {}) {
const { input, endpoint, symbol, preprocessing } = options;
super(options);
2017-08-17 22:00:37 +05:30
this.symbol = symbol;
this.config = {
Ajax: {
endpoint,
method: 'setData',
loadingTemplate: this.loadingTemplate,
2017-09-10 17:25:29 +05:30
preprocessing,
2017-08-17 22:00:37 +05:30
onError() {
/* eslint-disable no-new */
new Flash('An error occured fetching the dropdown data.');
/* eslint-enable no-new */
},
},
Filter: {
filterFunction: gl.DropdownUtils.filterWithSymbol.bind(null, this.symbol, input),
template: 'title',
},
};
}
itemClicked(e) {
super.itemClicked(e, (selected) => {
const title = selected.querySelector('.js-data-value').innerText.trim();
return `${this.symbol}${gl.DropdownUtils.getEscapedText(title)}`;
});
}
renderContent(forceShowList = false) {
this.droplab
.changeHookList(this.hookId, this.dropdown, [Ajax, Filter], this.config);
super.renderContent(forceShowList);
}
init() {
this.droplab
.addHook(this.input, this.dropdown, [Ajax, Filter], this.config).init();
}
}
window.gl = window.gl || {};
gl.DropdownNonUser = DropdownNonUser;