From 3afbb8e871af4e37965850bb59df3fcf2337d2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 10 Dec 2021 16:18:26 +0100 Subject: Broke out setup of popup on event creation. --- static/components/popup-element.ts | 21 +++++++++++++++- static/script.ts | 50 +++----------------------------------- 2 files changed, 23 insertions(+), 48 deletions(-) (limited to 'static') diff --git a/static/components/popup-element.ts b/static/components/popup-element.ts index 840faef8..4d5545fc 100644 --- a/static/components/popup-element.ts +++ b/static/components/popup-element.ts @@ -1,4 +1,4 @@ -export { PopupElement } +export { PopupElement, setup_popup_element } import { VEvent } from '../vevent' import { bind_popup_control } from '../dragable' @@ -141,3 +141,22 @@ class PopupElement extends ComponentVEvent { el.style.height = `${parent.clientHeight - 20}px` } } + +/* Create a new popup element for the given VEvent, and ready it for editing the + event. Used when creating event (through the frontend). + The return value can safely be ignored. +*/ +function setup_popup_element(ev: VEvent): PopupElement { + let uid = ev.getProperty('uid'); + let popup = new PopupElement(uid); + ev.register(popup); + /* TODO propper way to find popup container */ + (document.querySelector('.days') as Element).appendChild(popup); + let tabBtn = popup.querySelector('[role="tab"][title="Redigera"]') as HTMLButtonElement + tabBtn.click() + let tab = document.getElementById(tabBtn.getAttribute('aria-controls')!)! + let input = tab.querySelector('input[name="summary"]') as HTMLInputElement + popup.visible = true; + input.select(); + return popup; +} diff --git a/static/script.ts b/static/script.ts index f243dd67..cf92b24f 100644 --- a/static/script.ts +++ b/static/script.ts @@ -3,7 +3,7 @@ import { SmallcalCellHighlight, Timebar } from './clock' import { makeElement } from './lib' import { vcal_objects, event_calendar_mapping } from './globals' import { EventCreator } from './event-creator' -import { PopupElement } from './components/popup-element' +import { PopupElement, setup_popup_element } from './components/popup-element' import { initialize_components } from './elements' /* @@ -81,23 +81,9 @@ window.addEventListener('load', function() { )); c.addEventListener('mouseup', eventCreator.create_event_finisher( function(ev: VEvent) { - // let popup = document.createElement('popup-element') as PopupElement; - let uid = ev.getProperty('uid'); - vcal_objects.set(uid, ev); - - let popup = new PopupElement(uid); - ev.register(popup); - // console.log(popup); - (document.querySelector('.days') as Element).appendChild(popup); - let tabBtn = popup.querySelector('[role="tab"][title="Redigera"]') as HTMLButtonElement - tabBtn.click() - let tab = document.getElementById(tabBtn.getAttribute('aria-controls')!)! - let input = tab.querySelector('input[name="summary"]') as HTMLInputElement - popup.visible = true; - input.select(); - + setup_popup_element(ev); })); } @@ -112,39 +98,9 @@ window.addEventListener('load', function() { ); c.onmouseup = eventCreator.create_event_finisher( function(ev: VEvent) { - // let popup = document.createElement('popup-element') as PopupElement; - let uid = ev.getProperty('uid'); - vcal_objects.set(uid, ev); - - let popup = new PopupElement(uid); - /* TODO these things fail, due to the event not being - present in the global_events map */ - (document.querySelector('.days') as Element).appendChild(popup); - ev.register(popup); - popup.visible = true; - console.log(popup); - // (popup.querySelector("input[name='summary']") as HTMLInputElement).focus(); - // let popupElement = document.getElementById("popup" + event.id); - // open_popup(popup_from_event(event)); - - // popupElement.querySelector("input[name='summary']").focus(); - - - // ---------------------------------------------------------------------------------------------------- - // TODO restore this - // let popupElement = document.getElementById("popup" + event.id); - // open_popup(popupElement); - - // popupElement.querySelector("input[name='summary']").focus(); - - // /* This assumes that it's unchecked beforehand. - // Preferably we would just ensure that it's checked here, - // But we also need to make sure that the proper handlers - // are run then */ - // popupElement.querySelector("input[name='wholeday']").click(); - + setup_popup_element(ev); }); } } -- cgit v1.2.3