Skip to content

Commit

Permalink
Move the blocked period end date automatically on start date change (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Apr 15, 2024
1 parent b880356 commit eba1eb2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions assets/js/pages/blocked_periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ App.Pages.BlockedPeriods = (function () {

let filterResults = {};
let filterLimit = 20;
let backupStartDateTimeObject = undefined;

/**
* Add the page event listeners.
Expand Down Expand Up @@ -159,6 +160,27 @@ App.Pages.BlockedPeriods = (function () {
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());
});
}

/**
Expand Down Expand Up @@ -298,6 +320,8 @@ App.Pages.BlockedPeriods = (function () {

$blockedPeriods.find('.record-details .is-invalid').removeClass('is-invalid');
$blockedPeriods.find('.record-details .form-message').hide();

backupStartDateTimeObject = undefined;
}

/**
Expand Down

0 comments on commit eba1eb2

Please sign in to comment.