/**
* Show the selector popup.
* @param {Function} callback
- * @param {String} searchText
* @param {EntitySelectorSearchOptions} searchOptions
*/
- show(callback, searchText = '', searchOptions = {}) {
+ show(callback, searchOptions = {}) {
this.callback = callback;
this.getSelector().configureSearchOptions(searchOptions);
this.getPopup().show();
- if (searchText) {
- this.getSelector().searchText(searchText);
- }
-
this.getSelector().focusSearch();
}
* @property entityTypes string
* @property entityPermission string
* @property searchEndpoint string
+ * @property initialValue string
*/
/**
entityTypes: this.$opts.entityTypes || 'page,book,chapter',
entityPermission: this.$opts.entityPermission || 'view',
searchEndpoint: this.$opts.searchEndpoint || '',
+ initialValue: this.searchInput.value || '',
};
this.search = '';
configureSearchOptions(options) {
Object.assign(this.searchOptions, options);
this.reset();
+ this.searchInput.value = this.searchOptions.initialValue;
}
setupListeners() {
this.searchInput.focus();
}
- searchText(queryText) {
- this.searchInput.value = queryText;
- this.searchEntities(queryText);
- }
-
showLoading() {
this.loading.style.display = 'block';
this.resultsContainer.style.display = 'none';
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();
const selectorPopup = window.$components.first('entity-selector-popup');
selectorPopup.show(entity => {
this.setValue(entity.id, entity.name);
- }, '', {
+ }, {
+ initialValue: '',
searchEndpoint: this.selectorEndpoint,
entityTypes: 'page',
entityPermission: 'view',
const selectedText = selectionText || entity.name;
const newText = `[${selectedText}](${entity.link})`;
this.#replaceSelection(newText, newText.length, selectionRange);
- }, selectionText, {
+ }, {
+ initialValue: selectionText,
searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view',
text: entity.name,
title: entity.name,
});
- }, selectionText, {
+ }, {
+ initialValue: selectionText,
searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view',
editor.selection.collapse(false);
editor.focus();
- }, selectionText, {
+ }, {
+ initialValue: selectionText,
searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view',