aboutsummaryrefslogtreecommitdiff
path: root/static/formatters.ts
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-03-15 01:14:45 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-03-15 01:43:12 +0100
commit2d35caa4b3e025a57c626f89c665da31ffbfe27d (patch)
treef22ad2d5c07626f116ca7c3a8762fd2fe68d6855 /static/formatters.ts
parentMake make-routes pre-compile all regexes. (diff)
downloadcalp-2d35caa4b3e025a57c626f89c665da31ffbfe27d.tar.gz
calp-2d35caa4b3e025a57c626f89c665da31ffbfe27d.tar.xz
Introduce concept of VEvent formatters in frontend.
Diffstat (limited to '')
-rw-r--r--static/formatters.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/static/formatters.ts b/static/formatters.ts
new file mode 100644
index 00000000..38c71e5e
--- /dev/null
+++ b/static/formatters.ts
@@ -0,0 +1,29 @@
+export {
+ formatters,
+}
+
+import { makeElement } from './lib'
+
+let formatters : Map<string, (e : HTMLElement, s : any) => void>;
+formatters = window.formatters = new Map();
+
+
+formatters.set('categories', (el, d) => {
+ for (let item of d) {
+ let q = encodeURIComponent(
+ `(member "${item}" (or (prop event (quote CATEGORIES)) (quote ())))`)
+ el.appendChild(makeElement('a', {
+ textContent: item,
+ href: `/search/?q=${q}`,
+ }))
+ }
+})
+
+formatters.set('default', (el, d) => {
+ let fmt;
+ if ((fmt = el.dataset.fmt)) {
+ el.textContent = d.format(fmt);
+ } else {
+ el.textContent = d;
+ }
+})