2018-03-17 18:26:18 +05:30
|
|
|
import Flash from '../flash';
|
|
|
|
import Ajax from '../droplab/plugins/ajax';
|
|
|
|
import Filter from '../droplab/plugins/filter';
|
2018-03-27 19:54:05 +05:30
|
|
|
import FilteredSearchDropdown from './filtered_search_dropdown';
|
|
|
|
import DropdownUtils from './dropdown_utils';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
export default class DropdownNonUser extends 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 */
|
2019-07-31 22:56:46 +05:30
|
|
|
new Flash(__('An error occurred fetching the dropdown data.'));
|
2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-enable no-new */
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Filter: {
|
2018-03-27 19:54:05 +05:30
|
|
|
filterFunction: DropdownUtils.filterWithSymbol.bind(null, this.symbol, input),
|
2017-08-17 22:00:37 +05:30
|
|
|
template: 'title',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
itemClicked(e) {
|
2018-12-13 13:39:08 +05:30
|
|
|
super.itemClicked(e, selected => {
|
2017-08-17 22:00:37 +05:30
|
|
|
const title = selected.querySelector('.js-data-value').innerText.trim();
|
2018-03-27 19:54:05 +05:30
|
|
|
return `${this.symbol}${DropdownUtils.getEscapedText(title)}`;
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent(forceShowList = false) {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.droplab.changeHookList(this.hookId, this.dropdown, [Ajax, Filter], this.config);
|
2017-08-17 22:00:37 +05:30
|
|
|
super.renderContent(forceShowList);
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.droplab.addHook(this.input, this.dropdown, [Ajax, Filter], this.config).init();
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|