mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 10:35:30 +00:00
51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
export class AlmanachEditPage extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
this._pendingAgent = null;
|
|
}
|
|
|
|
connectedCallback() {
|
|
this._initForm();
|
|
this._initPlaces();
|
|
}
|
|
|
|
_initForm() {
|
|
const form = this.querySelector("#changealmanachform");
|
|
if (form && typeof window.FormLoad === "function") {
|
|
window.FormLoad(form);
|
|
}
|
|
}
|
|
|
|
_parseJSONAttr(element, name) {
|
|
if (!element) {
|
|
return null;
|
|
}
|
|
const raw = element.getAttribute(name);
|
|
if (!raw) {
|
|
return null;
|
|
}
|
|
try {
|
|
return JSON.parse(raw);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
_initPlaces() {
|
|
const placesSelect = this.querySelector("#places");
|
|
if (!placesSelect) {
|
|
return;
|
|
}
|
|
const initialPlaces = this._parseJSONAttr(placesSelect, "data-initial-options") || [];
|
|
const initialPlaceIds = this._parseJSONAttr(placesSelect, "data-initial-values") || [];
|
|
|
|
if (initialPlaces.length > 0 && typeof placesSelect.setOptions === "function") {
|
|
placesSelect.setOptions(initialPlaces);
|
|
}
|
|
if (initialPlaceIds.length > 0) {
|
|
placesSelect.value = initialPlaceIds;
|
|
}
|
|
}
|
|
|
|
}
|