Files
wekan/client/components/forms/datepicker.jade
T
Lauri Ojansivu 9c288c3d4d Date templates: one edit form and one badge instead of twenty-two copies.
Two shapes were copied across three files. The edit-a-date form - date, time,
Save, Delete - existed eight times, letter for letter: the card's Received,
Start, Due and End, a vote's end date, a planning poker's end date, a date
custom field, and a ninth `datepicker` template that nothing included and no
popup could open (a popup's template name ends in `Popup`). The date badge -
the coloured date on a card and on a minicard - existed fourteen times.

The JavaScript was already shared: client/lib/datepicker.js holds the state and
the handlers, and each popup differs only in the field it stores. It was only
the markup, so a change to the form meant eight edits and a change to the badge
meant fourteen, with nothing to say so.

Each is one template now - editDateForm and dateBadgeBody. They take what they
draw as ARGUMENTS, because a helper is looked up on the template it is written
in and not on the one including it: that is what lets one piece of markup serve
them all while every popup keeps its own state, its own click and its own name.
cardDate.jade went from 289 lines to 91, and the dead datepicker.js went with
the template it wired up.

The badge's `baseClass` is the trap this had to avoid: three of the fourteen -
the custom-field dates - were never `.card-date` and must not become one, so
the class each caller carried is passed in rather than baked into the shared
markup. tests/dateTemplates.test.cjs pins that, the minicard kind classes, and
that no state moved.

Thanks to xet7 !
2026-08-14 06:48:47 +03:00

30 lines
1.4 KiB
Plaintext

//- The date-and-time form every "edit a date" popup is made of: the card's
//- Received, Start, Due and End dates, a vote's and a planning poker's end
//- date, and a date custom field. Eight popups drew this same form, letter for
//- letter, in three different files.
//-
//- It takes what it shows as ARGUMENTS rather than reading helpers: a helper
//- inside a template is looked up on that template, not on the one including
//- it, and all eight popups keep their own state and handlers
//- (client/lib/datepicker.js, which they already shared - it was only the
//- markup that was copied). So this template has no code of its own at all;
//- it renders three values and the buttons.
//-
//- The buttons are handled where the state is: `js-submit-date` and
//- `js-delete-date` bubble to the popup that includes this, whose events come
//- from datePickerEvents().
template(name="editDateForm")
.datepicker-container
form.edit-date
.fields
.left
label(for="date") {{_ 'date'}}
input.js-date-field#date(type="date" name="date" value=showDate autofocus)
.right
label(for="time") {{_ 'time'}}
input.js-time-field#time(type="time" name="time" value=showTime)
if error.get
.warning {{_ error.get}}
button.primary.wide.left.js-submit-date(type="submit") {{_ 'save'}}
button.js-delete-date.negate.wide.right.js-delete-date {{_ 'delete'}}