UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

366 lines (352 loc) • 13.2 kB
/** * DevExtreme (ui/scheduler/workspaces/ui.scheduler.work_space.grouped.strategy.horizontal.js) * Version: 20.1.7 * Build date: Tue Aug 25 2020 * * Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; var _position = require("../../../core/utils/position"); var _uiSchedulerWork_spaceGrouped = require("./ui.scheduler.work_space.grouped.strategy"); var _uiSchedulerWork_spaceGrouped2 = _interopRequireDefault(_uiSchedulerWork_spaceGrouped); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj } } function _typeof(obj) { "@babel/helpers - typeof"; if ("function" === typeof Symbol && "symbol" === typeof Symbol.iterator) { _typeof = function(obj) { return typeof obj } } else { _typeof = function(obj) { return obj && "function" === typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj } } return _typeof(obj) } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function") } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true } Object.defineProperty(target, descriptor.key, descriptor) } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) { _defineProperties(Constructor.prototype, protoProps) } if (staticProps) { _defineProperties(Constructor, staticProps) } return Constructor } function _inherits(subClass, superClass) { if ("function" !== typeof superClass && null !== superClass) { throw new TypeError("Super expression must either be null or a function") } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) { _setPrototypeOf(subClass, superClass) } } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function(o, p) { o.__proto__ = p; return o }; return _setPrototypeOf(o, p) } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function() { var result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget) } else { result = Super.apply(this, arguments) } return _possibleConstructorReturn(this, result) } } function _possibleConstructorReturn(self, call) { if (call && ("object" === _typeof(call) || "function" === typeof call)) { return call } return _assertThisInitialized(self) } function _assertThisInitialized(self) { if (void 0 === self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return self } function _isNativeReflectConstruct() { if ("undefined" === typeof Reflect || !Reflect.construct) { return false } if (Reflect.construct.sham) { return false } if ("function" === typeof Proxy) { return true } try { Date.prototype.toString.call(Reflect.construct(Date, [], function() {})); return true } catch (e) { return false } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function(o) { return o.__proto__ || Object.getPrototypeOf(o) }; return _getPrototypeOf(o) } var HORIZONTAL_GROUPED_ATTR = "dx-group-row-count"; var HorizontalGroupedStrategy = function(_GroupedStrategy) { _inherits(HorizontalGroupedStrategy, _GroupedStrategy); var _super = _createSuper(HorizontalGroupedStrategy); function HorizontalGroupedStrategy() { _classCallCheck(this, HorizontalGroupedStrategy); return _super.apply(this, arguments) } _createClass(HorizontalGroupedStrategy, [{ key: "prepareCellIndexes", value: function(cellCoordinates, groupIndex, inAllDay) { var groupByDay = this._workSpace.isGroupedByDate(); if (!groupByDay) { return { rowIndex: cellCoordinates.rowIndex, cellIndex: cellCoordinates.cellIndex + groupIndex * this._workSpace._getCellCount() } } else { return { rowIndex: cellCoordinates.rowIndex, cellIndex: cellCoordinates.cellIndex * this._workSpace._getGroupCount() + groupIndex } } } }, { key: "calculateCellIndex", value: function(rowIndex, cellIndex) { cellIndex %= this._workSpace._getCellCount(); return this._workSpace._getRowCount() * cellIndex + rowIndex } }, { key: "getGroupIndex", value: function(rowIndex, cellIndex) { var groupByDay = this._workSpace.isGroupedByDate(); var groupCount = this._workSpace._getGroupCount(); if (groupByDay) { return cellIndex % groupCount } else { return Math.floor(cellIndex / this._workSpace._getCellCount()) } } }, { key: "calculateHeaderCellRepeatCount", value: function() { return this._workSpace._getGroupCount() || 1 } }, { key: "insertAllDayRowsIntoDateTable", value: function() { return false } }, { key: "getTotalCellCount", value: function(groupCount) { groupCount = groupCount || 1; return this._workSpace._getCellCount() * groupCount } }, { key: "getTotalRowCount", value: function() { return this._workSpace._getRowCount() } }, { key: "addAdditionalGroupCellClasses", value: function(cellClass, index) { cellClass = this._addLastGroupCellClass(cellClass, index); return this._addFirstGroupCellClass(cellClass, index) } }, { key: "_addLastGroupCellClass", value: function(cellClass, index) { var groupByDay = this._workSpace.isGroupedByDate(); if (groupByDay) { if (index % this._workSpace._getGroupCount() === 0) { return cellClass + " " + this.getLastGroupCellClass() } } else { if (index % this._workSpace._getCellCount() === 0) { return cellClass + " " + this.getLastGroupCellClass() } } return cellClass } }, { key: "_addFirstGroupCellClass", value: function(cellClass, index) { if ((index - 1) % this._workSpace._getCellCount() === 0) { return cellClass + " " + this.getFirstGroupCellClass() } return cellClass } }, { key: "getHorizontalMax", value: function(groupIndex) { return this._workSpace.getMaxAllowedPosition()[groupIndex] } }, { key: "getVerticalMax", value: function(groupIndex) { return this._workSpace.getMaxAllowedVerticalPosition()[0] } }, { key: "calculateTimeCellRepeatCount", value: function() { return 1 } }, { key: "getWorkSpaceMinWidth", value: function() { return (0, _position.getBoundingRect)(this._workSpace.$element().get(0)).width - this._workSpace.getTimePanelWidth() } }, { key: "getAllDayOffset", value: function() { return this._workSpace.getAllDayHeight() } }, { key: "getAllDayTableHeight", value: function() { return (0, _position.getBoundingRect)(this._workSpace._$allDayTable.get(0)).height || 0 } }, { key: "getGroupCountAttr", value: function(groupRowCount, groupRows) { return { attr: HORIZONTAL_GROUPED_ATTR, count: groupRows && groupRows.elements.length } } }, { key: "getLeftOffset", value: function() { return this._workSpace.getTimePanelWidth() } }, { key: "getGroupBoundsOffset", value: function(cellCount, $cells, cellWidth, coordinates) { var groupIndex; var cellIndex; var startCellIndex; var startOffset; var endOffset; if (this._workSpace.isGroupedByDate()) { startCellIndex = 0; startOffset = $cells.eq(startCellIndex).offset().left - cellWidth / 2; endOffset = $cells.eq(cellCount * this._workSpace._getGroupCount() - 1).offset().left + cellWidth + cellWidth / 2 } else { cellIndex = this._workSpace.getCellIndexByCoordinates(coordinates); groupIndex = coordinates.groupIndex || Math.floor(cellIndex / cellCount); startCellIndex = groupIndex * cellCount; startOffset = $cells.eq(startCellIndex).offset().left - cellWidth / 2; endOffset = $cells.eq(startCellIndex + cellCount - 1).offset().left + cellWidth + cellWidth / 2 } return { left: startOffset, right: endOffset, top: 0, bottom: 0 } } }, { key: "shiftIndicator", value: function($indicator, height, rtlOffset, groupIndex) { var offset = this._getIndicatorOffset(groupIndex); var horizontalOffset = rtlOffset ? rtlOffset - offset : offset; $indicator.css("left", horizontalOffset); $indicator.css("top", height) } }, { key: "_getIndicatorOffset", value: function(groupIndex) { var groupByDay = this._workSpace.isGroupedByDate(); return groupByDay ? this._calculateGroupByDateOffset(groupIndex) : this._calculateOffset(groupIndex) } }, { key: "_calculateOffset", value: function(groupIndex) { return this._workSpace._getCellCount() * this._workSpace.getRoundedCellWidth(groupIndex - 1, 0) * groupIndex + this._workSpace.getIndicatorOffset(groupIndex) + groupIndex } }, { key: "_calculateGroupByDateOffset", value: function(groupIndex) { return this._workSpace.getIndicatorOffset(0) * this._workSpace._getGroupCount() + this._workSpace.getRoundedCellWidth(groupIndex - 1, 0) * groupIndex } }, { key: "getShaderOffset", value: function(i, width) { var offset = this._workSpace._getCellCount() * this._workSpace.getRoundedCellWidth(i - 1) * i; return this._workSpace.option("rtlEnabled") ? (0, _position.getBoundingRect)(this._workSpace._dateTableScrollable.$content().get(0)).width - offset - this._workSpace.getTimePanelWidth() - width : offset } }, { key: "getShaderTopOffset", value: function(i) { return -this.getShaderMaxHeight() * (i > 0 ? 1 : 0) } }, { key: "getShaderHeight", value: function() { var height = this._workSpace.getIndicationHeight(); return height } }, { key: "getShaderMaxHeight", value: function() { return (0, _position.getBoundingRect)(this._workSpace._dateTableScrollable.$content().get(0)).height } }, { key: "getShaderWidth", value: function(i) { return this._workSpace.getIndicationWidth(i) } }, { key: "getScrollableScrollTop", value: function(allDay) { return !allDay ? this._workSpace.getScrollable().scrollTop() : 0 } }, { key: "getGroupIndexByCell", value: function($cell) { var rowIndex = $cell.parent().index(); var cellIndex = $cell.index(); return this.getGroupIndex(rowIndex, cellIndex) } }]); return HorizontalGroupedStrategy }(_uiSchedulerWork_spaceGrouped2.default); module.exports = HorizontalGroupedStrategy;