2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2019-04-29 10:20:16 -04:00
|
|
|
import { __ } from '~/locale';
|
2020-08-24 14:10:19 -04:00
|
|
|
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
|
2018-03-09 15:18:59 -05:00
|
|
|
|
2018-02-05 19:10:58 -05:00
|
|
|
export default class TransferDropdown {
|
|
|
|
constructor() {
|
|
|
|
this.groupDropdown = $('.js-groups-dropdown');
|
|
|
|
this.parentInput = $('#new_parent_group_id');
|
|
|
|
this.data = this.groupDropdown.data('data');
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.buildDropdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDropdown() {
|
2019-09-13 09:26:31 -04:00
|
|
|
const extraOptions = [{ id: '-1', text: __('No parent group') }, { type: 'divider' }];
|
2018-02-05 19:10:58 -05:00
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
initDeprecatedJQueryDropdown(this.groupDropdown, {
|
2018-02-05 19:10:58 -05:00
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
|
|
|
toggleLabel: item => item.text,
|
|
|
|
search: { fields: ['text'] },
|
|
|
|
data: extraOptions.concat(this.data),
|
|
|
|
text: item => item.text,
|
2018-10-24 15:17:03 -04:00
|
|
|
clicked: options => {
|
2018-02-05 19:10:58 -05:00
|
|
|
const { e } = options;
|
|
|
|
e.preventDefault();
|
|
|
|
this.assignSelected(options.selectedObj);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
assignSelected(selected) {
|
|
|
|
this.parentInput.val(selected.id);
|
2019-09-11 10:28:34 -04:00
|
|
|
this.parentInput.change();
|
2018-02-05 19:10:58 -05:00
|
|
|
}
|
|
|
|
}
|