Files
wekan/client/components/forms/calendarTimeInput.js
T
Lauri Ojansivu 5057a0a2c1 Add member-selected calendars and accessible date and time controls
Apply the selected calendar to shared date displays, calendar month views and date inputs. Provide mouse and keyboard date navigation and hour/minute selection while preserving native date storage. Document the supported offline calendars and add display, picker and browser regressions.

Thanks to mimZD and xet7 !
2026-09-12 21:01:41 +03:00

44 lines
1.5 KiB
JavaScript

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { initialTimeValue, parseTimeInput } from '/imports/lib/datePickerTime';
Template.calendarTimeInput.onCreated(function () {
this.time = new ReactiveVar('12:00');
this.autorun(() => {
const data = Template.currentData();
this.time.set((data.value ? parseTimeInput(data.value) : null) || initialTimeValue(null, data.defaultTime) || '12:00');
});
});
Template.calendarTimeInput.helpers({
hours() {
const selected = Template.instance().time.get().split(':')[0];
return Array.from({ length: 24 }, (_, number) => {
const value = String(number).padStart(2, '0');
return { value, selected: value === selected };
});
},
minutes() {
const selected = Template.instance().time.get().split(':')[1];
return Array.from({ length: 60 }, (_, number) => {
const value = String(number).padStart(2, '0');
return { value, selected: value === selected };
});
},
nativeTime() { return Template.instance().time.get(); },
});
Template.calendarTimeInput.events({
'change .js-calendar-native-time'(event, tpl) {
const value = parseTimeInput(event.currentTarget.value);
if (value) tpl.time.set(value);
},
'change select'(event, tpl) {
const value = `${tpl.find('.js-calendar-hour').value}:${tpl.find('.js-calendar-minute').value}`;
tpl.time.set(value);
const input = tpl.find('.js-calendar-native-time');
input.value = value;
input.dispatchEvent(new Event('change', { bubbles: true }));
},
});