UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

159 lines (156 loc) • 5.69 kB
/** * DevExtreme (cjs/__internal/scheduler/header/m_date_navigator.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDateNavigator = void 0; var _message = _interopRequireDefault(require("../../../common/core/localization/message")); var _date = _interopRequireDefault(require("../../../core/utils/date")); var _themes = require("../../../ui/themes"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function(n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) { ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]) } } return n }, _extends.apply(null, arguments) } const { trimTime: trimTime } = _date.default; const DATE_NAVIGATOR_CLASS = "dx-scheduler-navigator"; const PREVIOUS_BUTTON_CLASS = "dx-scheduler-navigator-previous"; const CALENDAR_BUTTON_CLASS = "dx-scheduler-navigator-caption"; const NEXT_BUTTON_CLASS = "dx-scheduler-navigator-next"; const DIRECTION_LEFT = -1; const DIRECTION_RIGHT = 1; const getDateNavigator = (header, item) => { const items = [getPreviousButtonOptions(header), getCalendarButtonOptions(header), getNextButtonOptions(header)]; const stylingMode = (0, _themes.isMaterialBased)() ? "text" : "contained"; return _extends({ widget: "dxButtonGroup", cssClass: DATE_NAVIGATOR_CLASS, options: { items: items, stylingMode: stylingMode, selectionMode: "none", onItemClick: e => { e.itemData.clickHandler(e) } } }, item) }; exports.getDateNavigator = getDateNavigator; const getPreviousButtonOptions = header => { const ariaMessage = _message.default.format("dxScheduler-navigationPrevious"); return { key: "previous", icon: "chevronprev", elementAttr: { class: PREVIOUS_BUTTON_CLASS, "aria-label": ariaMessage }, clickHandler: () => header._updateDateByDirection(-1), onContentReady: e => { const previousButton = e.component; previousButton.option("disabled", isPreviousButtonDisabled(header)); header._addEvent("min", (() => { previousButton.option("disabled", isPreviousButtonDisabled(header)) })); header._addEvent("currentDate", (() => { previousButton.option("disabled", isPreviousButtonDisabled(header)) })); header._addEvent("startViewDate", (() => { previousButton.option("disabled", isPreviousButtonDisabled(header)) })) } } }; const getCalendarButtonOptions = header => ({ key: "calendar", text: header.captionText, elementAttr: { class: CALENDAR_BUTTON_CLASS }, clickHandler: e => header._showCalendar(e), onContentReady: e => { const calendarButton = e.component; header._addEvent("currentView", (() => { calendarButton.option("text", header.captionText) })); header._addEvent("currentDate", (() => { calendarButton.option("text", header.captionText) })); header._addEvent("startViewDate", (() => { calendarButton.option("text", header.captionText) })); header._addEvent("views", (() => { calendarButton.option("text", header.captionText) })); header._addEvent("firstDayOfWeek", (() => { calendarButton.option("text", header.captionText) })) } }); const getNextButtonOptions = header => { const ariaMessage = _message.default.format("dxScheduler-navigationNext"); return { key: "next", icon: "chevronnext", elementAttr: { class: NEXT_BUTTON_CLASS, "aria-label": ariaMessage }, clickHandler: () => header._updateDateByDirection(1), onContentReady: e => { const nextButton = e.component; nextButton.option("disabled", isNextButtonDisabled(header)); header._addEvent("min", (() => { nextButton.option("disabled", isNextButtonDisabled(header)) })); header._addEvent("currentDate", (() => { nextButton.option("disabled", isNextButtonDisabled(header)) })); header._addEvent("startViewDate", (() => { nextButton.option("disabled", isNextButtonDisabled(header)) })) } } }; const isPreviousButtonDisabled = header => { let min = header.option("min"); if (!min) { return false } min = new Date(min); const caption = header._getCaption(); min = trimTime(min); const previousDate = header._getNextDate(-1, caption.endDate); return previousDate < min }; const isNextButtonDisabled = header => { let max = header.option("max"); if (!max) { return false } max = new Date(max); const caption = header._getCaption(); max = max.setHours(23, 59, 59); const nextDate = header._getNextDate(1, caption.startDate); return nextDate > max };