From 12d9658e95ec981239a8391e75af784efe78f47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 10 Dec 2021 16:18:47 +0100 Subject: Add create event button! --- static/globals.ts | 23 +++++++++++++++++++++++ static/style.scss | 13 +++++++++++++ 2 files changed, 36 insertions(+) (limited to 'static') diff --git a/static/globals.ts b/static/globals.ts index cb65d953..eb7488c0 100644 --- a/static/globals.ts +++ b/static/globals.ts @@ -7,6 +7,9 @@ import { VEvent } from './vevent' import { uid } from './types' import { ComponentBlock } from './components/vevent-block' +import { v4 as uuid } from 'uuid' +import { setup_popup_element } from './components/popup-element' + const vcal_objects: Map = new Map; const event_calendar_mapping: Map = new Map; @@ -16,10 +19,30 @@ declare global { VIEW: 'month' | 'week'; EDIT_MODE: boolean; default_calendar: string; + + addNewEvent: ((e: any) => void); } } window.vcal_objects = vcal_objects; + +window.addNewEvent = () => { + let ev = new VEvent(); + let uid = uuid() + let now = new Date() + ev.setProperties([ + ['uid', uid], + ['dtstart', now, 'date-time'], + ['dtend', new Date(now.getTime() + 3600 * 1000), 'date-time'], + ]) + ev.calendar = window.default_calendar; + + vcal_objects.set(uid, ev); + + let popup = setup_popup_element(ev); + popup.maximize(); +} + function find_block(uid: uid): ComponentBlock | null { let obj = vcal_objects.get(uid) if (obj === undefined) { diff --git a/static/style.scss b/static/style.scss index 4e9936a2..48de9bcc 100644 --- a/static/style.scss +++ b/static/style.scss @@ -45,6 +45,19 @@ html, body { -1em 1em 0.5em gold; z-index: 1; } + + /* For new event button */ + position: relative; + + /* add new event button */ + > button { + position: absolute; + right: 2mm; + bottom: 5mm; + + height: 1cm; + width: 1cm; + } } -- cgit v1.2.3