From eff2468afffe7571f01cdfa7b7ea774476f8ecc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 8 Nov 2021 18:33:05 +0100 Subject: All ComponentVEvent requires uid. --- static/globals.ts | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'static/globals.ts') diff --git a/static/globals.ts b/static/globals.ts index 5e97bf39..6b332772 100644 --- a/static/globals.ts +++ b/static/globals.ts @@ -7,8 +7,6 @@ import { VEvent, xml_to_vcal } from './vevent' import { bind_popup_control } from './dragable' import { uid, parseDate, gensym, to_local, boolean, makeElement } from './lib' -"use strict"; - const vcal_objects: Map = new Map() interface HasValue { @@ -27,16 +25,24 @@ Lacks an accompaning tag, and shouldn't be directly instanciated. class ComponentVEvent extends HTMLElement { template: HTMLTemplateElement + uid: string - constructor() { + constructor(uid?: string) { super(); this.template = document.getElementById(this.tagName) as HTMLTemplateElement; - let uid; - if ((uid = this.dataset.uid)) { - vcal_objects.get(uid)?.register(this); + let real_uid; + if (this.dataset.uid) uid = this.dataset.uid; + if (uid) real_uid = uid; + + if (!real_uid) { + throw `UID required` } + this.uid = real_uid; + + vcal_objects.get(this.uid)?.register(this); + /* We DON'T have a redraw here in the general case, since the HTML rendered server-side should be fine enough for us. Those that need a direct rerendering (such as the edit tabs) @@ -108,18 +114,11 @@ function popuplateTab(tab: HTMLElement, tabgroup: string, index: number) { class ComponentEdit extends ComponentVEvent { firstTime: boolean - uid: string constructor() { super(); this.firstTime = true; - - if (this.dataset.uid === undefined) { - throw "data-uid must be set" - } else { - this.uid = this.dataset.uid; - } } connectedCallback() { @@ -227,12 +226,11 @@ function find_block(uid: uid): HTMLElement | null { A grahpical block in the week view. */ class ComponentBlock extends ComponentVEvent { - constructor() { - super(); + constructor(uid?: string) { + super(uid); this.addEventListener('click', () => { - let uid = this.dataset.uid - if (uid === undefined) throw new Error('UID missing from' + this) + let uid = this.uid let popup = find_popup(uid); if (popup === null) throw new Error('no popup for uid ' + uid); toggle_popup(popup); @@ -436,13 +434,13 @@ function buildDescriptionList(data: [string, any][]): HTMLElement { } /* */ -class PopupElement extends HTMLElement { +class PopupElement extends ComponentVEvent { tabgroup_id: string tabcount: number - constructor() { - super(); + constructor(uid?: string) { + super(uid); /* TODO populate remaining */ // this.id = 'popup' + this.dataset.uid @@ -458,10 +456,7 @@ class PopupElement extends HTMLElement { let template: HTMLTemplateElement = document.getElementById('popup-template') as HTMLTemplateElement let body = (template.content.cloneNode(true) as DocumentFragment).firstElementChild!; - if (this.dataset.uid === null) { - throw 'UID is required' - } - let uid = this.dataset.uid! + let uid = this.uid; // console.log(uid); body.getElementsByClassName('populate-with-uid') -- cgit v1.2.3