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.getPopup().show();
21 this.getSelector().focusSearch();
25 this.getPopup().hide();
32 return window.$components.firstOnElement(this.container, 'popup');
36 * @returns {EntitySelector}
39 return window.$components.firstOnElement(this.selectorEl, 'entity-selector');
42 onSelectButtonClick() {
43 this.handleConfirmedSelection(this.selection);
46 onSelectionChange(entity) {
47 this.selection = entity;
48 if (entity === null) {
49 this.selectButton.setAttribute('disabled', 'true');
51 this.selectButton.removeAttribute('disabled');
55 handleConfirmedSelection(entity) {
57 this.getSelector().reset();
58 if (this.callback && entity) this.callback(entity);