From 0cfa00fc43eaf98db8b2461a2d07687b6591cd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 26 Nov 2021 17:14:30 +0100 Subject: Remove default ComponentVEvent redraw. --- static/components/vevent-block.ts | 19 ++++++++++++++++++- static/components/vevent-description.ts | 22 ++++++++++++++++++++++ static/components/vevent.ts | 27 ++------------------------- 3 files changed, 42 insertions(+), 26 deletions(-) (limited to 'static') diff --git a/static/components/vevent-block.ts b/static/components/vevent-block.ts index a4aaba24..de9cf748 100644 --- a/static/components/vevent-block.ts +++ b/static/components/vevent-block.ts @@ -23,7 +23,24 @@ class ComponentBlock extends ComponentVEvent { } redraw(data: VEvent) { - super.redraw(data); + let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; + + for (let el of body.querySelectorAll('[data-property]')) { + if (!(el instanceof HTMLElement)) continue; + let p = el.dataset.property!; + let d, fmt; + if ((d = data.getProperty(p))) { + if ((fmt = el.dataset.fmt)) { + el.textContent = d.format(fmt); + } else { + el.textContent = d; + } + } + } + + this.replaceChildren(body); + + /* -------------------------------------------------- */ let p; if ((p = data.getProperty('dtstart'))) { diff --git a/static/components/vevent-description.ts b/static/components/vevent-description.ts index f97b60e1..03c5355d 100644 --- a/static/components/vevent-description.ts +++ b/static/components/vevent-description.ts @@ -1,5 +1,6 @@ export { ComponentDescription } +import { VEvent } from '../vevent' import { ComponentVEvent } from './vevent' /* @@ -9,4 +10,25 @@ class ComponentDescription extends ComponentVEvent { constructor() { super(); } + + redraw(data: VEvent) { + // update ourselves from template + + let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; + + for (let el of body.querySelectorAll('[data-property]')) { + if (!(el instanceof HTMLElement)) continue; + let p = el.dataset.property!; + let d, fmt; + if ((d = data.getProperty(p))) { + if ((fmt = el.dataset.fmt)) { + el.textContent = d.format(fmt); + } else { + el.textContent = d; + } + } + } + + this.replaceChildren(body); + } } diff --git a/static/components/vevent.ts b/static/components/vevent.ts index cf28045a..561051fa 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -8,7 +8,7 @@ import { VEvent } from '../vevent' Lacks an accompaning tag, and shouldn't be directly instanciated. */ -class ComponentVEvent extends HTMLElement { +abstract class ComponentVEvent extends HTMLElement { template: HTMLTemplateElement uid: string @@ -45,29 +45,6 @@ class ComponentVEvent extends HTMLElement { } } - redraw(data: VEvent) { - // update ourselves from template - - if (!this.template) { - throw "Something"; - } - - let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; - - for (let el of body.getElementsByClassName("bind")) { - if (!(el instanceof HTMLElement)) continue; - let p = el.dataset.property!; - let d, fmt; - if ((d = data.getProperty(p))) { - if ((fmt = el.dataset.fmt)) { - el.textContent = d.format(fmt); - } else { - el.textContent = d; - } - } - } - - this.replaceChildren(body); - } + abstract redraw(data: VEvent): void } -- cgit v1.2.3