From 3ddbd37ade2e03e4fc3a6f5ba52234bc286fded3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 13 Dec 2021 02:26:36 +0100 Subject: Made VEventComponent template optional. --- static/components/edit-rrule.ts | 4 ++++ static/components/tab-group-element.ts | 1 + static/components/vevent-block.ts | 6 +++++- static/components/vevent-description.ts | 10 +++++++++- static/components/vevent-edit.ts | 4 ++++ static/components/vevent.ts | 5 ++--- 6 files changed, 25 insertions(+), 5 deletions(-) (limited to 'static/components') diff --git a/static/components/edit-rrule.ts b/static/components/edit-rrule.ts index cac19e80..a361bdee 100644 --- a/static/components/edit-rrule.ts +++ b/static/components/edit-rrule.ts @@ -14,6 +14,10 @@ class EditRRule extends ComponentVEvent { constructor(uid?: string) { super(uid); + if (!this.template) { + throw 'vevent-edit-rrule template required'; + } + let frag = this.template.content.cloneNode(true) as DocumentFragment let body = frag.firstElementChild! this.replaceChildren(body); diff --git a/static/components/tab-group-element.ts b/static/components/tab-group-element.ts index e84da19f..05cac7d2 100644 --- a/static/components/tab-group-element.ts +++ b/static/components/tab-group-element.ts @@ -165,6 +165,7 @@ class TabGroupElement extends ComponentVEvent { } + /* returns our rrule tab if we have one */ has_rrule_tab(): Element | false { for (let child of this.children) { if ((child.firstChild! as HTMLElement).tagName.toLowerCase() === 'vevent-edit-rrule') { diff --git a/static/components/vevent-block.ts b/static/components/vevent-block.ts index 95c72592..8cf61d30 100644 --- a/static/components/vevent-block.ts +++ b/static/components/vevent-block.ts @@ -13,6 +13,10 @@ class ComponentBlock extends ComponentVEvent { constructor(uid?: string) { super(uid); + if (!this.template) { + throw 'vevent-block template required'; + } + this.addEventListener('click', () => { let uid = this.uid /* TODO is it better to find the popup through a query selector, or @@ -24,7 +28,7 @@ class ComponentBlock extends ComponentVEvent { } redraw(data: VEvent) { - let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; + let body = (this.template!.content.cloneNode(true) as DocumentFragment).firstElementChild!; for (let el of body.querySelectorAll('[data-property]')) { if (!(el instanceof HTMLElement)) continue; diff --git a/static/components/vevent-description.ts b/static/components/vevent-description.ts index 98c9007e..4d81d6b3 100644 --- a/static/components/vevent-description.ts +++ b/static/components/vevent-description.ts @@ -8,10 +8,18 @@ import { makeElement } from '../lib' */ class ComponentDescription extends ComponentVEvent { + + constructor(uid?: string) { + super(uid); + if (!this.template) { + throw 'vevent-description template required'; + } + } + redraw(data: VEvent) { // update ourselves from template - let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; + let body = (this.template!.content.cloneNode(true) as DocumentFragment).firstElementChild!; for (let el of body.querySelectorAll('[data-property]')) { if (!(el instanceof HTMLElement)) continue; diff --git a/static/components/vevent-edit.ts b/static/components/vevent-edit.ts index 5c482882..ee368296 100644 --- a/static/components/vevent-edit.ts +++ b/static/components/vevent-edit.ts @@ -17,6 +17,10 @@ class ComponentEdit extends ComponentVEvent { constructor(uid?: string) { super(uid); + if (!this.template) { + throw 'vevent-edit template required'; + } + let frag = this.template.content.cloneNode(true) as DocumentFragment let body = frag.firstElementChild! this.replaceChildren(body); diff --git a/static/components/vevent.ts b/static/components/vevent.ts index 01391f9e..b72cda90 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -10,13 +10,12 @@ Lacks an accompaning tag, and shouldn't be directly instanciated. */ abstract class ComponentVEvent extends HTMLElement { - template: HTMLTemplateElement + template: HTMLTemplateElement | null uid: string constructor(uid?: string) { super(); - this.template = document.getElementById(this.tagName) as HTMLTemplateElement; - + this.template = document.getElementById(this.tagName) as HTMLTemplateElement | null let real_uid; -- cgit v1.2.3