]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/entity-selector-popup.js
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / resources / js / components / entity-selector-popup.js
index e7cb60b1f6c4c05c751033ebec4424b8de7fea1d..29c06e9095113420b1d744d2fa73cd607635ea69 100644 (file)
@@ -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
+}