mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
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 !
15 lines
732 B
JavaScript
15 lines
732 B
JavaScript
import '/client/components/forms/datepicker.jade';
|
|
import '/client/components/forms/inlinedform.jade';
|
|
|
|
import '/client/lib/inlinedform';
|
|
// No datepicker.js: the template in datepicker.jade is `editDateForm`, which
|
|
// renders what it is passed and has no state of its own. The state and the
|
|
// handlers belong to the eight popups that include it, and come from
|
|
// client/lib/datepicker.js. The template this file used to wire up - a ninth
|
|
// copy of the same form, called `datepicker` - was included by nothing and
|
|
// could not be opened as a popup either (a popup's template name ends in
|
|
// `Popup`), so it went with the duplication.
|
|
|
|
import '/client/components/forms/datepicker.css';
|
|
import '/client/components/forms/forms.css';
|