devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
278 lines (276 loc) • 12.6 kB
JavaScript
/**
* DevExtreme (cjs/__internal/scheduler/appointment_drag_controller.js)
* Version: 26.1.4
* Build date: Fri Jul 24 2026
*
* Copyright (c) 2012 - 2026 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.AppointmentDragController = void 0;
var _events_engine = _interopRequireDefault(require("../../common/core/events/core/events_engine"));
var _drag = require("../../common/core/events/drag");
var _index = require("../../common/core/events/utils/index");
var _renderer = _interopRequireDefault(require("../../core/renderer"));
var _extend = require("../../core/utils/extend");
var _window = require("../../core/utils/window");
var _m_size = require("../core/utils/m_size");
var _m_draggable = _interopRequireDefault(require("../m_draggable"));
var _const = require("./appointments_new/const");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const APPOINTMENT_DRAG_SOURCE_CLASS = "dx-scheduler-appointment-drag-source";
const TOOLTIP_LIST_ITEM_CLASS = "dx-list-item";
const HIGHLIGHTED_CELL_CLASS = "dx-scheduler-date-table-droppable-cell";
const CELL_SELECTOR = ".dx-scheduler-date-table-cell, .dx-scheduler-all-day-table-cell";
const DRAG_ENTER_EVENT = (0, _index.addNamespace)(_drag.enter, "dxSchedulerAppointmentDrag");
const DRAG_LEAVE_EVENT = (0, _index.addNamespace)(_drag.leave, "dxSchedulerAppointmentDrag");
class AppointmentDragController {
constructor(options) {
this.options = options;
this.workSpaceDraggable = null;
this.tooltipDraggable = null;
this.$initialCell = null;
this.$highlightedCell = null;
this.$dragClone = null;
this.$workSpace = null;
this.draggedItemData = null;
this.onExternalDragEnter = e => {
if (this.draggedItemData) {
return
}
this.highlightCell((0, _renderer.default)(e.target).closest(CELL_SELECTOR))
};
this.onExternalDragLeave = () => {
if (this.draggedItemData) {
return
}
this.removeCellHighlight()
}
}
createWorkSpaceDraggable($workSpace, draggableOptions) {
const config = Object.assign({}, this.getCommonDraggableConfig(), {
filter: `.${_const.APPOINTMENT_CLASSES.CONTAINER}`,
dragTemplate: dragInfo => {
this.$dragClone = (0, _renderer.default)(dragInfo.itemElement).clone();
this.$dragClone.css({
top: "",
left: ""
});
this.$dragClone.removeClass(APPOINTMENT_DRAG_SOURCE_CLASS);
return this.$dragClone
},
onDragStart: e => {
this.onDragStart(e, draggableOptions.getAppointmentData((0, _renderer.default)(e.itemElement)))
}
});
this.workSpaceDraggable = this.options.createComponent($workSpace, _m_draggable.default, config);
this.$workSpace = $workSpace;
_events_engine.default.on($workSpace, DRAG_ENTER_EVENT, CELL_SELECTOR, this.onExternalDragEnter);
_events_engine.default.on($workSpace, DRAG_LEAVE_EVENT, this.onExternalDragLeave)
}
disposeWorkSpaceDraggable() {
var _this$workSpaceDragga;
if (this.$workSpace) {
_events_engine.default.off(this.$workSpace, DRAG_ENTER_EVENT);
_events_engine.default.off(this.$workSpace, DRAG_LEAVE_EVENT);
this.$workSpace = null
}
null === (_this$workSpaceDragga = this.workSpaceDraggable) || void 0 === _this$workSpaceDragga || _this$workSpaceDragga.dispose();
this.workSpaceDraggable = null
}
createTooltipDraggable($tooltipList, draggableOptions) {
let tooltipItem = null;
const config = Object.assign({}, this.getCommonDraggableConfig(), {
filter: ".dx-list-item",
dragTemplate: () => {
if (!tooltipItem) {
return (0, _renderer.default)()
}
const appointmentViewModel = tooltipItem.settings;
this.$dragClone = draggableOptions.dragTemplate(appointmentViewModel);
this.$dragClone.css({
top: "",
left: ""
});
this.$dragClone.removeClass(APPOINTMENT_DRAG_SOURCE_CLASS);
return this.$dragClone
},
onDragStart: e => {
tooltipItem = (0, _renderer.default)(e.itemElement).data("dxListItemData");
this.onDragStart(e, {
appointmentData: tooltipItem.appointment,
targetedAppointmentData: tooltipItem.targetedAppointment ?? tooltipItem.appointment
})
},
cursorOffset: () => ({
x: (0, _m_size.getWidth)(this.$dragClone) / 2,
y: (0, _m_size.getHeight)(this.$dragClone) / 2
})
});
this.tooltipDraggable = this.options.createComponent($tooltipList, _m_draggable.default, config)
}
disposeTooltipDraggable() {
var _this$tooltipDraggabl;
null === (_this$tooltipDraggabl = this.tooltipDraggable) || void 0 === _this$tooltipDraggabl || _this$tooltipDraggabl.dispose();
this.tooltipDraggable = null
}
getCommonDraggableConfig() {
const config = this.options.getAppointmentDraggingConfig();
const draggableConfig = {
component: this.options.component,
container: this.options.$draggableContainer().get(0),
onCancelByEsc: true,
onDragMove: this.onDragMove.bind(this),
onDragEnd: this.onDragEnd.bind(this),
onDragCancel: this.onDragCancel.bind(this),
onDrop: this.onDrop.bind(this)
};
return (0, _extend.extend)(draggableConfig, {
autoScroll: config.autoScroll,
data: config.data,
group: config.group,
scrollSpeed: config.scrollSpeed,
scrollSensitivity: config.scrollSensitivity
})
}
onDragStart(e, draggedItemData) {
var _this$options$getAppo, _this$options$getAppo2;
e.itemData = draggedItemData.appointmentData;
if (!this.options.canDragAppointment(draggedItemData.appointmentData)) {
e.cancel = true;
return
}
null === (_this$options$getAppo = (_this$options$getAppo2 = this.options.getAppointmentDraggingConfig()).onDragStart) || void 0 === _this$options$getAppo || _this$options$getAppo.call(_this$options$getAppo2, e);
if (e.cancel) {
return
}
this.draggedItemData = draggedItemData;
this.$initialCell = this.options.getCellFromDragTarget((0, _renderer.default)(e.itemElement));
this.options.hideAppointmentTooltip();
(0, _renderer.default)(e.itemElement).addClass(APPOINTMENT_DRAG_SOURCE_CLASS)
}
onDragMove(e) {
var _this$options$getAppo3, _this$options$getAppo4;
null === (_this$options$getAppo3 = (_this$options$getAppo4 = this.options.getAppointmentDraggingConfig()).onDragMove) || void 0 === _this$options$getAppo3 || _this$options$getAppo3.call(_this$options$getAppo4, e);
if (e.cancel) {
return
}
const $cell = this.options.getCellFromDragTarget((0, _renderer.default)(this.$dragClone));
if (!$cell) {
this.removeHighlightedCell();
return
}
this.highlightCell($cell)
}
onDragEnd(e) {
var _this$$initialCell$ge, _this$options$getAppo5, _this$options$getAppo6, _this$$initialCell;
const {
draggedItemData: draggedItemData
} = this;
this.draggedItemData = null;
if (!draggedItemData) {
this.removeDraggingClasses((0, _renderer.default)(e.itemElement));
return
}
if (this.$initialCell && !(null !== (_this$$initialCell$ge = this.$initialCell.get(0)) && void 0 !== _this$$initialCell$ge && _this$$initialCell$ge.isConnected)) {
this.$initialCell = null
}
const isSameComponent = e.fromComponent === e.toComponent;
const $dropCell = this.getSourceDropCell(e);
e.toItemData = Object.assign({}, e.itemData, this.options.getUpdatedItemData(e.itemData, $dropCell ?? this.$initialCell ?? void 0));
null === (_this$options$getAppo5 = (_this$options$getAppo6 = this.options.getAppointmentDraggingConfig()).onDragEnd) || void 0 === _this$options$getAppo5 || _this$options$getAppo5.call(_this$options$getAppo6, e);
if (true === e.cancel) {
this.removeDraggingClasses((0, _renderer.default)(e.itemElement));
return
}
if (!isSameComponent) {
var _this$options$getAppo7, _this$options$getAppo8;
null === (_this$options$getAppo7 = (_this$options$getAppo8 = this.options.getAppointmentDraggingConfig()).onRemove) || void 0 === _this$options$getAppo7 || _this$options$getAppo7.call(_this$options$getAppo8, e);
this.removeDraggingClasses((0, _renderer.default)(e.itemElement));
return
}
const isSameCell = (null === (_this$$initialCell = this.$initialCell) || void 0 === _this$$initialCell ? void 0 : _this$$initialCell.is($dropCell ?? (0, _renderer.default)())) ?? false;
if (!$dropCell || isSameCell) {
this.removeDraggingClasses((0, _renderer.default)(e.itemElement));
return
}
this.options.updateAppointmentOnDrop(draggedItemData.appointmentData, draggedItemData.targetedAppointmentData, $dropCell).finally(() => {
this.removeDraggingClasses((0, _renderer.default)(e.itemElement))
}).catch(err => {
throw err
});
this.removeCellHighlight()
}
getSourceDropCell(e) {
const $cell = this.$highlightedCell;
if (!$cell || 0 === $cell.closest(e.fromComponent.$element()).length) {
return null
}
return $cell
}
onDrop(e) {
var _this$options$getAppo9, _this$options$getAppo0;
if (e.fromComponent === e.toComponent) {
return
}
const $cell = this.getDropCell(e) ?? void 0;
e.itemData = Object.assign({}, e.itemData, this.options.getUpdatedItemData(e.itemData, $cell));
null === (_this$options$getAppo9 = (_this$options$getAppo0 = this.options.getAppointmentDraggingConfig()).onAdd) || void 0 === _this$options$getAppo9 || _this$options$getAppo9.call(_this$options$getAppo0, e);
this.removeCellHighlight()
}
getDropCell(e) {
const point = this.getDropPoint(e);
const $cellFromPoint = point ? this.options.getCellFromPoint(point.x, point.y) : null;
if ($cellFromPoint) {
return $cellFromPoint
}
const $droppableCell = this.options.getDroppableCell();
return $droppableCell.length ? $droppableCell : null
}
getDropPoint(e) {
const {
event: event
} = e;
if (!event) {
return null
}
const window = (0, _window.getWindow)();
const toClient = (client, page, scroll) => client ?? (null != page ? page - (scroll || 0) : void 0);
const x = toClient(event.clientX, event.pageX, window.scrollX);
const y = toClient(event.clientY, event.pageY, window.scrollY);
return null != x && null != y ? {
x: x,
y: y
} : null
}
onDragCancel(e) {
this.draggedItemData = null;
this.removeDraggingClasses((0, _renderer.default)(e.itemElement))
}
removeDraggingClasses($dragSource) {
$dragSource.removeClass(APPOINTMENT_DRAG_SOURCE_CLASS);
this.removeCellHighlight()
}
highlightCell($cell) {
this.removeHighlightedCell();
$cell.addClass(HIGHLIGHTED_CELL_CLASS);
this.$highlightedCell = $cell
}
removeHighlightedCell() {
var _this$$highlightedCel;
null === (_this$$highlightedCel = this.$highlightedCell) || void 0 === _this$$highlightedCel || _this$$highlightedCel.removeClass(HIGHLIGHTED_CELL_CLASS);
this.$highlightedCell = null
}
removeCellHighlight() {
this.removeHighlightedCell();
this.options.getDroppableCell().removeClass(HIGHLIGHTED_CELL_CLASS)
}
}
exports.AppointmentDragController = AppointmentDragController;