Fix working plan exception breaks handling

This commit is contained in:
Alex Tselegidis 2023-12-04 18:26:36 +01:00
parent 1cb5a2288c
commit 08908e5ad6

View file

@ -48,7 +48,7 @@ App.Components.WorkingPlanExceptionsModal = (function () {
*/ */
function renderNoBreaksRow() { function renderNoBreaksRow() {
return $(` return $(`
<tr> <tr class="no-breaks-row">
<td colspan="3" class="text-center"> <td colspan="3" class="text-center">
${lang('no_breaks')} ${lang('no_breaks')}
</td> </td>
@ -66,7 +66,7 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$end.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay); $end.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay);
$addBreak.prop('disabled', isNonWorkingDay); $addBreak.prop('disabled', isNonWorkingDay);
$breaks.find('button').prop('disabled', isNonWorkingDay); $breaks.find('button').prop('disabled', isNonWorkingDay);
$breaks.toggleClass('text-decoration-line-through', isNonWorkingDay) $breaks.toggleClass('text-decoration-line-through', isNonWorkingDay);
} }
/** /**
@ -115,21 +115,24 @@ App.Components.WorkingPlanExceptionsModal = (function () {
function getBreaks() { function getBreaks() {
const breaks = []; const breaks = [];
$breaks.find('tbody tr').each((index, tr) => { $breaks
const $tr = $(tr); .find('tbody tr')
.not('.no-breaks-row')
.each((index, tr) => {
const $tr = $(tr);
if ($tr.find('input:text').length) { if ($tr.find('input:text').length) {
return true; return true;
} }
const start = $tr.find('.working-plan-exceptions-break-start').text(); const start = $tr.find('.working-plan-exceptions-break-start').text();
const end = $tr.find('.working-plan-exceptions-break-end').text(); const end = $tr.find('.working-plan-exceptions-break-end').text();
breaks.push({ breaks.push({
start: moment(start, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm'), start: moment(start, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm'),
end: moment(end, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm') end: moment(end, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm')
});
}); });
});
// Sort breaks increasingly by hour within day // Sort breaks increasingly by hour within day
breaks.sort((break1, break2) => { breaks.sort((break1, break2) => {
@ -158,11 +161,13 @@ App.Components.WorkingPlanExceptionsModal = (function () {
const isNonWorkingDay = $isNonWorkingDay.prop('checked'); const isNonWorkingDay = $isNonWorkingDay.prop('checked');
const workingPlanException = isNonWorkingDay ? null : { const workingPlanException = isNonWorkingDay
start: moment($start[0]._flatpickr.selectedDates[0]).format('HH:mm'), ? null
end: moment($end[0]._flatpickr.selectedDates[0]).format('HH:mm'), : {
breaks: getBreaks() start: moment($start[0]._flatpickr.selectedDates[0]).format('HH:mm'),
}; end: moment($end[0]._flatpickr.selectedDates[0]).format('HH:mm'),
breaks: getBreaks()
};
deferred.resolve(date, workingPlanException); deferred.resolve(date, workingPlanException);