1 import {Component} from './component';
3 export class EntitySelectorPopup extends Component {
6 this.container = this.$el;
7 this.selectButton = this.$refs.select;
8 this.selectorEl = this.$refs.selector;
11 this.selection = null;
13 this.selectButton.addEventListener('click', this.onSelectButtonClick.bind(this));
14 window.$events.listen('entity-select-change', this.onSelectionChange.bind(this));
15 window.$events.listen('entity-select-confirm', this.handleConfirmedSelection.bind(this));
19 * Show the selector popup.
20 * @param {Function} callback
21 * @param {EntitySelectorSearchOptions} searchOptions
23 show(callback, searchOptions = {}) {
24 this.callback = callback;
25 this.getSelector().configureSearchOptions(searchOptions);
26 this.getPopup().show();
28 this.getSelector().focusSearch();
32 this.getPopup().hide();
39 return window.$components.firstOnElement(this.container, 'popup');
43 * @returns {EntitySelector}
46 return window.$components.firstOnElement(this.selectorEl, 'entity-selector');
49 onSelectButtonClick() {
50 this.handleConfirmedSelection(this.selection);
53 onSelectionChange(entity) {
54 this.selection = entity;
55 if (entity === null) {
56 this.selectButton.setAttribute('disabled', 'true');
58 this.selectButton.removeAttribute('disabled');
62 handleConfirmedSelection(entity) {
64 this.getSelector().reset();
65 if (this.callback && entity) this.callback(entity);