| 1 |
import { Component } from "@odoo/owl"; |
| 2 |
import { DateTimePicker } from "@web/core/datetime/datetime_picker"; |
| 3 |
import { CalendarFilterSection } from "@web/views/calendar/calendar_filter_section/calendar_filter_section"; |
| 4 |
|
| 5 |
export class CalendarSidePanel extends Component { |
| 6 |
static components = { |
| 7 |
DatePicker: DateTimePicker, |
| 8 |
FilterSection: CalendarFilterSection, |
| 9 |
}; |
| 10 |
static template = "web.CalendarSidePanel"; |
| 11 |
static props = ["model"]; |
| 12 |
|
| 13 |
get datePickerProps() { |
| 14 |
return { |
| 15 |
type: "date", |
| 16 |
showWeekNumbers: false, |
| 17 |
maxPrecision: "days", |
| 18 |
daysOfWeekFormat: "narrow", |
| 19 |
onSelect: (date) => { |
| 20 |
let scale = "week"; |
| 21 |
|
| 22 |
if (this.props.model.date.hasSame(date, "day")) { |
| 23 |
const scales = ["month", "week", "day"]; |
| 24 |
scale = scales[(scales.indexOf(this.props.model.scale) + 1) % scales.length]; |
| 25 |
} else { |
| 26 |
// Check if dates are on the same week |
| 27 |
// As a.hasSame(b, "week") does not depend on locale and week always starts on Monday, |
| 28 |
// we are comparing derivated dates instead to take this into account. |
| 29 |
const currentDate = |
| 30 |
this.props.model.date.weekday === 7 |
| 31 |
? this.props.model.date.plus({ day: 1 }) |
| 32 |
: this.props.model.date; |
| 33 |
const pickedDate = date.weekday === 7 ? date.plus({ day: 1 }) : date; |
| 34 |
|
| 35 |
// a.hasSame(b, "week") does not depend on locale and week alway starts on Monday |
| 36 |
if (currentDate.hasSame(pickedDate, "week")) { |
| 37 |
scale = "day"; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
this.props.model.load({ scale, date }); |
| 42 |
}, |
| 43 |
value: this.props.model.date, |
| 44 |
}; |
| 45 |
} |
| 46 |
get filterPanelProps() { |
| 47 |
return { |
| 48 |
model: this.props.model, |
| 49 |
}; |
| 50 |
} |
| 51 |
|
| 52 |
get showDatePicker() { |
| 53 |
return this.props.model.showDatePicker && !this.env.isSmall; |
| 54 |
} |
| 55 |
} |