X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b37e84dc101e8ca5c80bcd731adb9cc19b9e08ab..refs/pull/5625/head:/resources/js/components/page-picker.js diff --git a/resources/js/components/page-picker.js b/resources/js/components/page-picker.js index fba0a0a43..5ab511595 100644 --- a/resources/js/components/page-picker.js +++ b/resources/js/components/page-picker.js @@ -1,4 +1,8 @@ -import {Component} from "./component"; +import {Component} from './component'; + +function toggleElem(elem, show) { + elem.toggleAttribute('hidden', !show); +} export class PagePicker extends Component { @@ -10,6 +14,8 @@ export class PagePicker extends Component { this.defaultDisplay = this.$refs.defaultDisplay; this.buttonSep = this.$refs.buttonSeperator; + this.selectorEndpoint = this.$opts.selectorEndpoint; + this.value = this.input.value; this.setupListeners(); } @@ -17,17 +23,23 @@ export class PagePicker extends Component { setupListeners() { this.selectButton.addEventListener('click', this.showPopup.bind(this)); this.display.parentElement.addEventListener('click', this.showPopup.bind(this)); + this.display.addEventListener('click', e => e.stopPropagation()); - this.resetButton.addEventListener('click', event => { + this.resetButton.addEventListener('click', () => { this.setValue('', ''); }); } showPopup() { - /** @type {EntitySelectorPopup} **/ + /** @type {EntitySelectorPopup} * */ 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', }); } @@ -44,7 +56,7 @@ export class PagePicker extends Component { toggleElem(this.defaultDisplay, !hasValue); toggleElem(this.display, hasValue); if (hasValue) { - let id = this.getAssetIdFromVal(); + const id = this.getAssetIdFromVal(); this.display.textContent = `#${id}, ${name}`; this.display.href = window.baseUrl(`/link/${id}`); } @@ -55,7 +67,3 @@ export class PagePicker extends Component { } } - -function toggleElem(elem, show) { - elem.style.display = show ? null : 'none'; -} \ No newline at end of file