2022-11-15 07:44:57 -05:00
|
|
|
import {Component} from "./component";
|
2017-08-28 08:38:32 -04:00
|
|
|
|
2022-11-15 07:44:57 -05:00
|
|
|
export class PagePicker extends Component {
|
2017-08-28 08:38:32 -04:00
|
|
|
|
2022-11-15 07:44:57 -05:00
|
|
|
setup() {
|
|
|
|
this.input = this.$refs.input;
|
|
|
|
this.resetButton = this.$refs.resetButton;
|
|
|
|
this.selectButton = this.$refs.selectButton;
|
|
|
|
this.display = this.$refs.display;
|
|
|
|
this.defaultDisplay = this.$refs.defaultDisplay;
|
|
|
|
this.buttonSep = this.$refs.buttonSeperator;
|
2017-08-28 08:38:32 -04:00
|
|
|
|
|
|
|
this.value = this.input.value;
|
|
|
|
this.setupListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupListeners() {
|
2018-09-20 10:27:30 -04:00
|
|
|
this.selectButton.addEventListener('click', this.showPopup.bind(this));
|
|
|
|
this.display.parentElement.addEventListener('click', this.showPopup.bind(this));
|
2017-08-28 08:38:32 -04:00
|
|
|
|
|
|
|
this.resetButton.addEventListener('click', event => {
|
|
|
|
this.setValue('', '');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-20 10:27:30 -04:00
|
|
|
showPopup() {
|
2022-11-15 07:44:57 -05:00
|
|
|
/** @type {EntitySelectorPopup} **/
|
|
|
|
const selectorPopup = window.$components.first('entity-selector-popup');
|
|
|
|
selectorPopup.show(entity => {
|
2018-09-20 10:27:30 -04:00
|
|
|
this.setValue(entity.id, entity.name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-28 08:38:32 -04:00
|
|
|
setValue(value, name) {
|
|
|
|
this.value = value;
|
|
|
|
this.input.value = value;
|
|
|
|
this.controlView(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
controlView(name) {
|
2022-11-15 07:44:57 -05:00
|
|
|
const hasValue = this.value && this.value !== 0;
|
2017-08-28 08:38:32 -04:00
|
|
|
toggleElem(this.resetButton, hasValue);
|
|
|
|
toggleElem(this.buttonSep, hasValue);
|
|
|
|
toggleElem(this.defaultDisplay, !hasValue);
|
|
|
|
toggleElem(this.display, hasValue);
|
|
|
|
if (hasValue) {
|
|
|
|
let id = this.getAssetIdFromVal();
|
|
|
|
this.display.textContent = `#${id}, ${name}`;
|
|
|
|
this.display.href = window.baseUrl(`/link/${id}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAssetIdFromVal() {
|
|
|
|
return Number(this.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleElem(elem, show) {
|
2022-11-15 07:44:57 -05:00
|
|
|
elem.style.display = show ? null : 'none';
|
|
|
|
}
|