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 this.callback = callback;
20 this.container.components.popup.show();
21 this.getSelector().focusSearch();
25 this.container.components.popup.hide();
29 return this.selectorEl.components['entity-selector'];
32 onSelectButtonClick() {
33 this.handleConfirmedSelection(this.selection);
36 onSelectionChange(entity) {
37 this.selection = entity;
38 if (entity === null) {
39 this.selectButton.setAttribute('disabled', 'true');
41 this.selectButton.removeAttribute('disabled');
45 handleConfirmedSelection(entity) {
47 this.getSelector().reset();
48 if (this.callback && entity) this.callback(entity);