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 {String} searchText
22 * @param {EntitySelectorSearchOptions} searchOptions
24 show(callback, searchText = '', searchOptions = {}) {
25 this.callback = callback;
26 this.getSelector().configureSearchOptions(searchOptions);
27 this.getPopup().show();
30 this.getSelector().searchText(searchText);
33 this.getSelector().focusSearch();
37 this.getPopup().hide();
44 return window.$components.firstOnElement(this.container, 'popup');
48 * @returns {EntitySelector}
51 return window.$components.firstOnElement(this.selectorEl, 'entity-selector');
54 onSelectButtonClick() {
55 this.handleConfirmedSelection(this.selection);
58 onSelectionChange(entity) {
59 this.selection = entity;
60 if (entity === null) {
61 this.selectButton.setAttribute('disabled', 'true');
63 this.selectButton.removeAttribute('disabled');
67 handleConfirmedSelection(entity) {
69 this.getSelector().reset();
70 if (this.callback && entity) this.callback(entity);