Move the blocked period end date automatically on start date change (#1499)

This commit is contained in:
Alex Tselegidis 2024-04-15 14:40:03 +02:00
parent b8803566df
commit eba1eb2b26

View file

@ -26,6 +26,7 @@ App.Pages.BlockedPeriods = (function () {
let filterResults = {}; let filterResults = {};
let filterLimit = 20; let filterLimit = 20;
let backupStartDateTimeObject = undefined;
/** /**
* Add the page event listeners. * Add the page event listeners.
@ -159,6 +160,27 @@ App.Pages.BlockedPeriods = (function () {
select(id, true); select(id, true);
} }
}); });
$blockedPeriods.on('focus', '#start-date-time', () => {
backupStartDateTimeObject = App.Utils.UI.getDateTimePickerValue($startDateTime);
});
/**
* Event: Start Date Time Input "Change"
*/
$blockedPeriods.on('change', '#start-date-time', (event) => {
const endDateTimeObject = App.Utils.UI.getDateTimePickerValue($endDateTime);
if (!backupStartDateTimeObject || !endDateTimeObject) {
return;
}
const endDateTimeMoment = moment(endDateTimeObject);
const backupStartDateTimeMoment = moment(backupStartDateTimeObject);
const diff = endDateTimeMoment.diff(backupStartDateTimeMoment);
const newEndDateTimeMoment = endDateTimeMoment.clone().add(diff, 'milliseconds');
App.Utils.UI.setDateTimePickerValue($endDateTime, newEndDateTimeMoment.toDate());
});
} }
/** /**
@ -298,6 +320,8 @@ App.Pages.BlockedPeriods = (function () {
$blockedPeriods.find('.record-details .is-invalid').removeClass('is-invalid'); $blockedPeriods.find('.record-details .is-invalid').removeClass('is-invalid');
$blockedPeriods.find('.record-details .form-message').hide(); $blockedPeriods.find('.record-details .form-message').hide();
backupStartDateTimeObject = undefined;
} }
/** /**