X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/736d6afb7d49931b6afbb697514099888a826083..refs/pull/5280/head:/resources/js/components/entity-selector-popup.js diff --git a/resources/js/components/entity-selector-popup.js b/resources/js/components/entity-selector-popup.js index e7cb60b1f..29c06e909 100644 --- a/resources/js/components/entity-selector-popup.js +++ b/resources/js/components/entity-selector-popup.js @@ -1,14 +1,10 @@ -/** - * Entity Selector Popup - * @extends {Component} - */ -class EntitySelectorPopup { +import {Component} from './component'; + +export class EntitySelectorPopup extends Component { setup() { - this.elem = this.$el; + this.container = this.$el; this.selectButton = this.$refs.select; - - window.EntitySelectorPopup = this; this.selectorEl = this.$refs.selector; this.callback = null; @@ -19,18 +15,35 @@ class EntitySelectorPopup { window.$events.listen('entity-select-confirm', this.handleConfirmedSelection.bind(this)); } - show(callback) { + /** + * Show the selector popup. + * @param {Function} callback + * @param {EntitySelectorSearchOptions} searchOptions + */ + show(callback, searchOptions = {}) { this.callback = callback; - this.elem.components.popup.show(); + this.getSelector().configureSearchOptions(searchOptions); + this.getPopup().show(); + this.getSelector().focusSearch(); } hide() { - this.elem.components.popup.hide(); + this.getPopup().hide(); } + /** + * @returns {Popup} + */ + getPopup() { + return window.$components.firstOnElement(this.container, 'popup'); + } + + /** + * @returns {EntitySelector} + */ getSelector() { - return this.selectorEl.components['entity-selector']; + return window.$components.firstOnElement(this.selectorEl, 'entity-selector'); } onSelectButtonClick() { @@ -51,6 +64,5 @@ class EntitySelectorPopup { this.getSelector().reset(); if (this.callback && entity) this.callback(entity); } -} -export default EntitySelectorPopup; \ No newline at end of file +}