X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e711290d8b1ce06b38e0560248806e8de2077870..refs/pull/5626/head:/resources/js/components/page-picker.js diff --git a/resources/js/components/page-picker.js b/resources/js/components/page-picker.js index 83bf60a17..5ab511595 100644 --- a/resources/js/components/page-picker.js +++ b/resources/js/components/page-picker.js @@ -1,5 +1,9 @@ import {Component} from './component'; +function toggleElem(elem, show) { + elem.toggleAttribute('hidden', !show); +} + export class PagePicker extends Component { setup() { @@ -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,8 +23,9 @@ 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('', ''); }); } @@ -28,6 +35,11 @@ export class PagePicker extends Component { 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', }); } @@ -55,7 +67,3 @@ export class PagePicker extends Component { } } - -function toggleElem(elem, show) { - elem.style.display = show ? null : 'none'; -}