calendar
All repositories: gitoria
10.2 KB
import { editRow, addRow, removeRow } from '../lib/reminder-rows.hl'// Event editor: form state and validation; the host owns the visible month's data.import { withIndex, defaultRows } from '../lib/reminders.hl'request = nullwinFirst = ''winLast = ''defaultText = ''defRows = []Boolean fCustom = falseHybrid remRows = []String fId = ''String fTitle = ''Boolean fAllDay = falseString fStartDate = ''String fStartTime = '09:00'String fEndDate = ''String fEndTime = '10:00'String fPlace = ''String fNotes = ''String fZone = 'UTC'String formClass = 'closed'String formError = ''String formHeading = 'New event'Boolean isNew = trueString formKind = 'timed'String ownClass = 'quiet'String calClass = ''String defaultClass = ''String rowsClass = 'hidden'String addClass = 'quiet hidden'String timedButton = ''String alldayButton = 'quiet'String deleteClass = 'danger hidden'set request(Hybrid value) {if (value != null) { fZone = value.fields.zone openForm(value.fields, value.heading, value.fresh) }}Style {reminderBox {display = 'grid'gap = '.4rem'h3 {margin = '0'fontSize = '.85rem'fontWeight = '600'color = 'var(--color-text-muted, rgb(145, 150, 155))'}p {margin = '0'fontSize = '.85rem'color = 'var(--color-text-muted, rgb(145, 150, 155))'}}'#rem-rows' {display = 'grid'gridTemplateColumns = 'minmax(0, 1fr)'gap = '.5rem'margin = '0'padding = '0'listStyle = 'none'}reminderRow {display = 'grid'gridTemplateColumns = '5rem minmax(0, 1fr) 2.75rem'alignItems = 'center'gap = '.4rem'input {minWidth = '0'width = '100%'}select {minWidth = '0'width = '100%'gridColumn = '2'}'input[type=time]' {gridColumn = '1 / 3'}button {gridColumn = '3'gridRow = '1'minWidth = '2.75rem'minHeight = '2.75rem'padding = '0'}}'reminder-row.other' {'input[type=time]' {display = 'none'}}kindSwitch {display = 'flex'flexWrap = 'wrap'gap = '.5rem''button:not(.quiet)' {color = 'var(--color-accent-text)'background = 'var(--color-accent)'}}formButtons {display = 'flex'flexWrap = 'wrap'gap = '.5rem''button.danger' {marginLeft = 'auto'}}eventEditor {position = 'fixed'inset = '0'zIndex = '40'display = 'grid'placeItems = 'center'padding = '1rem'background = 'color-mix(in srgb, var(--color-background-sunken) 82%, transparent)'form {display = 'grid'gap = '.7rem'width = '100%'maxWidth = '28rem'maxHeight = '100%'overflowY = 'auto'padding = '1rem'background = 'var(--color-surface)'borderRadius = 'var(--radius-large)'}h2 {margin = '0'}label {display = 'grid'gap = '.2rem'margin = '0'fontSize = '.85rem'fontWeight = '400'color = 'var(--color-text-muted)'}input {width = '100%'color = 'var(--color-text-strong)'}textarea {width = '100%'color = 'var(--color-text-strong)'}}'event-editor.closed' {display = 'none'}'event-editor[popover]' {width = '100%'height = '100%'maxWidth = 'none'maxHeight = 'none'margin = '0'border = '0'overflow = 'hidden'color = 'var(--color-text)'}'event-editor[popover]:not(:popover-open)' {display = 'none'}fieldRow {display = 'grid'gridTemplateColumns = 'minmax(0, 1fr) minmax(0, 1fr)'gap = '.5rem'}'form.allday' {'label.timed' {display = 'none'}fieldRow {gridTemplateColumns = 'minmax(0, 1fr)'}}@media {minWidth = '60rem'reminderRow {gridTemplateColumns = '5rem minmax(0, 1fr) 7.5rem 2.75rem''input[type=time]' {gridColumn = '3'}button {gridColumn = '4'}}'reminder-row.other' {select {gridColumn = '2 / 4'}}}'.hidden' {display = 'none'}}View {eventEditor { id = "eventeditor" class = formClassform { id = "eventform" class = formKindon submit(Hybrid e) {e.preventDefault()emit saveEvent(e)}h2 { id = "formheading" formHeading }kindSwitch {button { id = "kind-timed" type = "button" class = timedButton "At a time" on click(Hybrid e) { emit setKind(false) } }button { id = "kind-allday" type = "button" class = alldayButton "All day" on click(Hybrid e) { emit setKind(true) } }}label { "Title"input { id = "f-title" name = "title" maxlength = "200" autocomplete = "off" required = "required" value = fTitle on input(Hybrid e) { emit setF('title', e.target.value) } }}fieldRow {label { "From"input { id = "f-startdate" name = "startDate" type = "date" required = "required" value = fStartDate on input(Hybrid e) { emit setF('startDate', e.target.value) } }}label { class = "timed" "at"input { id = "f-starttime" name = "startTime" type = "time" value = fStartTime on input(Hybrid e) { emit setF('startTime', e.target.value) } }}}fieldRow {label { "To"input { id = "f-enddate" name = "endDate" type = "date" value = fEndDate on input(Hybrid e) { emit setF('endDate', e.target.value) } }}label { class = "timed" "at"input { id = "f-endtime" name = "endTime" type = "time" value = fEndTime on input(Hybrid e) { emit setF('endTime', e.target.value) } }}}label { "Place"input { id = "f-place" name = "place" maxlength = "200" autocomplete = "off" value = fPlace on input(Hybrid e) { emit setF('place', e.target.value) } }}label { "Notes"textarea { id = "f-notes" name = "notes" rows = "4" maxlength = "5000" value = fNotes on input(Hybrid e) { emit setF('notes', e.target.value) } }}reminderBox {h3 { "Reminders" }kindSwitch {button { id = "rem-calendar" type = "button" class = calClass "Calendar's" on click(Hybrid e) { emit setCustom(false) } }button { id = "rem-own" type = "button" class = ownClass "Own" on click(Hybrid e) { emit setCustom(true) } }}p { id = "rem-default-text" class = defaultClass defaultText }ol { id = "rem-rows" class = rowsClassfor (r of remRows) {reminderRow { class = r.clsinput { type = "number" min = "0" value = r.n on change(Hybrid e) { emit setRem('rem', r.i, 'n', e.target.value) } }select { value = r.unit on change(Hybrid e) { emit setRem('rem', r.i, 'unit', e.target.value) }option { value = "minutes" "minutes before" }option { value = "hours" "hours before" }option { value = "days" "days before, at" }}input { type = "time" value = r.time on change(Hybrid e) { emit setRem('rem', r.i, 'time', e.target.value) } }button { type = "button" class = "quiet" "×" on click(Hybrid e) { emit delRem('rem', r.i) } }}}}button { id = "rem-add" type = "button" class = addClass "Add reminder" on click(Hybrid e) { emit addRem('rem') } }}p { id = "formerror" class = "message" formError }formButtons {button { id = "event-save" type = "submit" "Save" }button { id = "event-cancel" type = "button" class = "quiet" "Cancel" on click(Hybrid e) { emit closeForm(e) } }button { id = "event-delete" type = "button" class = deleteClass "Delete" on click(Hybrid e) { emit deleteEvent(e) } }}}}}syncCustom() {calClass = fCustom ? 'quiet' : ''ownClass = fCustom ? '' : 'quiet'defaultClass = fCustom ? 'hidden' : ''rowsClass = fCustom ? '' : 'hidden'addClass = fCustom ? 'quiet' : 'quiet hidden'}syncForm() {formKind = fAllDay ? 'allday' : 'timed'timedButton = fAllDay ? 'quiet' : ''alldayButton = fAllDay ? '' : 'quiet'deleteClass = isNew ? 'danger hidden' : 'danger'}openForm(Hybrid fields, String heading, Boolean fresh) {fId = fields.idfTitle = fields.titlefAllDay = fields.allDayfStartDate = fields.startDatefStartTime = fields.startTimefEndDate = fields.endDatefEndTime = fields.endTimefPlace = fields.placefNotes = fields.notesisNew = freshfCustom = fields.customremRows = withIndex(fields.rows)syncCustom()formHeading = headingformError = ''formClass = 'open'syncForm()}on setF(String name, String value) {if (name == 'title') { fTitle = value }if (name == 'startDate') { fStartDate = value }if (name == 'startTime') { fStartTime = value }if (name == 'endDate') { fEndDate = value }if (name == 'endTime') { fEndTime = value }if (name == 'place') { fPlace = value }if (name == 'notes') { fNotes = value }}on setCustom(Boolean own) {fCustom = own// switching to own reminders starts from the calendar's, so nothing has to be typed for the usual caseif (own && remRows.length == 0) { remRows = withIndex(defaultRows) }syncCustom()}on setRem(String which, Number i, String field, String value) {remRows = editRow(remRows, i, field, value)}on addRem(String which) {remRows = addRow(remRows)}on delRem(String which, Number i) {remRows = removeRow(remRows, i)}on setKind(Boolean allDay) {fAllDay = allDayif (!allDay && fStartTime == '') { fStartTime = '09:00' }if (!allDay && fEndTime == '' && fEndDate != '') { fEndTime = '10:00' }syncForm()}on closeForm(Hybrid e) {formClass = 'closed'}formFields() {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 }}on saveEvent(Hybrid e) {f = formFields()if (fTitle.trim() == '' || fStartDate == '') {formError = 'the event needs a title and a start date'return null}r = emit server calSave(f, winFirst, winLast)if (r == null) {// OFFLINE: the save waits in the app's queue (it is sent when the connection is back); here the event and its// reminders are set at once, so the notification still comesif (f.id == '') { f.id = 'local-' + Date.now() }emit server calSaveQueued(f, winFirst, winLast)$parent.saveOffline(f)formClass = 'closed'return null}if (r.error != null) {formError = r.errorreturn null}formClass = 'closed'$parent.saved(r)}on deleteEvent(Hybrid e) {r = emit server calDelete(fId, winFirst, winLast)if (r == null || r.error != null) {formError = r == null ? 'the event could not be deleted (offline?)' : r.errorreturn null}formClass = 'closed'$parent.saved(r)}
Branches
Latest commits
- 651752c0|||PR run the browser gate once per deployAtlas
- e24e28a1|||PR preserve calendar state across month addresses and split dialogsAtlas
- 384d3d23|||PR give calendar months their own addressAtlas
- 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