X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e86a90967ee6066e4e22986265b2a2825853e17d..refs/heads/release:/resources/js/components/entity-selector.js diff --git a/resources/js/components/entity-selector.js b/resources/js/components/entity-selector.js index 5ad991437..7491119a1 100644 --- a/resources/js/components/entity-selector.js +++ b/resources/js/components/entity-selector.js @@ -1,4 +1,4 @@ -import {onChildEvent} from '../services/dom'; +import {onChildEvent} from '../services/dom.ts'; import {Component} from './component'; /** @@ -6,6 +6,7 @@ import {Component} from './component'; * @property entityTypes string * @property entityPermission string * @property searchEndpoint string + * @property initialValue string */ /** @@ -25,6 +26,7 @@ export class EntitySelector extends Component { entityTypes: this.$opts.entityTypes || 'page,book,chapter', entityPermission: this.$opts.entityPermission || 'view', searchEndpoint: this.$opts.searchEndpoint || '', + initialValue: this.searchInput.value || '', }; this.search = ''; @@ -44,6 +46,7 @@ export class EntitySelector extends Component { configureSearchOptions(options) { Object.assign(this.searchOptions, options); this.reset(); + this.searchInput.value = this.searchOptions.initialValue; } setupListeners() { @@ -108,11 +111,6 @@ export class EntitySelector extends Component { this.searchInput.focus(); } - searchText(queryText) { - this.searchInput.value = queryText; - this.searchEntities(queryText); - } - showLoading() { this.loading.style.display = 'block'; this.resultsContainer.style.display = 'none'; @@ -128,6 +126,11 @@ export class EntitySelector extends Component { throw new Error('Search endpoint not set for entity-selector load'); } + if (this.searchOptions.initialValue) { + this.searchEntities(this.searchOptions.initialValue); + return; + } + window.$http.get(this.searchUrl()).then(resp => { this.resultsContainer.innerHTML = resp.data; this.hideLoading();