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));
18 show(callback, searchText = '') {
19 this.callback = callback;
20 this.getPopup().show();
23 this.getSelector().searchText(searchText);
26 this.getSelector().focusSearch();
30 this.getPopup().hide();
37 return window.$components.firstOnElement(this.container, 'popup');
41 * @returns {EntitySelector}
44 return window.$components.firstOnElement(this.selectorEl, 'entity-selector');
47 onSelectButtonClick() {
48 this.handleConfirmedSelection(this.selection);
51 onSelectionChange(entity) {
52 this.selection = entity;
53 if (entity === null) {
54 this.selectButton.setAttribute('disabled', 'true');
56 this.selectButton.removeAttribute('disabled');
60 handleConfirmedSelection(entity) {
62 this.getSelector().reset();
63 if (this.callback && entity) this.callback(entity);