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();
19 this.selectButton.addEventListener('click', event => {
20 window.EntitySelectorPopup.show(entity => {
21 this.setValue(entity.id, entity.name);
25 this.resetButton.addEventListener('click', event => {
26 this.setValue('', '');
30 setValue(value, name) {
32 this.input.value = value;
33 this.controlView(name);
37 let hasValue = this.value && this.value !== 0;
38 toggleElem(this.resetButton, hasValue);
39 toggleElem(this.buttonSep, hasValue);
40 toggleElem(this.defaultDisplay, !hasValue);
41 toggleElem(this.display, hasValue);
43 let id = this.getAssetIdFromVal();
44 this.display.textContent = `#${id}, ${name}`;
45 this.display.href = window.baseUrl(`/link/${id}`);
50 return Number(this.value);
55 function toggleElem(elem, show) {
56 let display = (elem.tagName === 'BUTTON' || elem.tagName === 'SPAN') ? 'inline-block' : 'block';
57 elem.style.display = show ? display : 'none';
60 module.exports = PagePicker;