mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
fix(calendar): prevent adding timeblocks outside of working hours
This commit is contained in:
1 parent
128d53788e
commit
af6dcfe0b8
1 file changed
+36
-20
@@ -282,31 +282,47 @@ export default {
|
||||
},
|
||||
|
||||
onCellClick(DOMEvent, split) {
|
||||
const dateFrom = split.date;
|
||||
dateFrom.setHours(Math.floor(DOMEvent.offsetY / 100), 0, 0, 0);
|
||||
const dateTo = new Date(dateFrom);
|
||||
dateTo.setHours(dateFrom.getHours() + 1);
|
||||
const allNonWorkingHoursEvents =
|
||||
DOMEvent.target.querySelectorAll('.non-working-event');
|
||||
|
||||
const time = moment(dateFrom).format('HH:mm');
|
||||
const calendarHeight = DOMEvent.target.offsetHeight;
|
||||
|
||||
const isTeamCalendar = this.$route.name === 'Dashboard - Teams';
|
||||
const employee = isTeamCalendar
|
||||
? split.employee_id
|
||||
: Number(localStorage.getItem('selectedEmployee') || this.user.id);
|
||||
const morningNonWorkingHoursEventHeight =
|
||||
allNonWorkingHoursEvents?.[0]?.offsetHeight || 950;
|
||||
const afternoonNonWorkingHoursEventHeight =
|
||||
allNonWorkingHoursEvents?.[1]?.offsetHeight || 1700;
|
||||
|
||||
this.$events.emit('show-menu-modal', {
|
||||
time,
|
||||
date: tmUtils.formatDateTimeForBackend(dateFrom),
|
||||
employee,
|
||||
});
|
||||
if (
|
||||
// Check if the click is not in the non-working hours events
|
||||
DOMEvent.offsetY > morningNonWorkingHoursEventHeight &&
|
||||
DOMEvent.offsetY < calendarHeight - afternoonNonWorkingHoursEventHeight
|
||||
) {
|
||||
const dateFrom = split.date;
|
||||
dateFrom.setHours(Math.floor(DOMEvent.offsetY / 100), 0, 0, 0);
|
||||
const dateTo = new Date(dateFrom);
|
||||
dateTo.setHours(dateFrom.getHours() + 1);
|
||||
|
||||
setTimeout(() => {
|
||||
this.$events.emit('add-timeblock', {
|
||||
id: null,
|
||||
start: tmUtils.formatDateTimeForBackend(dateFrom),
|
||||
end: tmUtils.formatDateTimeForBackend(dateTo),
|
||||
const time = moment(dateFrom).format('HH:mm');
|
||||
|
||||
const isTeamCalendar = this.$route.name === 'Dashboard - Teams';
|
||||
const employee = isTeamCalendar
|
||||
? split.employee_id
|
||||
: Number(localStorage.getItem('selectedEmployee') || this.user.id);
|
||||
|
||||
this.$events.emit('show-menu-modal', {
|
||||
time,
|
||||
date: tmUtils.formatDateTimeForBackend(dateFrom),
|
||||
employee,
|
||||
});
|
||||
}, 150);
|
||||
|
||||
setTimeout(() => {
|
||||
this.$events.emit('add-timeblock', {
|
||||
id: null,
|
||||
start: tmUtils.formatDateTimeForBackend(dateFrom),
|
||||
end: tmUtils.formatDateTimeForBackend(dateTo),
|
||||
});
|
||||
}, 150);
|
||||
}
|
||||
|
||||
if (!this.isDOMElementAnEvent(DOMEvent.target)) this.selectCell(DOMEvent);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user