6 this.input = elem.querySelector('input');
7 this.resetButton = elem.querySelector('[page-picker-reset]');
8 this.selectButton = elem.querySelector('[page-picker-select]');
9 this.display = elem.querySelector('[page-picker-display]');
10 this.defaultDisplay = elem.querySelector('[page-picker-default]');
11 this.buttonSep = elem.querySelector('span.sep');
13 this.value = this.input.value;
14 this.setupListeners();
18 this.selectButton.addEventListener('click', this.showPopup.bind(this));
19 this.display.parentElement.addEventListener('click', this.showPopup.bind(this));
21 this.resetButton.addEventListener('click', event => {
22 this.setValue('', '');
27 window.EntitySelectorPopup.show(entity => {
28 this.setValue(entity.id, entity.name);
32 setValue(value, name) {
34 this.input.value = value;
35 this.controlView(name);
39 let hasValue = this.value && this.value !== 0;
40 toggleElem(this.resetButton, hasValue);
41 toggleElem(this.buttonSep, hasValue);
42 toggleElem(this.defaultDisplay, !hasValue);
43 toggleElem(this.display, hasValue);
45 let id = this.getAssetIdFromVal();
46 this.display.textContent = `#${id}, ${name}`;
47 this.display.href = window.baseUrl(`/link/${id}`);
52 return Number(this.value);
57 function toggleElem(elem, show) {
58 let display = (elem.tagName === 'BUTTON' || elem.tagName === 'SPAN') ? 'inline-block' : 'block';
59 elem.style.display = show ? display : 'none';
62 export default PagePicker;