UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

1,189 lines (1,188 loc) • 115 kB
/** * DevExtreme (esm/__internal/scheduler/workspaces/m_work_space.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/ */ import _extends from "@babel/runtime/helpers/esm/extends"; import { locate, resetPosition } from "../../../common/core/animation/translator"; import { name as clickEventName } from "../../../common/core/events/click"; import { name as contextMenuEventName } from "../../../common/core/events/contextmenu"; import eventsEngine from "../../../common/core/events/core/events_engine"; import { drop as dragEventDrop, enter as dragEventEnter, leave as dragEventLeave } from "../../../common/core/events/drag"; import pointerEvents from "../../../common/core/events/pointer"; import { addNamespace, isMouseEvent } from "../../../common/core/events/utils/index"; import messageLocalization from "../../../common/core/localization/message"; import domAdapter from "../../../core/dom_adapter"; import { getPublicElement } from "../../../core/element"; import $ from "../../../core/renderer"; import { noop } from "../../../core/utils/common"; import { compileGetter } from "../../../core/utils/data"; import dateUtils from "../../../core/utils/date"; import { extend } from "../../../core/utils/extend"; import { getBoundingRect } from "../../../core/utils/position"; import { getHeight, getOuterHeight, getOuterWidth, getWidth, setOuterHeight, setWidth } from "../../../core/utils/size"; import { isDefined } from "../../../core/utils/type"; import { getWindow, hasWindow } from "../../../core/utils/window"; import Scrollable from "../../../ui/scroll_view/ui.scrollable"; import errors from "../../../ui/widget/ui.errors"; import { getMemoizeScrollTo } from "../../core/utils/scroll"; import { AllDayPanelTitleComponent, AllDayTableComponent, DateTableComponent, GroupPanelComponent, HeaderPanelComponent, TimePanelComponent } from "../../scheduler/r1/components/index"; import { calculateIsGroupedAllDayPanel, calculateViewStartDate, getCellDuration, getGroupCount, getStartViewDateTimeOffset, getViewStartByOptions, isDateAndTimeView } from "../../scheduler/r1/utils/index"; import WidgetObserver from "../base/m_widget_observer"; import AppointmentDragBehavior from "../m_appointment_drag_behavior"; import { APPOINTMENT_DRAG_SOURCE_CLASS, DATE_TABLE_CLASS, DATE_TABLE_ROW_CLASS, FIXED_CONTAINER_CLASS, GROUP_HEADER_CONTENT_CLASS, GROUP_ROW_CLASS, TIME_PANEL_CLASS, VERTICAL_GROUP_COUNT_CLASSES, VIRTUAL_CELL_CLASS } from "../m_classes"; import { APPOINTMENT_SETTINGS_KEY } from "../m_constants"; import tableCreatorModule from "../m_table_creator"; import { utils } from "../m_utils"; import { createResourcesTree, getCellGroups, getGroupsObjectFromGroupsArray } from "../resources/m_utils"; import VerticalShader from "../shaders/m_current_time_shader_vertical"; import { getAllDayHeight, getCellHeight, getCellWidth, getMaxAllowedPosition, PositionHelper } from "./helpers/m_position_helper"; import { Cache } from "./m_cache"; import { CellsSelectionController } from "./m_cells_selection_controller"; import CellsSelectionState from "./m_cells_selection_state"; import { VirtualScrollingDispatcher, VirtualScrollingRenderer } from "./m_virtual_scrolling"; import HorizontalGroupedStrategy from "./m_work_space_grouped_strategy_horizontal"; import VerticalGroupedStrategy from "./m_work_space_grouped_strategy_vertical"; import ViewDataProvider from "./view_model/m_view_data_provider"; const { tableCreator: tableCreator } = tableCreatorModule; const DRAGGING_MOUSE_FAULT = 10; const { abstract: abstract } = WidgetObserver; const toMs = dateUtils.dateToMilliseconds; const COMPONENT_CLASS = "dx-scheduler-work-space"; const GROUPED_WORKSPACE_CLASS = "dx-scheduler-work-space-grouped"; const VERTICAL_GROUPED_WORKSPACE_CLASS = "dx-scheduler-work-space-vertical-grouped"; const WORKSPACE_VERTICAL_GROUP_TABLE_CLASS = "dx-scheduler-work-space-vertical-group-table"; const WORKSPACE_WITH_BOTH_SCROLLS_CLASS = "dx-scheduler-work-space-both-scrollbar"; const WORKSPACE_WITH_COUNT_CLASS = "dx-scheduler-work-space-count"; const WORKSPACE_WITH_GROUP_BY_DATE_CLASS = "dx-scheduler-work-space-group-by-date"; const WORKSPACE_WITH_ODD_CELLS_CLASS = "dx-scheduler-work-space-odd-cells"; const TIME_PANEL_CELL_CLASS = "dx-scheduler-time-panel-cell"; const TIME_PANEL_ROW_CLASS = "dx-scheduler-time-panel-row"; const ALL_DAY_PANEL_CLASS = "dx-scheduler-all-day-panel"; const ALL_DAY_TABLE_CLASS = "dx-scheduler-all-day-table"; const ALL_DAY_CONTAINER_CLASS = "dx-scheduler-all-day-appointments"; const ALL_DAY_TITLE_CLASS = "dx-scheduler-all-day-title"; const ALL_DAY_TABLE_CELL_CLASS = "dx-scheduler-all-day-table-cell"; const ALL_DAY_TABLE_ROW_CLASS = "dx-scheduler-all-day-table-row"; const WORKSPACE_WITH_ALL_DAY_CLASS = "dx-scheduler-work-space-all-day"; const WORKSPACE_WITH_COLLAPSED_ALL_DAY_CLASS = "dx-scheduler-work-space-all-day-collapsed"; const WORKSPACE_WITH_MOUSE_SELECTION_CLASS = "dx-scheduler-work-space-mouse-selection"; const HORIZONTAL_SIZES_CLASS = "dx-scheduler-cell-sizes-horizontal"; const VERTICAL_SIZES_CLASS = "dx-scheduler-cell-sizes-vertical"; const HEADER_PANEL_CLASS = "dx-scheduler-header-panel"; const HEADER_PANEL_CELL_CLASS = "dx-scheduler-header-panel-cell"; const HEADER_ROW_CLASS = "dx-scheduler-header-row"; const GROUP_HEADER_CLASS = "dx-scheduler-group-header"; const DATE_TABLE_CELL_CLASS = "dx-scheduler-date-table-cell"; const DATE_TABLE_FOCUSED_CELL_CLASS = "dx-scheduler-focused-cell"; const VIRTUAL_ROW_CLASS = "dx-scheduler-virtual-row"; const DATE_TABLE_DROPPABLE_CELL_CLASS = "dx-scheduler-date-table-droppable-cell"; const SCHEDULER_HEADER_SCROLLABLE_CLASS = "dx-scheduler-header-scrollable"; const SCHEDULER_SIDEBAR_SCROLLABLE_CLASS = "dx-scheduler-sidebar-scrollable"; const SCHEDULER_DATE_TABLE_SCROLLABLE_CLASS = "dx-scheduler-date-table-scrollable"; const SCHEDULER_WORKSPACE_DXPOINTERDOWN_EVENT_NAME = addNamespace(pointerEvents.down, "dxSchedulerWorkSpace"); const DragEventNames = { ENTER: addNamespace(dragEventEnter, "dxSchedulerDateTable"), DROP: addNamespace(dragEventDrop, "dxSchedulerDateTable"), LEAVE: addNamespace(dragEventLeave, "dxSchedulerDateTable") }; const SCHEDULER_CELL_DXCLICK_EVENT_NAME = addNamespace(clickEventName, "dxSchedulerDateTable"); const SCHEDULER_CELL_DXPOINTERDOWN_EVENT_NAME = addNamespace(pointerEvents.down, "dxSchedulerDateTable"); const SCHEDULER_CELL_DXPOINTERUP_EVENT_NAME = addNamespace(pointerEvents.up, "dxSchedulerDateTable"); const SCHEDULER_CELL_DXPOINTERMOVE_EVENT_NAME = addNamespace(pointerEvents.move, "dxSchedulerDateTable"); const CELL_DATA = "dxCellData"; const DATE_TABLE_MIN_CELL_WIDTH = 75; const DAY_MS = toMs("day"); const HOUR_MS = toMs("hour"); const DRAG_AND_DROP_SELECTOR = `.${DATE_TABLE_CLASS} td, .${ALL_DAY_TABLE_CLASS} td`; const CELL_SELECTOR = `.${DATE_TABLE_CELL_CLASS}, .${ALL_DAY_TABLE_CELL_CLASS}`; const CELL_INDEX_CALCULATION_EPSILON = .05; const DEFAULT_WORKSPACE_RENDER_OPTIONS = { renderComponents: { header: true, timePanel: true, dateTable: true, allDayPanel: true }, generateNewData: true }; class SchedulerWorkSpace extends WidgetObserver { constructor() { super(...arguments); this.viewDirection = "vertical" } get type() { return "" } get viewDataProvider() { if (!this._viewDataProvider) { this._viewDataProvider = new ViewDataProvider(this.type) } return this._viewDataProvider } get cache() { if (!this._cache) { this._cache = new Cache } return this._cache } get cellsSelectionState() { if (!this._cellsSelectionState) { this._cellsSelectionState = new CellsSelectionState(this.viewDataProvider); const selectedCellsOption = this.option("selectedCellData"); if ((null === selectedCellsOption || void 0 === selectedCellsOption ? void 0 : selectedCellsOption.length) > 0) { const validSelectedCells = selectedCellsOption.map((selectedCell => { const { groups: groups } = selectedCell; if (!groups || 0 === this._getGroupCount()) { return _extends({}, selectedCell, { groupIndex: 0 }) } const groupIndex = this._getGroupIndexByResourceId(groups); return _extends({}, selectedCell, { groupIndex: groupIndex }) })); this._cellsSelectionState.setSelectedCellsByData(validSelectedCells) } } return this._cellsSelectionState } get cellsSelectionController() { if (!this._cellsSelectionController) { this._cellsSelectionController = new CellsSelectionController } return this._cellsSelectionController } get isAllDayPanelVisible() { return this._isShowAllDayPanel() && this.supportAllDayRow() } get verticalGroupTableClass() { return WORKSPACE_VERTICAL_GROUP_TABLE_CLASS } get renovatedHeaderPanelComponent() { return HeaderPanelComponent } get timeZoneCalculator() { return this.option("timeZoneCalculator") } get isDefaultDraggingMode() { return "default" === this.option("draggingMode") } _supportedKeys() { const clickHandler = function(e) { e.preventDefault(); e.stopPropagation(); const selectedCells = this.cellsSelectionState.getSelectedCells(); if (null !== selectedCells && void 0 !== selectedCells && selectedCells.length) { const selectedCellsElement = selectedCells.map((cellData => this._getCellByData(cellData))).filter((cell => !!cell)); e.target = selectedCellsElement; this._showPopup = true; this._cellClickAction({ event: e, cellElement: $(selectedCellsElement), cellData: selectedCells[0] }) } }; const onArrowPressed = (e, key) => { var _this$cellsSelectionS; e.preventDefault(); e.stopPropagation(); const focusedCellData = null === (_this$cellsSelectionS = this.cellsSelectionState.focusedCell) || void 0 === _this$cellsSelectionS ? void 0 : _this$cellsSelectionS.cellData; if (focusedCellData) { const isAllDayPanelCell = focusedCellData.allDay && !this._isVerticalGroupedWorkSpace(); const isMultiSelection = e.shiftKey; const isMultiSelectionAllowed = this.option("allowMultipleCellSelection"); const isRTL = this._isRTL(); const groupCount = this._getGroupCount(); const isGroupedByDate = this.isGroupedByDate(); const isHorizontalGrouping = this._isHorizontalGroupedWorkSpace(); const focusedCellPosition = this.viewDataProvider.findCellPositionInMap(_extends({}, focusedCellData, { isAllDay: focusedCellData.allDay })); const edgeIndices = isHorizontalGrouping && isMultiSelection && !isGroupedByDate ? this.viewDataProvider.getGroupEdgeIndices(focusedCellData.groupIndex, isAllDayPanelCell) : this.viewDataProvider.getViewEdgeIndices(isAllDayPanelCell); const nextCellData = this.cellsSelectionController.handleArrowClick({ focusedCellPosition: focusedCellPosition, edgeIndices: edgeIndices, isRTL: isRTL, isGroupedByDate: isGroupedByDate, groupCount: groupCount, isMultiSelection: isMultiSelection, isMultiSelectionAllowed: isMultiSelectionAllowed, viewType: this.type, key: key, getCellDataByPosition: this.viewDataProvider.getCellData.bind(this.viewDataProvider), isAllDayPanelCell: isAllDayPanelCell, focusedCellData: focusedCellData }); this._processNextSelectedCell(nextCellData, focusedCellData, isMultiSelection && isMultiSelectionAllowed) } }; return extend(super._supportedKeys(), { enter: clickHandler, space: clickHandler, downArrow: e => { onArrowPressed(e, "down") }, upArrow: e => { onArrowPressed(e, "up") }, rightArrow: e => { onArrowPressed(e, "right") }, leftArrow: e => { onArrowPressed(e, "left") } }) } _isRTL() { return this.option("rtlEnabled") } _moveToCell($cell, isMultiSelection) { if (!isDefined($cell) || !$cell.length) { return } const isMultiSelectionAllowed = this.option("allowMultipleCellSelection"); const currentCellData = this._getFullCellData($cell); const focusedCellData = this.cellsSelectionState.focusedCell.cellData; const nextFocusedCellData = this.cellsSelectionController.moveToCell({ isMultiSelection: isMultiSelection, isMultiSelectionAllowed: isMultiSelectionAllowed, currentCellData: currentCellData, focusedCellData: focusedCellData, isVirtualCell: $cell.hasClass(VIRTUAL_CELL_CLASS) }); this._processNextSelectedCell(nextFocusedCellData, focusedCellData, isMultiSelectionAllowed && isMultiSelection) } _processNextSelectedCell(nextCellData, focusedCellData, isMultiSelection) { const nextCellPosition = this.viewDataProvider.findCellPositionInMap({ startDate: nextCellData.startDate, groupIndex: nextCellData.groupIndex, isAllDay: nextCellData.allDay, index: nextCellData.index }); if (!this.viewDataProvider.isSameCell(focusedCellData, nextCellData)) { const $cell = nextCellData.allDay && !this._isVerticalGroupedWorkSpace() ? this._dom_getAllDayPanelCell(nextCellPosition.columnIndex) : this._dom_getDateCell(nextCellPosition); const isNextCellAllDay = nextCellData.allDay; this._setSelectedCellsStateAndUpdateSelection(isNextCellAllDay, nextCellPosition, isMultiSelection, $cell); this._dateTableScrollable.scrollToElement($cell) } } _setSelectedCellsStateAndUpdateSelection(isAllDay, cellPosition, isMultiSelection, $nextFocusedCell) { const nextCellCoordinates = { rowIndex: cellPosition.rowIndex, columnIndex: cellPosition.columnIndex, allDay: isAllDay }; this.cellsSelectionState.setFocusedCell(nextCellCoordinates.rowIndex, nextCellCoordinates.columnIndex, isAllDay); if (isMultiSelection) { this.cellsSelectionState.setSelectedCells(nextCellCoordinates) } else { this.cellsSelectionState.setSelectedCells(nextCellCoordinates, nextCellCoordinates) } this.updateCellsSelection(); this._updateSelectedCellDataOption(this.cellsSelectionState.getSelectedCells(), $nextFocusedCell) } _hasAllDayClass($cell) { return $cell.hasClass(ALL_DAY_TABLE_CELL_CLASS) } _focusInHandler(e) { if ($(e.target).is(this._focusTarget()) && this._isCellClick) { delete this._isCellClick; delete this._contextMenuHandled; super._focusInHandler.apply(this, arguments); this.cellsSelectionState.restoreSelectedAndFocusedCells(); if (!this.cellsSelectionState.focusedCell) { const cellCoordinates = { columnIndex: 0, rowIndex: 0, allDay: this._isVerticalGroupedWorkSpace() && this.isAllDayPanelVisible }; this.cellsSelectionState.setFocusedCell(cellCoordinates.rowIndex, cellCoordinates.columnIndex, cellCoordinates.allDay); this.cellsSelectionState.setSelectedCells(cellCoordinates, cellCoordinates) } this.updateCellsSelection(); this._updateSelectedCellDataOption(this.cellsSelectionState.getSelectedCells()) } } _focusOutHandler() { super._focusOutHandler.apply(this, arguments); if (!this._contextMenuHandled && !this._disposed) { this.cellsSelectionState.releaseSelectedAndFocusedCells(); this.viewDataProvider.updateViewData(this.generateRenderOptions()); this.updateCellsSelection() } } _focusTarget() { return this.$element() } _isVerticalGroupedWorkSpace() { var _this$option; return !!(null !== (_this$option = this.option("groups")) && void 0 !== _this$option && _this$option.length) && "vertical" === this.option("groupOrientation") } _isHorizontalGroupedWorkSpace() { var _this$option2; return !!(null !== (_this$option2 = this.option("groups")) && void 0 !== _this$option2 && _this$option2.length) && "horizontal" === this.option("groupOrientation") } _isWorkSpaceWithCount() { return this.option("intervalCount") > 1 } _isWorkspaceWithOddCells() { return .5 === this.option("hoursInterval") && !this.isVirtualScrolling() } _getRealGroupOrientation() { return this._isVerticalGroupedWorkSpace() ? "vertical" : "horizontal" } createRAllDayPanelElements() { this._$allDayPanel = $("<div>").addClass(ALL_DAY_PANEL_CLASS); this._$allDayTitle = $("<div>").appendTo(this._$headerPanelEmptyCell) } _dateTableScrollableConfig() { let config = { useKeyboard: false, bounceEnabled: false, updateManually: true, onScroll: () => { var _this$_groupedStrateg; null === (_this$_groupedStrateg = this._groupedStrategy.cache) || void 0 === _this$_groupedStrateg || _this$_groupedStrateg.clear() } }; if (this._needCreateCrossScrolling()) { config = extend(config, this._createCrossScrollingConfig(config)) } if (this.isVirtualScrolling() && (this.virtualScrollingDispatcher.horizontalScrollingAllowed || this.virtualScrollingDispatcher.height)) { const currentOnScroll = config.onScroll; config = _extends({}, config, { onScroll: e => { null === currentOnScroll || void 0 === currentOnScroll || currentOnScroll(e); this.virtualScrollingDispatcher.handleOnScrollEvent(null === e || void 0 === e ? void 0 : e.scrollOffset) } }) } return config } _createCrossScrollingConfig(_ref) { let { onScroll: onScroll } = _ref; return { direction: "both", onScroll: event => { null === onScroll || void 0 === onScroll || onScroll(); this._scrollSync.sidebar({ top: event.scrollOffset.top }); this._scrollSync.header({ left: event.scrollOffset.left }) }, onEnd: () => { this.option("onScrollEnd")() } } } _headerScrollableConfig() { return { useKeyboard: false, showScrollbar: "never", direction: "horizontal", useNative: false, updateManually: true, bounceEnabled: false, onScroll: event => { this._scrollSync.dateTable({ left: event.scrollOffset.left }) } } } _visibilityChanged(visible) { this.cache.clear(); if (visible) { this._updateGroupTableHeight() } if (visible && this._needCreateCrossScrolling()) { this._setTableSizes() } } _setTableSizes() { this.cache.clear(); this._attachTableClasses(); let cellWidth = this.getCellWidth(); if (cellWidth < this.getCellMinWidth()) { cellWidth = this.getCellMinWidth() } const minWidth = this.getWorkSpaceMinWidth(); const groupCount = this._getGroupCount(); const totalCellCount = this._getTotalCellCount(groupCount); let width = cellWidth * totalCellCount; if (width < minWidth) { width = minWidth } setWidth(this._$headerPanel, width); setWidth(this._$dateTable, width); if (this._$allDayTable) { setWidth(this._$allDayTable, width) } this._attachHeaderTableClasses(); this._updateGroupTableHeight(); this._updateScrollable() } getWorkSpaceMinWidth() { return this._groupedStrategy.getWorkSpaceMinWidth() } _dimensionChanged() { if (!this._isVisible()) { return } if (this.option("crossScrollingEnabled")) { this._setTableSizes() } this.updateHeaderEmptyCellWidth(); this._updateScrollable(); this.cache.clear() } _needCreateCrossScrolling() { return this.option("crossScrollingEnabled") } _getElementClass() { return noop() } _getRowCount() { return this.viewDataProvider.getRowCount({ intervalCount: this.option("intervalCount"), currentDate: this.option("currentDate"), viewType: this.type, hoursInterval: this.option("hoursInterval"), startDayHour: this.option("startDayHour"), endDayHour: this.option("endDayHour") }) } _getCellCount() { return this.viewDataProvider.getCellCount({ intervalCount: this.option("intervalCount"), currentDate: this.option("currentDate"), viewType: this.type, hoursInterval: this.option("hoursInterval"), startDayHour: this.option("startDayHour"), endDayHour: this.option("endDayHour") }) } isRenovatedRender() { return this.renovatedRenderSupported() && this.option("renovateRender") } _isVirtualModeOn() { return "virtual" === this.option("scrolling.mode") } isVirtualScrolling() { return this.isRenovatedRender() && this._isVirtualModeOn() } _initVirtualScrolling() { if (this.virtualScrollingDispatcher) { this.virtualScrollingDispatcher.dispose(); this.virtualScrollingDispatcher = null } this.virtualScrollingDispatcher = new VirtualScrollingDispatcher(this._getVirtualScrollingDispatcherOptions()); this.virtualScrollingDispatcher.attachScrollableEvents(); this.renderer = new VirtualScrollingRenderer(this) } onDataSourceChanged(argument) {} isGroupedAllDayPanel() { return calculateIsGroupedAllDayPanel(this.option("groups"), this.option("groupOrientation"), this.isAllDayPanelVisible) } generateRenderOptions(isProvideVirtualCellsWidth) { var _this$_getToday; const groupCount = this._getGroupCount(); const groupOrientation = groupCount > 0 ? this.option("groupOrientation") : this._getDefaultGroupStrategy(); const options = _extends({ groupByDate: this.option("groupByDate"), startRowIndex: 0, startCellIndex: 0, groupOrientation: groupOrientation, today: null === (_this$_getToday = this._getToday) || void 0 === _this$_getToday ? void 0 : _this$_getToday.call(this), groups: this.option("groups"), isProvideVirtualCellsWidth: isProvideVirtualCellsWidth, isAllDayPanelVisible: this.isAllDayPanelVisible, selectedCells: this.cellsSelectionState.getSelectedCells(), focusedCell: this.cellsSelectionState.focusedCell, headerCellTextFormat: this._getFormat(), getDateForHeaderText: (_, date) => date, viewOffset: this.option("viewOffset"), startDayHour: this.option("startDayHour"), endDayHour: this.option("endDayHour"), cellDuration: this.getCellDuration(), viewType: this.type, intervalCount: this.option("intervalCount"), hoursInterval: this.option("hoursInterval"), currentDate: this.option("currentDate"), startDate: this.option("startDate"), firstDayOfWeek: this.option("firstDayOfWeek"), showCurrentTimeIndicator: this.option("showCurrentTimeIndicator") }, this.virtualScrollingDispatcher.getRenderState()); return options } renovatedRenderSupported() { return true } _updateGroupTableHeight() { if (this._isVerticalGroupedWorkSpace() && hasWindow()) { this._setHorizontalGroupHeaderCellsHeight() } } updateHeaderEmptyCellWidth() { if (hasWindow() && this._isRenderHeaderPanelEmptyCell()) { const timePanelWidth = this.getTimePanelWidth(); const groupPanelWidth = this.getGroupTableWidth(); this._$headerPanelEmptyCell.css("width", timePanelWidth + groupPanelWidth) } } _isGroupsSpecified(resources) { var _this$option3; return (null === (_this$option3 = this.option("groups")) || void 0 === _this$option3 ? void 0 : _this$option3.length) && resources } _getGroupIndexByResourceId(id) { const groups = this.option("groups"); const resourceTree = createResourcesTree(groups); if (!resourceTree.length) { return 0 } return this._getGroupIndexRecursively(resourceTree, id) } _getGroupIndexRecursively(resourceTree, id) { const currentKey = resourceTree[0].name; const currentValue = id[currentKey]; return resourceTree.reduce(((prevIndex, _ref2) => { let { leafIndex: leafIndex, value: value, children: children } = _ref2; const areValuesEqual = currentValue === value; if (areValuesEqual && void 0 !== leafIndex) { return leafIndex } if (areValuesEqual) { return this._getGroupIndexRecursively(children, id) } return prevIndex }), 0) } _getViewStartByOptions() { return getViewStartByOptions(this.option("startDate"), this.option("currentDate"), this._getIntervalDuration(), this.option("startDate") ? this._calculateViewStartDate() : void 0) } _getIntervalDuration() { return this.viewDataProvider.getIntervalDuration(this.option("intervalCount")) } _getHeaderDate() { return this.getStartViewDate() } _calculateViewStartDate() { return calculateViewStartDate(this.option("startDate")) } _firstDayOfWeek() { return this.viewDataProvider.getFirstDayOfWeek(this.option("firstDayOfWeek")) } _attachEvents() { this._createSelectionChangedAction(); this._attachClickEvent(); this._attachContextMenuEvent() } _attachClickEvent() { const that = this; const pointerDownAction = this._createAction((e => { that._pointerDownHandler(e.event) })); this._createCellClickAction(); const cellSelector = `.${DATE_TABLE_CELL_CLASS},.${ALL_DAY_TABLE_CELL_CLASS}`; const $element = this.$element(); eventsEngine.off($element, SCHEDULER_WORKSPACE_DXPOINTERDOWN_EVENT_NAME); eventsEngine.off($element, SCHEDULER_CELL_DXCLICK_EVENT_NAME); eventsEngine.on($element, SCHEDULER_WORKSPACE_DXPOINTERDOWN_EVENT_NAME, (e => { if (isMouseEvent(e) && e.which > 1) { e.preventDefault(); return } pointerDownAction({ event: e }) })); eventsEngine.on($element, SCHEDULER_CELL_DXCLICK_EVENT_NAME, cellSelector, (e => { const $cell = $(e.target); that._cellClickAction({ event: e, cellElement: getPublicElement($cell), cellData: that.getCellData($cell) }) })) } _createCellClickAction() { this._cellClickAction = this._createActionByOption("onCellClick", { afterExecute: e => this._cellClickHandler(e.args[0].event) }) } _createSelectionChangedAction() { this._selectionChangedAction = this._createActionByOption("onSelectionChanged") } _cellClickHandler(argument) { if (this._showPopup) { delete this._showPopup; this._handleSelectedCellsClick() } } _pointerDownHandler(e) { const $target = $(e.target); if (!$target.hasClass(DATE_TABLE_CELL_CLASS) && !$target.hasClass(ALL_DAY_TABLE_CELL_CLASS)) { this._isCellClick = false; return } this._isCellClick = true; if ($target.hasClass("dx-scheduler-focused-cell")) { this._showPopup = true } else { const cellCoordinates = this._getCoordinatesByCell($target); const isAllDayCell = this._hasAllDayClass($target); this._setSelectedCellsStateAndUpdateSelection(isAllDayCell, cellCoordinates, false, $target) } } _handleSelectedCellsClick() { const selectedCells = this.cellsSelectionState.getSelectedCells(); const firstCellData = selectedCells[0]; const lastCellData = selectedCells[selectedCells.length - 1]; const result = { startDate: firstCellData.startDate, endDate: lastCellData.endDate }; if (void 0 !== lastCellData.allDay) { result.allDay = lastCellData.allDay } this.option("onSelectedCellsClick")(result, lastCellData.groups) } _attachContextMenuEvent() { this._createContextMenuAction(); const cellSelector = `.${DATE_TABLE_CELL_CLASS},.${ALL_DAY_TABLE_CELL_CLASS}`; const $element = this.$element(); const eventName = addNamespace(contextMenuEventName, this.NAME); eventsEngine.off($element, eventName, cellSelector); eventsEngine.on($element, eventName, cellSelector, this._contextMenuHandler.bind(this)) } _contextMenuHandler(e) { const $cell = $(e.target); this._contextMenuAction({ event: e, cellElement: getPublicElement($cell), cellData: this.getCellData($cell) }); this._contextMenuHandled = true } _createContextMenuAction() { this._contextMenuAction = this._createActionByOption("onCellContextMenu") } _getGroupHeaderContainer() { if (this._isVerticalGroupedWorkSpace()) { return this._$groupTable } return this._$thead } _getDateHeaderContainer() { return this._$thead } _getCalculateHeaderCellRepeatCount() { return this._groupedStrategy.calculateHeaderCellRepeatCount() } _updateScrollable() { var _this$_headerScrollab, _this$_sidebarScrolla; this._dateTableScrollable.update(); null === (_this$_headerScrollab = this._headerScrollable) || void 0 === _this$_headerScrollab || _this$_headerScrollab.update(); null === (_this$_sidebarScrolla = this._sidebarScrollable) || void 0 === _this$_sidebarScrolla || _this$_sidebarScrolla.update() } _getTimePanelRowCount() { return this._getCellCountInDay() } _getCellCountInDay() { const hoursInterval = this.option("hoursInterval"); const startDayHour = this.option("startDayHour"); const endDayHour = this.option("endDayHour"); return this.viewDataProvider.getCellCountInDay(startDayHour, endDayHour, hoursInterval) } _getTotalCellCount(groupCount) { return this._groupedStrategy.getTotalCellCount(groupCount) } _getTotalRowCount(groupCount, includeAllDayPanelRows) { let result = this._groupedStrategy.getTotalRowCount(groupCount); if (includeAllDayPanelRows && this.isAllDayPanelVisible) { result += groupCount } return result } _getGroupIndex(rowIndex, columnIndex) { return this._groupedStrategy.getGroupIndex(rowIndex, columnIndex) } calculateEndDate(startDate) { const { viewDataGenerator: viewDataGenerator } = this.viewDataProvider; return viewDataGenerator.calculateEndDate(startDate, viewDataGenerator.getInterval(this.option("hoursInterval")), this.option("endDayHour")) } _getGroupCount() { return getGroupCount(this.option("groups")) } _attachTablesEvents() { const element = this.$element(); this._attachDragEvents(element); this._attachPointerEvents(element) } _detachDragEvents(element) { eventsEngine.off(element, DragEventNames.ENTER); eventsEngine.off(element, DragEventNames.LEAVE); eventsEngine.off(element, DragEventNames.DROP) } _attachDragEvents(element) { this._detachDragEvents(element); eventsEngine.on(element, DragEventNames.ENTER, DRAG_AND_DROP_SELECTOR, { checkDropTarget: (target, event) => !this._isOutsideScrollable(target, event) }, (e => { if (!this.preventDefaultDragging) { this.removeDroppableCellClass(); $(e.target).addClass(DATE_TABLE_DROPPABLE_CELL_CLASS) } })); eventsEngine.on(element, DragEventNames.LEAVE, (() => { if (!this.preventDefaultDragging) { this.removeDroppableCellClass() } })); eventsEngine.on(element, DragEventNames.DROP, DRAG_AND_DROP_SELECTOR, (() => { var _this$dragBehavior, _this$dragBehavior$dr; if (!this.dragBehavior) { return } if (!(null !== (_this$dragBehavior = this.dragBehavior) && void 0 !== _this$dragBehavior && _this$dragBehavior.dragBetweenComponentsPromise)) { this.dragBehavior.removeDroppableClasses(); return } null === (_this$dragBehavior$dr = this.dragBehavior.dragBetweenComponentsPromise) || void 0 === _this$dragBehavior$dr || _this$dragBehavior$dr.then((() => { this.dragBehavior.removeDroppableClasses() })) })) } _attachPointerEvents(element) { let isPointerDown = false; eventsEngine.off(element, SCHEDULER_CELL_DXPOINTERMOVE_EVENT_NAME); eventsEngine.off(element, SCHEDULER_CELL_DXPOINTERDOWN_EVENT_NAME); eventsEngine.on(element, SCHEDULER_CELL_DXPOINTERDOWN_EVENT_NAME, DRAG_AND_DROP_SELECTOR, (e => { if (isMouseEvent(e) && 1 === e.which) { isPointerDown = true; this.$element().addClass(WORKSPACE_WITH_MOUSE_SELECTION_CLASS); eventsEngine.off(domAdapter.getDocument(), SCHEDULER_CELL_DXPOINTERUP_EVENT_NAME); eventsEngine.on(domAdapter.getDocument(), SCHEDULER_CELL_DXPOINTERUP_EVENT_NAME, (() => { isPointerDown = false; this.$element().removeClass(WORKSPACE_WITH_MOUSE_SELECTION_CLASS) })) } })); eventsEngine.on(element, SCHEDULER_CELL_DXPOINTERMOVE_EVENT_NAME, DRAG_AND_DROP_SELECTOR, (e => { if (isPointerDown && this._dateTableScrollable && !this._dateTableScrollable.option("scrollByContent")) { e.preventDefault(); e.stopPropagation(); this._moveToCell($(e.target), true) } })) } _getFormat() { return abstract() } getWorkArea() { return this._$dateTableContainer } getScrollable() { return this._dateTableScrollable } getScrollableScrollTop() { return this._dateTableScrollable.scrollTop() } getGroupedScrollableScrollTop(allDay) { return this._groupedStrategy.getScrollableScrollTop(allDay) } getScrollableScrollLeft() { return this._dateTableScrollable.scrollLeft() } getScrollableOuterWidth() { return this._dateTableScrollable.scrollWidth() } getScrollableContainer() { return $(this._dateTableScrollable.container()) } getHeaderPanelHeight() { return this._$headerPanel && getOuterHeight(this._$headerPanel, true) } getTimePanelWidth() { return this._$timePanel && getBoundingRect(this._$timePanel.get(0)).width } getGroupTableWidth() { return this._$groupTable ? getOuterWidth(this._$groupTable) : 0 } getWorkSpaceLeftOffset() { return this._groupedStrategy.getLeftOffset() } _getCellCoordinatesByIndex(index) { const columnIndex = Math.floor(index / this._getRowCount()); const rowIndex = index - this._getRowCount() * columnIndex; return { columnIndex: columnIndex, rowIndex: rowIndex } } _getDateGenerationOptions() { var _this$viewDataProvide; return { startDayHour: this.option("startDayHour"), endDayHour: this.option("endDayHour"), isWorkView: this.viewDataProvider.viewDataGenerator.isWorkView, interval: null === (_this$viewDataProvide = this.viewDataProvider.viewDataGenerator) || void 0 === _this$viewDataProvide ? void 0 : _this$viewDataProvide.getInterval(this.option("hoursInterval")), startViewDate: this.getStartViewDate(), firstDayOfWeek: this._firstDayOfWeek() } } _getIntervalBetween(currentDate, allDay) { const firstViewDate = this.getStartViewDate(); const startDayTime = this.option("startDayHour") * HOUR_MS; const timeZoneOffset = dateUtils.getTimezonesDifference(firstViewDate, currentDate); const fullInterval = currentDate.getTime() - firstViewDate.getTime() - timeZoneOffset; const days = this._getDaysOfInterval(fullInterval, startDayTime); const weekendsCount = this._getWeekendsCount(days); let result = (days - weekendsCount) * DAY_MS; if (!allDay) { const { hiddenInterval: hiddenInterval } = this.viewDataProvider; const visibleDayDuration = this.getVisibleDayDuration(); result = fullInterval - days * hiddenInterval - weekendsCount * visibleDayDuration } return result } _getWeekendsCount(argument) { return 0 } _getDaysOfInterval(fullInterval, startDayTime) { return Math.floor((fullInterval + startDayTime) / DAY_MS) } _updateIndex(index) { return index * this._getRowCount() } getDroppableCell() { return this._getDateTables().find(`.${DATE_TABLE_DROPPABLE_CELL_CLASS}`) } _getWorkSpaceWidth() { return this.cache.get("workspaceWidth", (() => { if (this._needCreateCrossScrolling()) { return getBoundingRect(this._$dateTable.get(0)).width } const totalWidth = getBoundingRect(this.$element().get(0)).width; const timePanelWidth = this.getTimePanelWidth(); const groupTableWidth = this.getGroupTableWidth(); return totalWidth - timePanelWidth - groupTableWidth })) } _getCellByCoordinates(cellCoordinates, groupIndex, inAllDayRow) { const indexes = this._groupedStrategy.prepareCellIndexes(cellCoordinates, groupIndex, inAllDayRow); return this._dom_getDateCell(indexes) } _dom_getDateCell(position) { return this._$dateTable.find(`tr:not(.${VIRTUAL_ROW_CLASS})`).eq(position.rowIndex).find(`td:not(.${VIRTUAL_CELL_CLASS})`).eq(position.columnIndex) } _dom_getAllDayPanelCell(columnIndex) { return this._$allDayPanel.find("tr").eq(0).find("td").eq(columnIndex) } _getCells(allDay, direction) { const cellClass = allDay ? ALL_DAY_TABLE_CELL_CLASS : DATE_TABLE_CELL_CLASS; if ("vertical" === direction) { let result = []; for (let i = 1;; i++) { const cells = this.$element().find(`tr .${cellClass}:nth-child(${i})`); if (!cells.length) { break } result = result.concat(cells.toArray()) } return $(result) } return this.$element().find(`.${cellClass}`) } _getFirstAndLastDataTableCell() { const selector = this.isVirtualScrolling() ? `.${DATE_TABLE_CELL_CLASS}, .${VIRTUAL_CELL_CLASS}` : `.${DATE_TABLE_CELL_CLASS}`; const $cells = this.$element().find(selector); return [$cells[0], $cells[$cells.length - 1]] } _getAllCells(allDay) { if (this._isVerticalGroupedWorkSpace()) { return this._$dateTable.find(`td:not(.${VIRTUAL_CELL_CLASS})`) } const cellClass = allDay && this.supportAllDayRow() ? ALL_DAY_TABLE_CELL_CLASS : DATE_TABLE_CELL_CLASS; return this.$element().find(`.${cellClass}`) } _setHorizontalGroupHeaderCellsHeight() { const { height: height } = getBoundingRect(this._$dateTable.get(0)); setOuterHeight(this._$groupTable, height) } _getGroupHeaderCells() { return this.$element().find(`.${GROUP_HEADER_CLASS}`) } _getScrollCoordinates(hours, minutes, date, groupIndex, allDay) { const currentDate = date || new Date(this.option("currentDate")); const startDayHour = this.option("startDayHour"); const endDayHour = this.option("endDayHour"); if (hours < startDayHour) { hours = startDayHour } if (hours >= endDayHour) { hours = endDayHour - 1 } currentDate.setHours(hours, minutes, 0, 0); const cell = this.viewDataProvider.findGlobalCellPosition(currentDate, groupIndex, allDay); const { position: position, cellData: cellData } = cell; return this.virtualScrollingDispatcher.calculateCoordinatesByDataAndPosition(cellData, position, currentDate, isDateAndTimeView(this.type), "vertical" === this.viewDirection) } _isOutsideScrollable(target, event) { const $dateTableScrollableElement = this._dateTableScrollable.$element(); const scrollableSize = getBoundingRect($dateTableScrollableElement.get(0)); const window = getWindow(); const isTargetInAllDayPanel = !$(target).closest($dateTableScrollableElement).length; const isOutsideHorizontalScrollable = event.pageX < scrollableSize.left || event.pageX > scrollableSize.left + scrollableSize.width + (window.scrollX || 0); const isOutsideVerticalScrollable = event.pageY < scrollableSize.top || event.pageY > scrollableSize.top + scrollableSize.height + (window.scrollY || 0); if (isTargetInAllDayPanel && !isOutsideHorizontalScrollable) { return false } return isOutsideVerticalScrollable || isOutsideHorizontalScrollable } setCellDataCache(cellCoordinates, groupIndex, $cell) { const key = JSON.stringify({ rowIndex: cellCoordinates.rowIndex, columnIndex: cellCoordinates.columnIndex, groupIndex: groupIndex }); this.cache.set(key, this.getCellData($cell)) } setCellDataCacheAlias(appointment, geometry) { const key = JSON.stringify({ rowIndex: appointment.rowIndex, columnIndex: appointment.columnIndex, groupIndex: appointment.groupIndex }); const aliasKey = JSON.stringify({ top: geometry.top, left: geometry.left }); this.cache.set(aliasKey, this.cache.get(key)) } supportAllDayRow() { return true } keepOriginalHours() { return false } _filterCellDataFields(cellData) { return extend(true, {}, { startDate: cellData.startDate, endDate: cellData.endDate, groups: cellData.groups, groupIndex: cellData.groupIndex, allDay: cellData.allDay }) } getCellData($cell) { const cellData = this._getFullCellData($cell) || {}; return this._filterCellDataFields(cellData) } _getFullCellData($cell) { const currentCell = $cell[0]; if (currentCell) { return this._getDataByCell($cell) } return } _getVirtualRowOffset() { return this.virtualScrollingDispatcher.virtualRowOffset } _getVirtualCellOffset() { return this.virtualScrollingDispatcher.virtualCellOffset } _getDataByCell($cell) { const rowIndex = $cell.parent().index() - this.virtualScrollingDispatcher.topVirtualRowsCount; const columnIndex = $cell.index() - this.virtualScrollingDispatcher.leftVirtualCellsCount; const { viewDataProvider: viewDataProvider } = this; const isAllDayCell = this._hasAllDayClass($cell); const cellData = viewDataProvider.getCellData(rowIndex, columnIndex, isAllDayCell); return cellData || void 0 } isGroupedByDate() { return this.option("groupByDate") && this._isHorizontalGroupedWorkSpace() && this._getGroupCount() > 0 } getCellIndexByDate(date, inAllDayRow) { const { viewDataGenerator: viewDataGenerator } = this.viewDataProvider; const timeInterval = inAllDayRow ? 864e5 : viewDataGenerator.getInterval(this.option("hoursInterval")); const startViewDateOffset = getStartViewDateTimeOffset(this.getStartViewDate(), this.option("startDayHour")); const dateTimeStamp = this._getIntervalBetween(date, inAllDayRow) + startViewDateOffset; let index = Math.floor(dateTimeStamp / timeInterval); if (inAllDayRow) { index = this._updateIndex(index) } if (index < 0) { index = 0 } return index } getDataByDroppableCell() { const cellData = this.getCellData($(this.getDroppableCell())); const { allDay: allDay } = cellData; const { startDate: startDate } = cellData; const { endDate: endDate } = cellData; return { startDate: startDate, endDate: endDate, allDay: allDay, groups: cellData.groups } } getDateRange() { return [this.getStartViewDate(), this.getEndViewDateByEndDayHour()] } getCellMinWidth() { return 75 } getRoundedCellWidth(groupIndex, startIndex, cellCount) { if (groupIndex < 0 || !hasWindow()) { return 0 } const $row = this.$element().find(`.${DATE_TABLE_ROW_CLASS}`).eq(0); let width = 0; const $cells = $row.find(`.${DATE_TABLE_CELL_CLASS}`); const totalCellCount = this._getCellCount() * groupIndex; cellCount = cellCount || this._getCellCount(); if (!isDefined(startIndex)) { startIndex = totalCellCount } for (let i = startIndex; i < totalCellCount + cellCount; i++) { const element = $($cells).eq(i).get(0); const elementWidth = element ? getBoundingRect(element).width : 0; width += elementWidth } return width / (totalCellCount + cellCount - startIndex) } getCellWidth() { return getCellWidth(this.getDOMElementsMetaData()) } getCellHeight() { return getCellHeight(this.getDOMElementsMetaData()) } getAllDayHeight() { return getAllDayHeight(this.option("showAllDayPanel"), this._isVerticalGroupedWorkSpace(), this.getDOMElementsMetaData()) }