Merge branch 'alextselegidis:develop' into develop

This commit is contained in:
krtcom 2024-04-17 08:03:20 +02:00 committed by GitHub
commit f2f395ddbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 5 deletions

View file

@ -48,7 +48,7 @@ if (!function_exists('array_find')) {
throw new InvalidArgumentException('No filter function provided.');
}
return array_filter($array, $callback)[0] ?? null;
return array_values(array_filter($array, $callback))[0] ?? null;
}
}

View file

@ -215,6 +215,11 @@ App.Components.WorkingPlanExceptionsModal = (function () {
);
}
function resetTimeSelection() {
App.Utils.UI.setDateTimePickerValue($start, moment('08:00', 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment('20:00', 'HH:mm').toDate());
}
/**
* Open the modal and start adding a new working plan exception.
*
@ -224,8 +229,8 @@ App.Components.WorkingPlanExceptionsModal = (function () {
deferred = $.Deferred();
App.Utils.UI.setDateTimePickerValue($date, new Date());
App.Utils.UI.setDateTimePickerValue($start, moment('08:00', 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($end, moment('20:00', 'HH:mm').toDate());
resetTimeSelection();
$isNonWorkingDay.prop('checked', false);
@ -450,11 +455,11 @@ App.Components.WorkingPlanExceptionsModal = (function () {
}
/**
* Event: Is Non Working Day "Change"
* Event: Is Non-Working Day "Change"
*/
function onIsNonWorkingDayChange() {
const isNonWorkingDay = $isNonWorkingDay.prop('checked');
resetTimeSelection();
toggleFieldsByNonWorkingDay(isNonWorkingDay);
}

View file

@ -26,6 +26,7 @@ App.Pages.BlockedPeriods = (function () {
let filterResults = {};
let filterLimit = 20;
let backupStartDateTimeObject = undefined;
/**
* Add the page event listeners.
@ -80,6 +81,9 @@ App.Pages.BlockedPeriods = (function () {
$blockedPeriods.find('.record-details .form-label span').prop('hidden', false);
$filterBlockedPeriods.find('button').prop('disabled', true);
$filterBlockedPeriods.find('.results').css('color', '#AAA');
App.Utils.UI.setDateTimePickerValue($startDateTime, moment('00:00', 'HH:mm').toDate());
App.Utils.UI.setDateTimePickerValue($endDateTime, moment('00:00', 'HH:mm').add(1, 'day').toDate());
});
/**
@ -156,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());
});
}
/**
@ -295,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;
}
/**