gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit189c4c8c189c4c8c|||PR WIP calendar28: replace visual class state with View conditionsAtlas189c4c8c/components/month-view/month-view.hl

43.8 KB

  1. // month-view.hl — THE MONTH VIEW: prev / next buttons on top, the month's name and the year between them, the
  2. // days below (weeks start on Monday; the days of the neighbouring months are dimmed; today is marked).
  3. // THE CALENDAR'S COPY of the pure-Hybriel month view of components.hybriel.worldapi.org (no .js), plus the user's
  4. // events on the days and the editor for them (add: click a day; edit / delete: click an event). Events come from
  5. // events.hl, one server round trip per change (faces calLoad / calSave / calDelete in calendar.hl). The date
  6. // arithmetic is written here (plain integers), so it runs the same on the server (first render) and in the browser.
  7. // What only the browser knows — today in the user's time zone, the month and weekday names in the user's language,
  8. // the time zone's name (`Date` and `Intl` are browser globals of View handlers) — is read the moment the pointer, a
  9. // finger or the keyboard reaches the month view; until then the server's UTC date and language-neutral names (month number, dots) show — the server never knows
  10. // the language, so it never guesses one: names appear once, in the browser's language, and stay.
  11. // The page reads `year` and `month` (1–12) as its own members. USE ONE PER PAGE: a composed component's
  12. // members are the page's state (COMPONENTS.md §12).
  13. import { serverToday } from '../../lib/clock.hl'
  14. import { pad, daysIn, before } from '../../lib/dates.hl'
  15. import { namesFor } from '../../lib/names.hl'
  16. import { userIdOfSession } from '../../lib/users.hl'
  17. import { eventsBetween, upcoming } from '../../lib/events.hl'
  18. import { defaultsOf } from '../../lib/settings.hl'
  19. import { pushConfigured } from '../../lib/util.hl'
  20. import { notify, subscribePush } from 'hl:web'
  21. import { plan, missed, shift, describe, withIndex, defaultRows } from '../../lib/reminders.hl'
  22. // the request's Accept-Language, handed in by the page (calendar.hl reads it from `headers`, hybriel #105): the first
  23. // render already writes the names
  24. acceptLanguage = null
  25. Hybrid known = namesFor(acceptLanguage)
  26. Boolean namesKnown = known != null
  27. String today = serverToday()
  28. Number year = toNumber(today.slice(0, 4))
  29. Number month = toNumber(today.slice(5, 7))
  30. Hybrid monthNames = namesKnown ? known.months : ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
  31. Hybrid weekdayNames = namesKnown ? known.days : ['·', '·', '·', '·', '·', '·', '·']
  32. String title = monthNames[month - 1] + ' ' + year
  33. Hybrid base = build(year, month, today)
  34. Hybrid weekdays = weekdayNames
  35. session = null
  36. userId = userIdOfSession(session)
  37. Boolean signedIn = userId != null
  38. String winFirst = base[0].date
  39. String winLast = base[41].date
  40. Hybrid events = signedIn ? eventsBetween(userId, winFirst, winLast) : []
  41. Hybrid days = fill(base, events)
  42. // the reminders (ticket calendar#4): the events of the next days with the reminders that apply (`soon`, kept with the page
  43. // state, so an offline page still knows them), the calendar's defaults in words, the timers the browser holds
  44. Hybrid soon = signedIn ? upcoming(userId, shift(today, -2), shift(today, 9)) : []
  45. String defaultText = signedIn ? describe(defaultsOf(userId)) : ''
  46. Hybrid defRows = signedIn ? defaultsOf(userId) : []
  47. Boolean fCustom = false
  48. Hybrid remRows = []
  49. Hybrid setRows = []
  50. Hybrid timers = []
  51. Number lastArm = 0
  52. // P1: arm() is called from several places at once (page load, pageshow, visibilitychange, the server's answer); its notify calls wait
  53. // for the browser, so a second run started in between showed the same missed reminder again and left timers behind. One at a time.
  54. Number arming = 0
  55. Number armAgain = 0
  56. String notifyState = 'unknown'
  57. String setError = ''
  58. Boolean settingsOpen = false
  59. String plannedText = ''
  60. String pushText = ''
  61. Boolean pushTried = false
  62. Boolean pushAvailable = pushConfigured
  63. Boolean pushIsOff = false
  64. Boolean pushOn = false
  65. String fId = ''
  66. String fTitle = ''
  67. Boolean fAllDay = false
  68. String fStartDate = ''
  69. String fStartTime = '09:00'
  70. String fEndDate = ''
  71. String fEndTime = '10:00'
  72. String fPlace = ''
  73. String fNotes = ''
  74. String fZone = 'UTC'
  75. Boolean formOpen = false
  76. Boolean askNotifyVisible = !pushOn && (notifyState == 'default' || (notifyState == 'granted' && pushIsOff))
  77. String formError = ''
  78. String formHeading = 'New event'
  79. Boolean isNew = true
  80. String prevLabel = namesKnown ? known.prev : '‹'
  81. String nextLabel = namesKnown ? known.next : '›'
  82. Number seen = 0
  83. Number paged = 0
  84. // 0 = Monday … 6 = Sunday (Sakamoto's method gives 0 = Sunday)
  85. weekdayOf(Number y, Number m, Number d) {
  86. t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
  87. yy = m < 3 ? y - 1 : y
  88. sun = (yy + (yy - yy % 4) / 4 - (yy - yy % 100) / 100 + (yy - yy % 400) / 400 + t[m - 1] + d) % 7
  89. return (sun + 6) % 7
  90. }
  91. // 42 days (six weeks of seven), so the view keeps its height from month to month
  92. build(Number y, Number m, String todayText) {
  93. py = m == 1 ? y - 1 : y
  94. pm = m == 1 ? 12 : m - 1
  95. ny = m == 12 ? y + 1 : y
  96. nm = m == 12 ? 1 : m + 1
  97. lead = weekdayOf(y, m, 1)
  98. n = daysIn(y, m)
  99. pn = daysIn(py, pm)
  100. out = []
  101. let day = 1 - lead
  102. let w = 0
  103. while (w < 6) {
  104. let i = 0
  105. while (i < 7) {
  106. let cy = y
  107. let cm = m
  108. let cd = day
  109. let outside = false
  110. if (day < 1) { cy = py cm = pm cd = pn + day outside = true }
  111. if (day > n) { cy = ny cm = nm cd = day - n outside = true }
  112. date = cy + '-' + pad(cm) + '-' + pad(cd)
  113. isToday = date == todayText
  114. out.push({ n = cd date = date isOutside = outside && !isToday isToday = isToday })
  115. day = day + 1
  116. i = i + 1
  117. }
  118. w = w + 1
  119. }
  120. return out
  121. }
  122. // the events that touch a day, as four chips on the day cell (a nested `for` does not repaint when the outer list is
  123. // reassigned: hybriel #86 — so the chips are fixed members of the day: t = text, has = visible, more = overflow, v = event id).
  124. // Timed events start with their time on the first day. More than four: the fourth chip says "+N more".
  125. fill(Hybrid list, Hybrid evs) {
  126. out = []
  127. let i = 0
  128. while (i < list.length) {
  129. d = list[i]
  130. hit = []
  131. let j = 0
  132. while (j < evs.length) {
  133. e = evs[j]
  134. if (!before(d.date, e.first) && !before(e.last, d.date)) { hit.push(e) }
  135. j = j + 1
  136. }
  137. row = { n = d.n date = d.date isOutside = d.isOutside isToday = d.isToday addLabel = 'Add event on ' + d.date }
  138. let k = 0
  139. while (k < 4) {
  140. let text = ''
  141. let visible = false
  142. let more = false
  143. let id = ''
  144. if (k < hit.length && (hit.length <= 4 || k < 3)) {
  145. e = hit[k]
  146. text = (e.allDay || d.date != e.first ? '' : e.startTime + ' ') + e.title
  147. visible = true
  148. id = e.id
  149. }
  150. if (k == 3 && hit.length > 4) { text = '+' + (hit.length - 3) + ' more' visible = true more = true }
  151. row['t' + k] = text
  152. row['has' + k] = visible
  153. row['more' + k] = more
  154. row['v' + k] = id
  155. k = k + 1
  156. }
  157. out.push(row)
  158. i = i + 1
  159. }
  160. return out
  161. }
  162. // the form's fields for a new event on `date` (all text; allDay a Boolean); zone = the browser's time zone name
  163. blank(String date, String zone) {
  164. return { id = '' title = '' allDay = false startDate = date startTime = '09:00' endDate = date endTime = '10:00' place = '' notes = '' zone = zone custom = false rows = [] }
  165. }
  166. show(Number y, Number m, Hybrid evs) {
  167. year = y
  168. month = m
  169. title = monthNames[m - 1] + ' ' + y
  170. base = build(y, m, today)
  171. winFirst = base[0].date
  172. winLast = base[41].date
  173. events = evs
  174. days = fill(base, evs)
  175. }
  176. // Layout only (mission 006): the theme (theme/theme.hl, `html month-view …`) tiles the day cells and takes the frames and radii away, buttons
  177. // and fields come from the theme (44 px taps, 16 px fields). Colours: the semantic WorldAPI tokens as css variables, each with its palette
  178. // value as fallback (a component's browser module cannot import tokens.hl itself); the app sets --color-accent in its styles.hl.
  179. // PHONE FIRST: a day cell has no side padding (its event chips are 44 px tall and as wide as the cell); the wide layout is from 60rem.
  180. Style {
  181. selected {
  182. color = 'var(--color-accent-text)'
  183. background = 'var(--color-accent)'
  184. }
  185. monthView { display = 'grid' gap = '.5rem'
  186. header { display = 'flex' flexWrap = 'wrap' alignItems = 'center' justifyContent = 'space-between' gap = '.5rem'
  187. // sync of components.hybriel 4922f9c (MC): the prev / next buttons are 44 px targets on any width (the theme gave 36 px high at 1280)
  188. button { minWidth = '2.75rem' minHeight = '2.75rem' }
  189. }
  190. // calendar#14: on a phone the month name and the Reminder settings button did not fit in one row, so the name broke into two lines
  191. // ("Oktobe / r 2026"). The name never breaks; the button drops to its own row on the right when the row is too narrow.
  192. '#settings-open' { marginLeft = 'auto' }
  193. h2 { margin = '0' fontSize = '1.1rem' color = 'var(--color-text-strong, rgb(245, 250, 255))' textAlign = 'center' flex = '1 1 auto' whiteSpace = 'nowrap' textTransform = 'capitalize' }
  194. '.hidden' { display = 'none' }
  195. }
  196. // the 7-column grid is the weekday row's and the days' only: it used to be `month-view ol`, so it also caught the reminder
  197. // lists (the settings dialog's rows stood in 7 narrow columns, calendar#11)
  198. '#month-weekdays, #month-days' { display = 'grid' gridTemplateColumns = 'repeat(7, minmax(0, 1fr))' margin = '0' padding = '0' listStyle = 'none' }
  199. '#month-weekdays' {
  200. li { margin = '0' padding = '.3rem 0' fontSize = '.8rem' fontWeight = '600' color = 'var(--color-text-muted, rgb(145, 150, 155))' textAlign = 'center' }
  201. }
  202. '#month-days' {
  203. today {
  204. outline = '2px solid var(--color-accent, #569bd4)'
  205. outlineOffset = '-2px'
  206. time {
  207. color = 'var(--color-accent, #569bd4)'
  208. fontWeight = '800'
  209. }
  210. }
  211. outside {
  212. background = 'var(--color-background, rgb(25, 30, 35))'
  213. time { color = 'var(--color-text-muted, rgb(145, 150, 155))' }
  214. }
  215. li {
  216. position = 'relative'
  217. minHeight = '3.5rem'
  218. margin = '0'
  219. padding = '.2rem 0'
  220. textAlign = 'right'
  221. cursor = 'pointer'
  222. overflow = 'hidden'
  223. }
  224. 'li:not(.outside)' { background = 'var(--color-surface, rgb(35, 40, 45))' }
  225. // The add action covers the cell; the date stays visible above it.
  226. 'button.day-add' {
  227. position = 'absolute'
  228. inset = '0'
  229. width = '100%'
  230. height = '100%'
  231. minWidth = '0'
  232. minHeight = '0'
  233. padding = '0'
  234. border = '0'
  235. borderRadius = '0'
  236. background = 'transparent'
  237. focusVisible {
  238. outline = '2px solid var(--color-accent)'
  239. outlineOffset = '-2px'
  240. }
  241. }
  242. time {
  243. pointerEvents = 'none'
  244. position = 'relative'
  245. display = 'block'
  246. paddingRight = '.25rem'
  247. color = 'var(--color-text, rgb(195, 200, 205))'
  248. fontSize = '.95rem'
  249. }
  250. }
  251. // the notifications section of the reminder settings: the state in words, then one full-width button per action (44 px taps)
  252. notifyBox { display = 'grid' gap = '.5rem'
  253. h3 { margin = '0' fontSize = '.85rem' fontWeight = '600' color = 'var(--color-text-muted, rgb(145, 150, 155))' }
  254. p { margin = '0' fontSize = '.85rem' color = 'var(--color-text-muted, rgb(145, 150, 155))'
  255. empty { display = 'none' }
  256. }
  257. button { width = '100%' }
  258. }
  259. reminderBox { display = 'grid' gap = '.4rem'
  260. h3 { margin = '0' fontSize = '.85rem' fontWeight = '600' color = 'var(--color-text-muted, rgb(145, 150, 155))' }
  261. p { margin = '0' fontSize = '.85rem' color = 'var(--color-text-muted, rgb(145, 150, 155))' }
  262. }
  263. // the reminder lists (the event's own, the calendar's defaults): one row per reminder, the full width
  264. '#rem-rows, #set-rows' { display = 'grid' gridTemplateColumns = 'minmax(0, 1fr)' gap = '.5rem' margin = '0' padding = '0' listStyle = 'none' }
  265. // PHONE: a reminder is `[number] [unit, the rest of the width] [×]` and, for "days before, at", the time under them; every
  266. // field is at least a tap (2.75rem) high (the theme); the unit's select takes the width the number and × leave
  267. reminderRow { display = 'grid' gridTemplateColumns = '5rem minmax(0, 1fr) 2.75rem' alignItems = 'center' gap = '.4rem'
  268. input { minWidth = '0' width = '100%' }
  269. select { minWidth = '0' width = '100%' gridColumn = '2' }
  270. 'input[type=time]' { gridColumn = '1 / 3' }
  271. button { gridColumn = '3' gridRow = '1' minWidth = '2.75rem' minHeight = '2.75rem' padding = '0' }
  272. }
  273. // ---- the events on the days and the editors (moved here from styles.hl, calendar#16; the markup is this file's) ----
  274. // PHONE: a cell is 48 px wide, so a chip is the cell's width and at least the tap (44 px, the theme's button size) high; its
  275. // text is cut with an ellipsis. The cell has no side padding so the chip may be that wide.
  276. dayEvents {
  277. position = 'relative'
  278. pointerEvents = 'none'
  279. display = 'grid'
  280. gap = '.15rem'
  281. marginTop = '.2rem'
  282. textAlign = 'left'
  283. }
  284. event {
  285. pointerEvents = 'auto'
  286. display = 'block'
  287. minWidth = '0'
  288. width = '100%'
  289. padding = '.15rem .2rem'
  290. overflow = 'hidden'
  291. fontSize = '.75rem'
  292. fontWeight = '500'
  293. lineHeight = '1.3'
  294. textAlign = 'left'
  295. textOverflow = 'ellipsis'
  296. whiteSpace = 'nowrap'
  297. color = 'var(--color-accent)'
  298. background = 'var(--color-background-sunken)'
  299. }
  300. more = event + {
  301. color = 'var(--color-text-muted)'
  302. background = 'transparent'
  303. }
  304. '#notify-ask' { color = 'var(--color-accent-text)' background = 'var(--color-accent)' }
  305. // the switches (time/all day, the event's own reminders or the calendar's): the chosen one is the accent, the other `quiet`
  306. kindSwitch { display = 'flex' flexWrap = 'wrap' gap = '.5rem'
  307. }
  308. formButtons { display = 'flex' flexWrap = 'wrap' gap = '.5rem'
  309. 'button.danger' { marginLeft = 'auto' }
  310. }
  311. // the editors (event, reminder settings): a full-page scrim with one panel
  312. eventEditor { position = 'fixed' inset = '0' zIndex = '40' display = 'grid' placeItems = 'center' padding = '1rem' background = 'color-mix(in srgb, var(--color-background-sunken) 82%, transparent)'
  313. form { display = 'grid' gap = '.7rem' width = '100%' maxWidth = '28rem' maxHeight = '100%' overflowY = 'auto' padding = '1rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  314. h2 { margin = '0' }
  315. label { display = 'grid' gap = '.2rem' margin = '0' fontSize = '.85rem' fontWeight = '400' color = 'var(--color-text-muted)' }
  316. input { width = '100%' color = 'var(--color-text-strong)' }
  317. textarea { width = '100%' color = 'var(--color-text-strong)' }
  318. }
  319. // the settings dialog is a popover (top layer): the browser's popover defaults (fit-content box, border, margin) give way to the full-page scrim
  320. 'event-editor[popover]' { width = '100%' height = '100%' maxWidth = 'none' maxHeight = 'none' margin = '0' border = '0' overflow = 'hidden' color = 'var(--color-text)' }
  321. 'event-editor[popover]:not(:popover-open)' { display = 'none' }
  322. fieldRow { display = 'grid' gridTemplateColumns = 'minmax(0, 1fr) minmax(0, 1fr)' gap = '.5rem' }
  323. 'field-row:has(label:only-child)' { gridTemplateColumns = 'minmax(0, 1fr)' }
  324. '@media (min-width: 60rem)' {
  325. // the desktop's chips are small on purpose (a pointer; four of them stand in one cell): under 44 px, deliberately
  326. 'button.event, button.more' { minHeight = '0' padding = '.05rem .3rem' borderRadius = 'var(--radius-small)' }
  327. '#month-days' { li { minHeight = '5rem' padding = '.3rem' } }
  328. // the editor's panel is 28rem wide there: the time stands in the row's line again
  329. reminderRow { gridTemplateColumns = '5rem minmax(0, 1fr) 7.5rem 2.75rem'
  330. 'input[type=time]' { gridColumn = '3' }
  331. button { gridColumn = '4' }
  332. }
  333. 'reminder-row:not(:has(input[type=time]))' { select { gridColumn = '2 / 4' } }
  334. }
  335. }
  336. View {
  337. monthView { on pointerover(e) { emit monthEnv(e) } on focusin(e) { emit monthEnv(e) } on touchstart(e) { emit monthEnv(e) }
  338. header {
  339. button { id = "month-prev" type = "button" class = "quiet" title = prevLabel "‹" on click(e) { emit monthPrev(e) } }
  340. h2 { id = "month-title" title }
  341. button { id = "month-next" type = "button" class = "quiet" title = nextLabel "›" on click(e) { emit monthNext(e) } } if (signedIn) { button { id = "settings-open" type = "button" class = "quiet" popovertarget = "settingseditor" popovertargetaction = "show" "Reminder settings" } }
  342. }
  343. ol { id = "month-weekdays" for (name of weekdays) { li { name } } }
  344. ol { id = "month-days"
  345. for (d of days) {
  346. if (d.isToday) { li { Style.today
  347. if (signedIn) { button { type = "button" class = "day-add" 'aria-label' = d.addLabel on click() { addDay(d.date) } } }
  348. time { datetime = d.date d.n }
  349. dayEvents {
  350. if (d.has0) { if (d.more0) { button { Style.more type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } else { button { Style.event type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } }
  351. if (d.has1) { if (d.more1) { button { Style.more type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } else { button { Style.event type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } }
  352. if (d.has2) { if (d.more2) { button { Style.more type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } else { button { Style.event type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } }
  353. if (d.has3) { if (d.more3) { button { Style.more type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } else { button { Style.event type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } }
  354. }
  355. } } else { if (d.isOutside) { li { Style.outside
  356. if (signedIn) { button { type = "button" class = "day-add" 'aria-label' = d.addLabel on click() { addDay(d.date) } } }
  357. time { datetime = d.date d.n }
  358. dayEvents {
  359. if (d.has0) { if (d.more0) { button { Style.more type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } else { button { Style.event type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } }
  360. if (d.has1) { if (d.more1) { button { Style.more type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } else { button { Style.event type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } }
  361. if (d.has2) { if (d.more2) { button { Style.more type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } else { button { Style.event type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } }
  362. if (d.has3) { if (d.more3) { button { Style.more type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } else { button { Style.event type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } }
  363. }
  364. } } else { li {
  365. if (signedIn) { button { type = "button" class = "day-add" 'aria-label' = d.addLabel on click() { addDay(d.date) } } }
  366. time { datetime = d.date d.n }
  367. dayEvents {
  368. if (d.has0) { if (d.more0) { button { Style.more type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } else { button { Style.event type = "button" value = d.v0 d.t0 on click() { pickEvent(d.v0, d.date) } } } }
  369. if (d.has1) { if (d.more1) { button { Style.more type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } else { button { Style.event type = "button" value = d.v1 d.t1 on click() { pickEvent(d.v1, d.date) } } } }
  370. if (d.has2) { if (d.more2) { button { Style.more type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } else { button { Style.event type = "button" value = d.v2 d.t2 on click() { pickEvent(d.v2, d.date) } } } }
  371. if (d.has3) { if (d.more3) { button { Style.more type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } else { button { Style.event type = "button" value = d.v3 d.t3 on click() { pickEvent(d.v3, d.date) } } } }
  372. }
  373. } } }
  374. }
  375. }
  376. if (formOpen) { eventEditor { id = "eventeditor"
  377. form { id = "eventform"
  378. on submit(e) {
  379. e.preventDefault()
  380. emit saveEvent(e)
  381. }
  382. h2 { id = "formheading" formHeading }
  383. kindSwitch {
  384. if (fAllDay) { button { id = "kind-timed" type = "button" "At a time" on click(e) { emit setKind(false) } } } else { button { id = "kind-timed" type = "button" Style.selected "At a time" on click(e) { emit setKind(false) } } }
  385. if (fAllDay) { button { id = "kind-allday" type = "button" Style.selected "All day" on click(e) { emit setKind(true) } } } else { button { id = "kind-allday" type = "button" "All day" on click(e) { emit setKind(true) } } }
  386. }
  387. label { "Title"
  388. input { id = "f-title" name = "title" maxlength = "200" autocomplete = "off" required = "required" value = fTitle on input(e) { emit setF('title', e.target.value) } }
  389. }
  390. fieldRow {
  391. label { "From"
  392. input { id = "f-startdate" name = "startDate" type = "date" required = "required" value = fStartDate on input(e) { emit setF('startDate', e.target.value) } }
  393. }
  394. if (!fAllDay) { label { "at"
  395. input { id = "f-starttime" name = "startTime" type = "time" value = fStartTime on input(e) { emit setF('startTime', e.target.value) } }
  396. } }
  397. }
  398. fieldRow {
  399. label { "To"
  400. input { id = "f-enddate" name = "endDate" type = "date" value = fEndDate on input(e) { emit setF('endDate', e.target.value) } }
  401. }
  402. if (!fAllDay) { label { "at"
  403. input { id = "f-endtime" name = "endTime" type = "time" value = fEndTime on input(e) { emit setF('endTime', e.target.value) } }
  404. } }
  405. }
  406. label { "Place"
  407. input { id = "f-place" name = "place" maxlength = "200" autocomplete = "off" value = fPlace on input(e) { emit setF('place', e.target.value) } }
  408. }
  409. label { "Notes"
  410. textarea { id = "f-notes" name = "notes" rows = "4" maxlength = "5000" value = fNotes on input(e) { emit setF('notes', e.target.value) } }
  411. }
  412. reminderBox {
  413. h3 { "Reminders" }
  414. kindSwitch {
  415. if (fCustom) { button { id = "rem-calendar" type = "button" "Calendar's" on click(e) { emit setCustom(false) } } } else { button { id = "rem-calendar" type = "button" Style.selected "Calendar's" on click(e) { emit setCustom(false) } } }
  416. if (fCustom) { button { id = "rem-own" type = "button" Style.selected "Own" on click(e) { emit setCustom(true) } } } else { button { id = "rem-own" type = "button" "Own" on click(e) { emit setCustom(true) } } }
  417. }
  418. if (!fCustom) { p { id = "rem-default-text" defaultText } }
  419. if (fCustom) { ol { id = "rem-rows"
  420. for (r of remRows) {
  421. reminderRow {
  422. input { type = "number" min = "0" value = r.n on change(e) { emit setRem('rem', r.i, 'n', e.target.value) } }
  423. select { value = r.unit on change(e) { emit setRem('rem', r.i, 'unit', e.target.value) }
  424. option { value = "minutes" "minutes before" }
  425. option { value = "hours" "hours before" }
  426. option { value = "days" "days before, at" }
  427. }
  428. if (r.unit == 'days') { input { type = "time" value = r.time on change(e) { emit setRem('rem', r.i, 'time', e.target.value) } } } else { input { type = "hidden" value = r.time on change(e) { emit setRem('rem', r.i, 'time', e.target.value) } } }
  429. button { type = "button" class = "quiet" "×" on click(e) { emit delRem('rem', r.i) } }
  430. }
  431. }
  432. } }
  433. if (fCustom) { button { id = "rem-add" type = "button" class = "quiet" "Add reminder" on click(e) { emit addRem('rem') } } }
  434. }
  435. p { id = "formerror" class = "message" formError }
  436. formButtons {
  437. button { id = "event-save" type = "submit" "Save" }
  438. button { id = "event-cancel" type = "button" class = "quiet" "Cancel" on click(e) { emit closeForm(e) } }
  439. if (!isNew) { button { id = "event-delete" type = "button" class = "danger" "Delete" on click(e) { emit deleteEvent(e) } } }
  440. }
  441. }
  442. } }
  443. eventEditor { id = "settingseditor" popover = "manual" popoverOpen = settingsOpen on toggle(Hybrid e) { emit settingsToggled(e) } on keydown(Hybrid e) { emit settingsKey(e) }
  444. form { id = "settingsform" class = "timed"
  445. on submit(e) {
  446. e.preventDefault()
  447. emit saveSettings(e)
  448. }
  449. h2 { "Reminder settings" }
  450. notifyBox {
  451. h3 { "Notifications on this device" }
  452. if (notifyState == 'denied') { p { id = "notify-blocked" "Notifications are blocked for this site in the browser settings." } }
  453. p { id = "notify-planned" plannedText }
  454. p { id = "push-state" pushText }
  455. if (askNotifyVisible) { button { id = "notify-ask" type = "button" "Turn on notifications" on click(e) { emit askNotify(e) } } }
  456. if (pushOn) { button { id = "push-test" type = "button" "Send a test notification" on click(e) { emit pushTest(e) } } }
  457. if (pushOn) { button { id = "push-off" type = "button" "Turn off on this device" on click(e) { emit pushOff(e) } } }
  458. }
  459. reminderBox {
  460. h3 { "Default reminders" }
  461. p { class = "muted" "Every event without reminders of its own is reminded like this:" }
  462. ol { id = "set-rows"
  463. for (r of setRows) {
  464. reminderRow {
  465. input { type = "number" min = "0" value = r.n on change(e) { emit setRem('set', r.i, 'n', e.target.value) } }
  466. select { value = r.unit on change(e) { emit setRem('set', r.i, 'unit', e.target.value) }
  467. option { value = "minutes" "minutes before" }
  468. option { value = "hours" "hours before" }
  469. option { value = "days" "days before, at" }
  470. }
  471. if (r.unit == 'days') { input { type = "time" value = r.time on change(e) { emit setRem('set', r.i, 'time', e.target.value) } } } else { input { type = "hidden" value = r.time on change(e) { emit setRem('set', r.i, 'time', e.target.value) } } }
  472. button { type = "button" class = "quiet" "×" on click(e) { emit delRem('set', r.i) } }
  473. }
  474. }
  475. }
  476. button { id = "set-add" type = "button" class = "quiet" "Add reminder" on click(e) { emit addRem('set') } }
  477. }
  478. p { id = "settingserror" class = "message" setError }
  479. formButtons {
  480. button { id = "set-save" type = "submit" "Save" }
  481. button { id = "set-cancel" type = "button" class = "quiet" popovertarget = "settingseditor" popovertargetaction = "hide" autofocus = "autofocus" "Cancel" }
  482. }
  483. }
  484. }
  485. input { id = "month-view-goto" type = "hidden" on change(e) { emit monthGoto(e.target.value) } }
  486. }
  487. }
  488. // the events of the six weeks shown, from the server (none while signed out)
  489. loadEvents(Number y, Number m) {
  490. if (!signedIn) { return [] }
  491. b = build(y, m, today)
  492. r = emit server calLoad(b[0].date, b[41].date)
  493. if (r != null && r.soon != null) { takeSoon(r) }
  494. return r == null || r.events == null ? [] : r.events
  495. }
  496. on monthPrev(Hybrid e) {
  497. browserEnv()
  498. paged = 1
  499. y = month == 1 ? year - 1 : year
  500. m = month == 1 ? 12 : month - 1
  501. show(y, m, loadEvents(y, m))
  502. }
  503. on monthNext(Hybrid e) {
  504. browserEnv()
  505. paged = 1
  506. y = month == 12 ? year + 1 : year
  507. m = month == 12 ? 1 : month + 1
  508. show(y, m, loadEvents(y, m))
  509. }
  510. // the browser's today, language and time zone, once: today follows the user's time zone, the names their language
  511. on monthEnv(Hybrid e) {
  512. browserEnv()
  513. // every ten minutes of use the timers are set again (a long-open page keeps the next week planned)
  514. if (signedIn && Date.now() - lastArm > 600000) { arm() }
  515. }
  516. // the device's IANA time zone, read from the browser each time (arm can run before the first pointer set fZone)
  517. deviceZone() {
  518. z = Intl.DateTimeFormat().resolvedOptions().timeZone
  519. return z != null && z != '' ? z : 'UTC'
  520. }
  521. browserEnv() {
  522. if (seen == 1) { return null }
  523. seen = 1
  524. serverDay = today
  525. now = new Date()
  526. lang = navigator.language != null ? navigator.language : 'en'
  527. zone = Intl.DateTimeFormat().resolvedOptions().timeZone
  528. browserDay = ('' + (10000 + now.getFullYear())).slice(1) + '-' + pad(now.getMonth() + 1) + '-' + pad(now.getDate())
  529. if (browserDay != serverDay) { today = browserDay }
  530. // the server already wrote the names of a language it knows: they stay, so paging never switches them
  531. if (!namesKnown) {
  532. mf = Intl.DateTimeFormat(lang, { month = 'long' timeZone = 'UTC' })
  533. df = Intl.DateTimeFormat(lang, { weekday = 'short' timeZone = 'UTC' })
  534. ms = []
  535. ds = []
  536. let i = 0
  537. while (i < 12) { ms.push(mf.format(new Date(Date.UTC(2024, i, 15, 12)))) i = i + 1 }
  538. i = 0
  539. while (i < 7) { ds.push(df.format(new Date(Date.UTC(2024, 0, 1 + i, 12)))) i = i + 1 }
  540. // (only what differs is assigned: a same-valued assignment still repaints the title and the days)
  541. if (ms.join('|') != monthNames.join('|')) { monthNames = ms }
  542. if (ds.join('|') != weekdayNames.join('|')) { weekdayNames = ds weekdays = ds }
  543. de = lang.slice(0, 2) == 'de'
  544. pl = de ? 'Voriger Monat' : 'Previous month'
  545. nl = de ? 'Nächster Monat' : 'Next month'
  546. if (pl != prevLabel) { prevLabel = pl }
  547. if (nl != nextLabel) { nextLabel = nl }
  548. }
  549. fZone = zone != null && zone != '' ? zone : 'UTC'
  550. readPermission()
  551. // calendar#9: a phone freezes or drops an app it switched away from, and its timers with it. Whenever the app is
  552. // shown again the timers are set again, and what came due meanwhile is shown at once (arm → missed)
  553. // Nothing is repainted unless the browser's day is not the server's: the server already drew this month with its events,
  554. // and a round trip here, answered while the user pages or taps a day, used to put the month back or swallow the tap.
  555. if (browserDay == serverDay) {
  556. if (!namesKnown) {
  557. named = monthNames[month - 1] + ' ' + year
  558. if (named != title) { title = named }
  559. }
  560. } else if (paged == 0) {
  561. // the month shown follows the corrected today only while the user has not paged yet (also when they page meanwhile)
  562. y = toNumber(today.slice(0, 4))
  563. m = toNumber(today.slice(5, 7))
  564. evs = loadEvents(y, m)
  565. if (paged == 0) { show(y, m, evs) } else { show(year, month, events) }
  566. } else { show(year, month, events) }
  567. // (offline the server did not answer: the timers are set from the reminders the page already holds)
  568. arm()
  569. }
  570. // ---- the reminders: notifications the browser holds a timer for (they fire while the app or its worker is open, also offline) ----
  571. // the server's newest answer about the reminders to come; the timers are set again from it
  572. takeSoon(Hybrid r) {
  573. soon = r.soon
  574. if (r.defaults != null) { defaultText = r.defaults }
  575. if (r.defaultRows != null) { defRows = r.defaultRows }
  576. arm()
  577. }
  578. // one timer per reminder that is still to come within a week; the old timers are dropped first. Before that, calendar#9:
  579. // the reminders that came due since this device last planned or showed one, while no timer could fire (the app switched
  580. // away and frozen, dropped, or closed), are shown now — late, for events that have not started yet
  581. arm() {
  582. if (arming == 1) {
  583. armAgain = 1
  584. return null
  585. }
  586. arming = 1
  587. armOnce()
  588. while (armAgain == 1) {
  589. armAgain = 0
  590. armOnce()
  591. }
  592. arming = 0
  593. return null
  594. }
  595. armOnce() {
  596. if (!signedIn) { return null }
  597. let i = 0
  598. while (i < timers.length) { clearTimeout(timers[i]) i = i + 1 }
  599. nowMs = Date.now()
  600. readPermission()
  601. let since = remindedUntil(nowMs)
  602. if (notifyState == 'granted') {
  603. since = pushedSince(since)
  604. late = missed(soon, since, nowMs, today, deviceZone())
  605. i = 0
  606. while (i < late.length) {
  607. q = late[i]
  608. notify(q.title, { body = q.late tag = q.key icon = '/icons/icon-192.png' })
  609. i = i + 1
  610. }
  611. }
  612. remember(nowMs)
  613. list = plan(soon, nowMs, 604800000, deviceZone())
  614. ids = []
  615. i = 0
  616. while (i < list.length) {
  617. // `p` is a new binding on every pass (hybriel #106): each timer keeps ITS reminder
  618. p = list[i]
  619. ids.push(setTimeout(() => {
  620. remember(p.at)
  621. notify(p.title, { body = p.body tag = p.key icon = '/icons/icon-192.png' })
  622. }, p.at - nowMs))
  623. i = i + 1
  624. }
  625. timers = ids
  626. lastArm = nowMs
  627. // calendar#9 part 2: a device that already allowed notifications is subscribed to Web Push once per page (its own handler:
  628. // the browser's subscribe can take long and must not hold the timers)
  629. if (!pushTried && notifyState == 'granted') {
  630. pushTried = true
  631. emit pushEnsure(1)
  632. }
  633. plannedText = list.length == 0 ? '' : (list.length == 1 ? '1 reminder' : list.length + ' reminders') + ' set for the next 7 days'
  634. }
  635. // P1: a device with push gets its reminders from the server, even when the page is closed. A reminder the server pushed
  636. // (shown, tapped, swiped away) must not be shown again by this page as "missed": the later of the page's own instant and the
  637. // server's. Without a subscription, or if the server does not answer, the page's own instant stays.
  638. pushedSince(Number own) {
  639. if (!pushAvailable || pushOffKept()) { return own }
  640. reg = navigator.serviceWorker != null ? navigator.serviceWorker.getRegistration() : null
  641. sub = reg != null && reg.pushManager != null ? reg.pushManager.getSubscription() : null
  642. if (sub == null) { return own }
  643. r = emit server calPushedUntil(sub.endpoint)
  644. return r != null && r.since != null && r.since > own ? r.since : own
  645. }
  646. // the instant up to which this device has planned or shown the user's reminders (the browser's localStorage); none
  647. // kept yet → the last 12 hours count as missed
  648. remindedKey() {
  649. return 'calendar-reminded-until-' + userId
  650. }
  651. remindedUntil(Number nowMs) {
  652. store = window.localStorage
  653. kept = store != null ? store.getItem(remindedKey()) : null
  654. return kept != null && kept != '' ? toNumber(kept) : nowMs - 43200000
  655. }
  656. remember(Number at) {
  657. store = window.localStorage
  658. if (store == null) { return null }
  659. kept = store.getItem(remindedKey())
  660. if (kept == null || kept == '' || toNumber(kept) < at) { store.setItem(remindedKey(), '' + at) }
  661. }
  662. // ONE state for the notification section (C13): `pushOn` (this device is subscribed to push) and `notifyState` / `pushIsOff` decide
  663. // every control at once — "Turn on" only while not on, test + off only while on, the blocked hint only when blocked
  664. readPermission() {
  665. n = window.Notification
  666. notifyState = n == null ? 'unsupported' : n.permission
  667. pushIsOff = pushOffKept()
  668. updateNotificationText()
  669. }
  670. updateNotificationText() {
  671. if (!pushOn && notifyState == 'unsupported') { pushText = 'This browser cannot show notifications.' }
  672. if (!pushOn && pushText == '') { pushText = 'Reminders show while the calendar is open on this device.' }
  673. }
  674. // the button is the click the browser wants before it allows notifications
  675. on askNotify(Hybrid e) {
  676. browserEnv()
  677. notify('Notifications are on', { body = 'Your reminders show up here.' })
  678. pushTried = true
  679. pushOffKeep(false)
  680. readPermission()
  681. emit pushEnsure(1)
  682. }
  683. // "Turn off on this device": the browser drops its push subscription and the server forgets the device. The choice is kept
  684. // (localStorage) so that this device is not subscribed again at the next page; "Turn on notifications" undoes it.
  685. on pushOff(Hybrid e) {
  686. browserEnv()
  687. pushOffKeep(true)
  688. reg = navigator.serviceWorker != null ? navigator.serviceWorker.getRegistration() : null
  689. sub = reg != null && reg.pushManager != null ? reg.pushManager.getSubscription() : null
  690. if (sub != null) {
  691. endpoint = sub.endpoint
  692. sub.unsubscribe()
  693. emit server calPushOff(endpoint)
  694. }
  695. pushOn = false
  696. pushText = 'Reminders show while the calendar is open on this device.'
  697. readPermission()
  698. }
  699. // "Send a test notification": the server sends ONE push to this device in ~10 seconds; leave the app and it arrives like a reminder
  700. on pushTest(Hybrid e) {
  701. browserEnv()
  702. reg = navigator.serviceWorker != null ? navigator.serviceWorker.getRegistration() : null
  703. sub = reg != null && reg.pushManager != null ? reg.pushManager.getSubscription() : null
  704. if (sub == null) {
  705. pushText = 'This device is not subscribed: tap "Turn on notifications" first.'
  706. return null
  707. }
  708. r = emit server calPushTest(sub.endpoint)
  709. pushText = r != null && r.ok ? 'A test notification is on its way (about 10 seconds). Close the calendar or lock the phone now: "Calendar test - Push works on this device" should appear.' : 'The test could not be started: ' + (r != null && r.error != null ? r.error : 'no answer')
  710. }
  711. pushOffKey() {
  712. return 'calendar-push-off-' + userId
  713. }
  714. pushOffKept() {
  715. store = window.localStorage
  716. return store != null && store.getItem(pushOffKey()) == '1'
  717. }
  718. pushOffKeep(Boolean off) {
  719. store = window.localStorage
  720. if (store == null) { return null }
  721. if (off) { store.setItem(pushOffKey(), '1') } else { store.removeItem(pushOffKey()) }
  722. pushIsOff = off
  723. }
  724. // calendar#9 part 2: this device's Web Push subscription goes to the server, which sends the reminders to it when the page
  725. // is closed. No push (no key on the server, no browser support, refused) leaves the page's own timers as they were.
  726. on pushEnsure(Number n) {
  727. if (!signedIn || !pushAvailable || notifyState != 'granted' || pushOffKept()) { return null }
  728. sub = subscribePush()
  729. if (sub == null) {
  730. pushText = 'Reminders show while the calendar is open on this device.'
  731. pushOn = false
  732. updateNotificationText()
  733. return null
  734. }
  735. r = emit server calPushSave(sub, fZone)
  736. pushText = r != null && r.ok ? 'Reminders also reach this device when the calendar is closed.' : 'Reminders show while the calendar is open on this device.'
  737. pushOn = r != null && r.ok
  738. updateNotificationText()
  739. }
  740. // the page is shown (first show included): a device that already allowed notifications is subscribed / its subscription
  741. // refreshed now, not at the user's first touch
  742. on client shown(Hybrid r) {
  743. if (seen == 0) { browserEnv() } else { arm() }
  744. }
  745. // from a host script (the date picker): "YYYY-MM-DD" → show that date's month
  746. on monthGoto(String text) {
  747. paged = 1
  748. y = toNumber(text.slice(0, 4))
  749. m = toNumber(text.slice(5, 7))
  750. show(y, m, loadEvents(y, m))
  751. }
  752. // ---- the editor ----
  753. openForm(Hybrid fields, String heading, Boolean fresh) {
  754. fId = fields.id
  755. fTitle = fields.title
  756. fAllDay = fields.allDay
  757. fStartDate = fields.startDate
  758. fStartTime = fields.startTime
  759. fEndDate = fields.endDate
  760. fEndTime = fields.endTime
  761. fPlace = fields.place
  762. fNotes = fields.notes
  763. isNew = fresh
  764. fCustom = fields.custom
  765. remRows = withIndex(fields.rows)
  766. formHeading = heading
  767. formError = ''
  768. formOpen = true
  769. }
  770. // Each day and chip carries its action's date or event id from the loop record.
  771. addDay(String date) {
  772. if (!signedIn) { return null }
  773. openForm(blank(date, fZone), 'New event', true)
  774. }
  775. pickEvent(String id, String date) {
  776. if (!signedIn) { return null }
  777. // The overflow chip has always opened a new event for its day.
  778. if (id == '') { addDay(date) return null }
  779. let j = 0
  780. while (j < events.length) {
  781. ev = events[j]
  782. if (ev.id == id) {
  783. fields = { id = ev.id title = ev.title allDay = ev.allDay startDate = ev.startDate startTime = ev.startTime endDate = ev.endDate endTime = ev.endTime place = ev.place notes = ev.notes zone = fZone custom = ev.custom rows = ev.rows }
  784. openForm(fields, 'Edit event', false)
  785. return null
  786. }
  787. j = j + 1
  788. }
  789. }
  790. on setF(String name, String value) {
  791. if (name == 'title') { fTitle = value }
  792. if (name == 'startDate') { fStartDate = value }
  793. if (name == 'startTime') { fStartTime = value }
  794. if (name == 'endDate') { fEndDate = value }
  795. if (name == 'endTime') { fEndTime = value }
  796. if (name == 'place') { fPlace = value }
  797. if (name == 'notes') { fNotes = value }
  798. }
  799. on setCustom(Boolean own) {
  800. fCustom = own
  801. // switching to own reminders starts from the calendar's, so nothing has to be typed for the usual case
  802. if (own && remRows.length == 0) { remRows = withIndex(defaultRows) }
  803. }
  804. // one reminder row of the event editor (which = 'rem') or of the settings (which = 'set')
  805. on setRem(String which, Number i, String field, String value) {
  806. rows = which == 'rem' ? remRows : setRows
  807. if (i < 0 || i >= rows.length) { return null }
  808. out = []
  809. let k = 0
  810. while (k < rows.length) {
  811. r = rows[k]
  812. let n = r.n
  813. let unit = r.unit
  814. let time = r.time
  815. if (k == i && field == 'n') { n = value }
  816. if (k == i && field == 'unit') { unit = value }
  817. if (k == i && field == 'time') { time = value }
  818. out.push({ unit = unit n = n time = time })
  819. k = k + 1
  820. }
  821. if (which == 'rem') { remRows = withIndex(out) } else { setRows = withIndex(out) }
  822. }
  823. on addRem(String which) {
  824. rows = which == 'rem' ? remRows : setRows
  825. out = []
  826. let k = 0
  827. while (k < rows.length) { out.push({ unit = rows[k].unit n = rows[k].n time = rows[k].time }) k = k + 1 }
  828. out.push({ unit = 'minutes' n = '10' time = '09:00' })
  829. if (which == 'rem') { remRows = withIndex(out) } else { setRows = withIndex(out) }
  830. }
  831. on delRem(String which, Number i) {
  832. rows = which == 'rem' ? remRows : setRows
  833. out = []
  834. let k = 0
  835. while (k < rows.length) {
  836. if (k != i) { out.push({ unit = rows[k].unit n = rows[k].n time = rows[k].time }) }
  837. k = k + 1
  838. }
  839. if (which == 'rem') { remRows = withIndex(out) } else { setRows = withIndex(out) }
  840. }
  841. // ---- the calendar settings: the default reminders ----
  842. // the dialog is a MANUAL popover (a nested auto one would be closed with the menu that opened it; the menu's "Reminder settings" opens it declaratively, popovertarget — the menu lives in the shell, outside this
  843. // component): opening it is the event that reads the device's state and the calendar's defaults
  844. on settingsToggled(Hybrid e) {
  845. settingsOpen = e.newState == 'open'
  846. if (e.newState != 'open') { return null }
  847. // no pointer event of the month view may have come yet, so the page's browser state is read now —
  848. // the notification section is right on the first look (and a device that allowed notifications is subscribed)
  849. browserEnv()
  850. readPermission()
  851. r = emit server calSettingsLoad()
  852. if (r == null || r.error != null) {
  853. setError = r == null ? 'the settings need the server: you are offline' : r.error
  854. return null
  855. }
  856. setRows = withIndex(r.rows)
  857. setError = ''
  858. }
  859. // Escape closes it (a manual popover has no light dismiss: it must stay open when the menu, which opened it, closes)
  860. on settingsKey(Hybrid e) {
  861. if (e.key == 'Escape') { settingsOpen = false }
  862. }
  863. on saveSettings(Hybrid e) {
  864. r = emit server calSettingsSave(setRows)
  865. if (r == null || r.error != null) {
  866. setError = r == null ? 'the settings could not be saved (offline?)' : r.error
  867. return null
  868. }
  869. settingsOpen = false
  870. takeSoon(r)
  871. }
  872. on setKind(Boolean allDay) {
  873. fAllDay = allDay
  874. if (!allDay && fStartTime == '') { fStartTime = '09:00' }
  875. if (!allDay && fEndTime == '' && fEndDate != '') { fEndTime = '10:00' }
  876. }
  877. on closeForm(Hybrid e) {
  878. formOpen = false
  879. }
  880. // what the form holds, as the face takes it
  881. formFields() {
  882. return { id = fId title = fTitle allDay = fAllDay startDate = fStartDate startTime = fStartTime endDate = fEndDate endTime = fEndTime place = fPlace notes = fNotes zone = fZone custom = fCustom reminders = remRows }
  883. }
  884. // the event as the page shows it, for an event saved while offline (the server sends the real one when it is back)
  885. localView(Hybrid f) {
  886. allDay = f.allDay
  887. last = f.endDate != '' ? f.endDate : f.startDate
  888. mine = []
  889. let k = 0
  890. while (k < f.reminders.length) { mine.push({ unit = f.reminders[k].unit n = f.reminders[k].n time = f.reminders[k].time }) k = k + 1 }
  891. return { id = f.id title = f.title allDay = allDay first = f.startDate last = last
  892. startDate = f.startDate startTime = allDay ? '' : f.startTime endDate = f.endDate endTime = allDay ? '' : f.endTime
  893. place = f.place notes = f.notes start = f.startDate zone = f.zone custom = f.custom rows = f.custom ? mine : defRows }
  894. }
  895. on saveEvent(Hybrid e) {
  896. f = formFields()
  897. if (fTitle.trim() == '' || fStartDate == '') {
  898. formError = 'the event needs a title and a start date'
  899. return null
  900. }
  901. r = emit server calSave(f, winFirst, winLast)
  902. if (r == null) {
  903. // OFFLINE: the save waits in the app's queue (it is sent when the connection is back); here the event and its
  904. // reminders are set at once, so the notification still comes
  905. if (f.id == '') { f.id = 'local-' + Date.now() }
  906. emit server calSaveQueued(f, winFirst, winLast)
  907. v = localView(f)
  908. evs = []
  909. let k = 0
  910. while (k < events.length) { if (events[k].id != v.id) { evs.push(events[k]) } k = k + 1 }
  911. evs.push(v)
  912. mine = []
  913. k = 0
  914. while (k < soon.length) { if (soon[k].id != v.id) { mine.push(soon[k]) } k = k + 1 }
  915. mine.push({ id = v.id title = v.title allDay = v.allDay startDate = v.startDate startTime = v.startTime place = v.place zone = v.zone rows = v.rows })
  916. soon = mine
  917. formOpen = false
  918. show(year, month, evs)
  919. arm()
  920. return null
  921. }
  922. if (r.error != null) {
  923. formError = r.error
  924. return null
  925. }
  926. formOpen = false
  927. takeSoon(r)
  928. show(year, month, r.events)
  929. }
  930. on deleteEvent(Hybrid e) {
  931. r = emit server calDelete(fId, winFirst, winLast)
  932. if (r == null || r.error != null) {
  933. formError = r == null ? 'the event could not be deleted (offline?)' : r.error
  934. return null
  935. }
  936. formOpen = false
  937. takeSoon(r)
  938. show(year, month, r.events)
  939. }

Branches

Latest commits

  • 189c4c8c|||PR WIP calendar28: replace visual class state with View conditionsAtlas
  • fff2f537Merge branch 'calendar31-lib' into mainAtlas
  • 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
  • a753b0ab|||PR move shared calendar logic to libAtlas
  • b32a921dMerge branch 'vendor-day72' into mainAtlas
  • 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
  • 53f5464dMerge branch 'calendar26-day73' into mainAtlas
  • 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
  • ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
  • cab224a1Re-vendor calendar to verified Hybriel day73Atlas
  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas