Reset Calendar-Event Datetimes in Event Editor
Hi!
We are currently working on customizing the event editor to fit our needs.
One use case we need to provide is to reset the event's duration to its initial duration (already saved in our event model) within the event editor. To do so, we want to provide an additional Button underneath the Datetime Inputs. When clicking the button, we want to reset the values of the endDate and -Time in order to fit the initial duration. The problem right now is that we can't access the eventRecord within the eventEdit to get the initial_duration. (When customizing the context menu of an event this was possible, so that we already implemented the reset functionality there). Can you please help us out? Is there a way of accessing the eventRecord within the evenEdit? Here is our current draft code:
startTimeField: {
weight: 40,
editable: true,
step: '5m',
picker: {
seconds: true
}
},
endTimeField: {
weight: 50,
editable: true,
type: 'time',
step: '5m',
picker: {
seconds: true
}
},
resetDurationButton: {
type: 'button',
icon: 'b-fa-arrow-left',
weight: 60,
scope: this,
text: 'Fit content duration',
onClick: 'up.resetDurationInEditor'
}
.
.
.
resetDurationInEditor({eventRecord}) {
// calculate endDate and endTime by current startDate and startTime considering eventRecord.initial_duration
document.getElementById('b-timefield-2-input').value = endTime;
document.getElementById('b-datefield-2-input').value = endDate;
}
In the context menu we did it like:
resetDuration({ eventRecord }) {
eventRecord.endDate = new Date((eventRecord.startDate.getTime()) + eventRecord.initial_duration * 1000);
}
Furthermore, we want to add a warning in case the user edits the dates, so that users are aware of looping content when the durations differ from each other. Is there a standard way to add validations to your input fields?
Hopefully, you can help me out!