1 import {Component} from './component';
3 function toggleElem(elem, show) {
4 elem.toggleAttribute('hidden', !show);
7 export class PagePicker extends Component {
10 this.input = this.$refs.input;
11 this.resetButton = this.$refs.resetButton;
12 this.selectButton = this.$refs.selectButton;
13 this.display = this.$refs.display;
14 this.defaultDisplay = this.$refs.defaultDisplay;
15 this.buttonSep = this.$refs.buttonSeperator;
17 this.value = this.input.value;
18 this.setupListeners();
22 this.selectButton.addEventListener('click', this.showPopup.bind(this));
23 this.display.parentElement.addEventListener('click', this.showPopup.bind(this));
24 this.display.addEventListener('click', e => e.stopPropagation());
26 this.resetButton.addEventListener('click', () => {
27 this.setValue('', '');
32 /** @type {EntitySelectorPopup} * */
33 const selectorPopup = window.$components.first('entity-selector-popup');
34 selectorPopup.show(entity => {
35 this.setValue(entity.id, entity.name);
39 setValue(value, name) {
41 this.input.value = value;
42 this.controlView(name);
46 const hasValue = this.value && this.value !== 0;
47 toggleElem(this.resetButton, hasValue);
48 toggleElem(this.buttonSep, hasValue);
49 toggleElem(this.defaultDisplay, !hasValue);
50 toggleElem(this.display, hasValue);
52 const id = this.getAssetIdFromVal();
53 this.display.textContent = `#${id}, ${name}`;
54 this.display.href = window.baseUrl(`/link/${id}`);
59 return Number(this.value);