Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the company working hours as the default values when managing working plan exceptions #1534

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions assets/js/components/working_plan_exceptions_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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"
*/
Expand All @@ -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);

Expand Down