From 961b9b4f7c6b788d58a5bf46fdcbb37130c4dff0 Mon Sep 17 00:00:00 2001 From: tm8544 <15167679+tm8544@users.noreply.github.com> Date: Wed, 15 May 2024 15:33:39 +0300 Subject: [PATCH] Update working_plan_exceptions_modal.js On working plan exception use company_working_plan hours for that vweekday as baseline instead of hardcoded hours. If the given weekday does not have a working plan, then hardcoded values will be used --- .../working_plan_exceptions_modal.js | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/assets/js/components/working_plan_exceptions_modal.js b/assets/js/components/working_plan_exceptions_modal.js index c257ca35..078bd213 100644 --- a/assets/js/components/working_plan_exceptions_modal.js +++ b/assets/js/components/working_plan_exceptions_modal.js @@ -216,8 +216,23 @@ 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()); + const dateTimeObject = App.Utils.UI.getDateTimePickerValue($date); + const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(dateTimeObject).day())); + App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate()); + App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate()); + } + + function getWeekdaysPlannedHours(weekDay) { + hours = {}; + const company_working_plan = JSON.parse(vars('company_working_plan')); + if (company_working_plan[weekDay]) { + hours["start"] = company_working_plan[weekDay]['start']; + hours["end"] = company_working_plan[weekDay]['end']; + } else { + hours["start"] = '08:00'; + hours["end"] = '16:00'; + } + return hours; } /** @@ -272,8 +287,9 @@ App.Components.WorkingPlanExceptionsModal = (function () { $breaks.find('tbody .working-plan-exceptions-break-start, tbody .working-plan-exceptions-break-end'), ); } else { - App.Utils.UI.setDateTimePickerValue($start, moment('08:00', 'HH:mm').toDate()); - App.Utils.UI.setDateTimePickerValue($end, moment('20:00', 'HH:mm').toDate()); + const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(date).day())); + App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate()); + App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate()); $breaks.find('tbody').html(renderNoBreaksRow()); } @@ -454,6 +470,16 @@ App.Components.WorkingPlanExceptionsModal = (function () { $addBreak.prop('disabled', false); } + /** + * Event: Edit Date "Change" + */ + function onEditDateChange() { + const dateTimeObject = App.Utils.UI.getDateTimePickerValue($date); + const plannedHours = getWeekdaysPlannedHours(App.Utils.Date.getWeekdayName(moment(dateTimeObject).day())); + App.Utils.UI.setDateTimePickerValue($start, moment(plannedHours['start'], 'HH:mm').toDate()); + App.Utils.UI.setDateTimePickerValue($end, moment(plannedHours['end'], 'HH:mm').toDate()); + } + /** * Event: Is Non-Working Day "Change" */ @@ -477,7 +503,8 @@ App.Components.WorkingPlanExceptionsModal = (function () { .on('click', '.working-plan-exceptions-edit-break', onEditBreakClick) .on('click', '.working-plan-exceptions-delete-break', onDeleteBreakClick) .on('click', '.working-plan-exceptions-save-break', onSaveBreakClick) - .on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick); + .on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick) + .on('change', '#working-plan-exceptions-date', onEditDateChange); $save.on('click', onSaveClick);