| 1 |
import { CalendarYearRenderer } from "@web/views/calendar/calendar_year/calendar_year_renderer"; |
| 2 |
|
| 3 |
import { useService } from "@web/core/utils/hooks"; |
| 4 |
import { useMandatoryDays } from "../../hooks"; |
| 5 |
import { useCalendarPopover } from "@web/views/calendar/hooks/calendar_popover_hook"; |
| 6 |
import { TimeOffCalendarYearPopover } from "./calendar_year_popover"; |
| 7 |
|
| 8 |
export class TimeOffCalendarYearRenderer extends CalendarYearRenderer { |
| 9 |
setup() { |
| 10 |
super.setup(); |
| 11 |
this.orm = useService("orm"); |
| 12 |
this.mandatoryDays = useMandatoryDays(this.props); |
| 13 |
this.mandatoryDaysList = []; |
| 14 |
this.mandatoryDayPopover = useCalendarPopover(TimeOffCalendarYearPopover); |
| 15 |
} |
| 16 |
|
| 17 |
get options() { |
| 18 |
return Object.assign(super.options, { |
| 19 |
weekNumbers: true, |
| 20 |
}); |
| 21 |
} |
| 22 |
|
| 23 |
get customOptions() { |
| 24 |
return { |
| 25 |
...super.customOptions, |
| 26 |
weekNumbersWithinDays: false, |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
/** @override **/ |
| 31 |
async onDateClick(info) { |
| 32 |
const is_mandatory_day = [...info.dayEl.classList].some((elClass) => |
| 33 |
elClass.startsWith("hr_mandatory_day_") |
| 34 |
); |
| 35 |
this.mandatoryDayPopover.close(); |
| 36 |
if (is_mandatory_day && !this.env.isSmall) { |
| 37 |
this.popover.close(); |
| 38 |
const date = luxon.DateTime.fromISO(info.dateStr); |
| 39 |
const target = info.dayEl; |
| 40 |
const mandatory_days_data = await this.orm.call( |
| 41 |
"hr.employee", |
| 42 |
"get_mandatory_days_data", |
| 43 |
[date, date] |
| 44 |
); |
| 45 |
mandatory_days_data.forEach((mandatory_day_data) => { |
| 46 |
mandatory_day_data["start"] = luxon.DateTime.fromISO(mandatory_day_data["start"]); |
| 47 |
mandatory_day_data["end"] = luxon.DateTime.fromISO(mandatory_day_data["end"]); |
| 48 |
}); |
| 49 |
const records = Object.values(this.props.model.records).filter((r) => |
| 50 |
luxon.Interval.fromDateTimes(r.start.startOf("day"), r.end.endOf("day")).contains( |
| 51 |
date |
| 52 |
) |
| 53 |
); |
| 54 |
const props = this.getPopoverProps(date, records); |
| 55 |
props["records"] = mandatory_days_data.concat(props["records"]); |
| 56 |
this.mandatoryDayPopover.open(target, props, "o_cw_popover_holidays o_cw_popover"); |
| 57 |
} else { |
| 58 |
super.onDateClick(info); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
openPopover(target, date, records) { |
| 63 |
this.popover.open(target, this.getPopoverProps(date, records), "o_cw_popover_holidays o_cw_popover"); |
| 64 |
} |
| 65 |
|
| 66 |
getDayCellClassNames(info) { |
| 67 |
return [...super.getDayCellClassNames(info), ...this.mandatoryDays(info)]; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* @override |
| 72 |
*/ |
| 73 |
eventClassNames({ event }) { |
| 74 |
const classesToAdd = super.eventClassNames(...arguments); |
| 75 |
const record = this.props.model.records[event.id]; |
| 76 |
if (record && record.requestDateFromPeriod && record.sameDay) { |
| 77 |
if (record.requestDateFromPeriod === "am" && record.requestDateToPeriod === "am") { |
| 78 |
classesToAdd.push("o_event_half_left") |
| 79 |
} else if (record.requestDateFromPeriod === "pm" && record.requestDateToPeriod === "pm") { |
| 80 |
classesToAdd.push("o_event_half_right") |
| 81 |
} |
| 82 |
} |
| 83 |
// handling half pill UX for custom_hours |
| 84 |
if (record?.rawRecord?.request_unit_hours && record.sameDay) { |
| 85 |
if (record.end.c.hour < 12) { |
| 86 |
classesToAdd.push("o_event_half_left"); |
| 87 |
} else if (record.end.c.hour >= 12 && record.start.c.hour >= 12) { |
| 88 |
classesToAdd.push("o_event_half_right"); |
| 89 |
} |
| 90 |
} |
| 91 |
return classesToAdd; |
| 92 |
} |
| 93 |
} |