@syncfusion/ej2-gantt
Version:
Essential JS 2 Gantt Component
917 lines • 171 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { isNullOrUndefined, createElement, extend, addClass, remove, removeClass, closest, merge, classList, getValue } from '@syncfusion/ej2-base';
import { parentsUntil } from '../base/utils';
import { DateProcessor } from '../base/date-processor';
import * as cls from '../base/css-constants';
import { EditTooltip } from '../renderer/edit-tooltip';
/**
* File for handling taskbar editing operation in Gantt.
*/
var TaskbarEdit = /** @class */ (function (_super) {
__extends(TaskbarEdit, _super);
function TaskbarEdit(ganttObj) {
var _this = _super.call(this, ganttObj) || this;
_this.leftValue = 0;
_this.previousLeftValue = 0;
_this.isMouseDragged = false;
_this.dependencyCancel = false;
_this.isDragged = false;
_this.editElement = null;
_this.elementOffsetLeft = 0;
_this.elementOffsetTop = 0;
_this.elementOffsetWidth = 0;
_this.elementOffsetHeight = 0;
_this.segmentIndex = -1;
_this.currentItemTop = 0;
_this.currentItemPrevTop = 0;
_this.topValue = 0;
_this.draggedRecordMarginTop = '0px';
_this.isClonedElement = false;
_this.updatePosition = false;
_this.tooltipValue = 0;
_this.parent = ganttObj;
_this.initPublicProp();
_this.wireEvents();
_this.editTooltip = new EditTooltip(_this.parent, _this);
return _this;
}
TaskbarEdit.prototype.wireEvents = function () {
this.parent.on('chartMouseDown', this.mouseDownHandler, this);
this.parent.on('chartMouseUp', this.mouseUpHandler, this);
this.parent.on('chartMouseLeave', this.mouseLeaveHandler, this);
this.parent.on('chartMouseMove', this.mouseMoveAction, this);
this.parent.on('chartMouseClick', this.mouseClickHandler, this);
};
/**
* To initialize the public property.
*
* @returns {void} .
* @private
*/
TaskbarEdit.prototype.initPublicProp = function () {
this.taskBarEditElement = null;
this.taskBarEditRecord = null;
this.taskBarEditAction = null;
this.connectorSecondElement = null;
this.connectorSecondRecord = null;
this.connectorSecondAction = null;
this.highlightedSecondElement = null;
this.fromPredecessorText = null;
this.toPredecessorText = null;
this.finalPredecessor = null;
this.drawPredecessor = false;
this.roundOffDuration = true;
this.dragMouseLeave = false;
this.isMouseDragged = false;
this.previousItemProperty = ['left', 'progress', 'duration', 'isMilestone', 'startDate', 'endDate', 'width', 'progressWidth',
'autoLeft', 'autoDuration', 'autoStartDate', 'autoEndDate', 'autoWidth', 'segments'];
this.tapPointOnFocus = false;
this.touchEdit = false;
};
TaskbarEdit.prototype.mouseDownHandler = function (e) {
if (this.parent.editSettings.allowTaskbarEditing && !this.parent.readOnly) {
this.canDrag = false;
if (this.taskBarEditElement) {
var targetElement = this.getElementByPosition(e);
var element = parentsUntil(targetElement, cls.taskBarMainContainer);
if ((element && element.innerHTML === this.taskBarEditElement.innerHTML ||
this.taskBarEditElement.classList.contains('e-segmented-taskbar') || this.taskBarEditElement.classList.contains('collpse-parent-border'))) {
this.updateTaskBarEditElement(e);
this.canDrag = true;
e.preventDefault();
}
}
else if (!this.parent.isAdaptive) {
this.updateTaskBarEditElement(e);
}
}
};
TaskbarEdit.prototype.mouseClickHandler = function (e) {
if (!this.parent.editSettings.allowTaskbarEditing) {
return;
}
var targetElement = this.getElementByPosition(e);
var element = parentsUntil(targetElement, cls.taskBarMainContainer);
if (this.parent.selectionModule && this.parent.selectionModule.enableSelectMultiTouch) {
if (this.tapPointOnFocus) {
this.updateTaskBarEditElement(e);
}
return;
}
if (this.tapPointOnFocus && !isNullOrUndefined(this.taskBarEditElement) && element &&
element.innerHTML !== this.taskBarEditElement.innerHTML) {
this.connectorSecondRecord = this.parent.ganttChartModule.getRecordByTaskBar(element);
this.connectorSecondAction = 'ConnectorPointLeftDrag';
this.connectorSecondElement = element;
this.fromPredecessorText = 'Finish';
if (this.validateConnectorPoint()) {
this.taskBarEditingAction(e, true);
}
this.showHideActivePredecessors(false);
this.initPublicProp();
}
else if (targetElement.classList.contains(cls.connectorPointLeftHover)) {
this.canDrag = false;
this.multipleSelectionEnabled();
this.showHideTaskBarEditingElements(targetElement, this.taskBarEditElement);
this.tapPointOnFocus = true;
this.taskBarEditAction = 'ConnectorPointLeftDrag';
this.connectorSecondRecord = this.taskBarEditRecord;
this.taskBarEditingAction(e, false);
}
else if (targetElement.classList.contains(cls.connectorPointRightHover)) {
this.canDrag = false;
this.multipleSelectionEnabled();
this.showHideTaskBarEditingElements(targetElement, this.taskBarEditElement);
this.tapPointOnFocus = true;
this.taskBarEditAction = 'ConnectorPointRightDrag';
this.connectorSecondRecord = this.taskBarEditRecord;
this.taskBarEditingAction(e, false);
}
else {
if (this.tapPointOnFocus) {
this.showHideActivePredecessors(false);
this.showHideTaskBarEditingElements(element, this.taskBarEditElement);
}
this.updateTaskBarEditElement(e);
}
};
TaskbarEdit.prototype.showHideActivePredecessors = function (show) {
var ganttProp = this.taskBarEditRecord.ganttProperties;
var predecessors = ganttProp.predecessor;
var id = this.parent.viewType === 'ResourceView' ? ganttProp.taskId : ganttProp.rowUniqueID;
if (predecessors) {
for (var i = 0; i < predecessors.length; i++) {
var predecessor = predecessors[i];
if (id.toString() === predecessor.from || id.toString() === predecessor.to) {
this.applyActiveColor(predecessor.from, predecessor.to, show);
}
}
}
var chartContent = this.parent.ganttChartModule.chartBodyContainer;
if (show) {
addClass([this.taskBarEditElement], [cls.activeChildTask]);
addClass([chartContent], [cls.touchMode]);
}
else {
removeClass([this.taskBarEditElement], [cls.activeChildTask]);
removeClass([chartContent], [cls.touchMode]);
}
this.touchEdit = show;
if (!isNullOrUndefined(this.parent.toolbarModule)) {
this.parent.toolbarModule.refreshToolbarItems();
}
};
TaskbarEdit.prototype.applyActiveColor = function (from, to, enable) {
var taskId = this.parent.viewType === 'ProjectView' ? this.taskBarEditRecord.ganttProperties.taskId.toString() :
this.taskBarEditRecord.ganttProperties.rowUniqueID.toString();
var ganttRecord = (taskId === from) ? this.parent.connectorLineModule.getRecordByID(to) :
this.parent.connectorLineModule.getRecordByID(from);
var $tr = this.parent.ganttChartModule.getChartRows()[this.parent.currentViewData.indexOf(ganttRecord)];
if (!isNullOrUndefined($tr)) {
var $taskbar = $tr.querySelector('.' + cls.taskBarMainContainer);
var $connectorElement = this.parent.element.querySelector('#ConnectorLineparent' + from + 'child' + to);
if (enable) {
addClass([$taskbar], [cls.activeConnectedTask]);
if ($connectorElement) {
addClass([$connectorElement], [cls.activeConnectedTask]);
}
}
else {
removeClass([$taskbar], [cls.activeConnectedTask]);
if ($connectorElement) {
removeClass([$connectorElement], [cls.activeConnectedTask]);
}
}
}
};
TaskbarEdit.prototype.validateConnectorPoint = function () {
var parentRecord = this.taskBarEditRecord.ganttProperties;
var childRecord = this.connectorSecondRecord.ganttProperties;
var isValid = true;
var parentId = this.parent.viewType === 'ResourceView' ? parentRecord.taskId : parentRecord.rowUniqueID;
var childId = this.parent.viewType === 'ResourceView' ? childRecord.taskId : childRecord.rowUniqueID;
if (this.connectorSecondRecord.hasChildRecords) {
isValid = false;
}
else if (childRecord.predecessor) {
for (var i = 0; i < childRecord.predecessor.length; i++) {
var predecessor = childRecord.predecessor[i];
if (predecessor.from === parentId.toString() &&
predecessor.to === childId.toString()) {
this.parent.connectorLineEditModule.childRecord = this.connectorSecondRecord;
this.parent.connectorLineEditModule.predecessorIndex = i;
this.parent.connectorLineEditModule.renderPredecessorDeleteConfirmDialog();
isValid = false;
break;
}
else if (predecessor.from === childId.toString() &&
predecessor.to === parentId.toString()) {
this.parent.connectorLineEditModule.childRecord = this.taskBarEditRecord;
this.parent.connectorLineEditModule.predecessorIndex = i;
this.parent.connectorLineEditModule.renderPredecessorDeleteConfirmDialog();
isValid = false;
break;
}
}
}
return isValid;
};
// eslint-disable-next-line
TaskbarEdit.prototype.mouseLeaveHandler = function (e) {
if (this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'ParentDrag' ||
this.taskBarEditAction === 'ProgressResizing' || this.taskBarEditAction === 'LeftResizing' ||
this.taskBarEditAction === 'RightResizing') {
this.dragMouseLeave = false;
}
else {
this.dragMouseLeave = true;
}
};
/**
* To update taskbar edited elements on mouse down action.
*
* @param {PointerEvent} e .
* @returns {void} .
* @private
*/
TaskbarEdit.prototype.updateTaskBarEditElement = function (e) {
var target = this.getElementByPosition(e);
var cloneTaskBar;
var element;
if (target.classList.contains(cls.manualParentRightResizer) || target.classList.contains(cls.manualParentMainContainer)
|| target.classList.contains(cls.manualParentTaskBar)) {
element = parentsUntil(target, cls.manualParentMainContainer);
}
else if (target.classList.contains(cls.manualParentMilestone)) {
element = parentsUntil(target, cls.manualParentMilestone);
}
else {
element = parentsUntil(target, cls.taskBarMainContainer);
if (!isNullOrUndefined(element) && !target.classList.contains('e-connectorpoint-left') &&
!target.classList.contains('e-connectorpoint-right')) {
var currentRecord = this.parent.ganttChartModule.getRecordByTaskBar(element);
if (currentRecord && currentRecord.ganttProperties && !isNullOrUndefined(currentRecord.ganttProperties.segments) &&
currentRecord.ganttProperties.segments.length > 0) {
if (target.classList.contains('e-progressbar-handler-after')) {
for (var i = 0; i < currentRecord.ganttProperties.segments.length; i++) {
if (currentRecord.ganttProperties.segments[i].showProgress) {
element = element.querySelectorAll('.e-segmented-taskbar')[i];
break;
}
}
}
else {
element = parentsUntil(target, cls.childTaskBarInnerDiv);
}
}
}
}
if (this.parent.editSettings.allowTaskbarEditing && element) {
this.showHideTaskBarEditingElements(element, this.editElement);
this.editElement = element;
this.realTaskbarElement = this.editElement;
var index = this.editElement.getAttribute('data-segment-index');
if (!isNullOrUndefined(index)) {
this.segmentIndex = Number(index);
}
else {
this.segmentIndex = -1;
}
this.taskBarEditRecord = this.parent.ganttChartModule.getRecordByTaskBar(this.editElement);
if (e.type === 'mousedown' || e.type === 'touchstart' || e.type === 'click') {
this.taskBarEditAction = this.getTaskBarAction(e);
var index_1 = this.editElement.getAttribute('data-segment-index');
var currentRecord = this.parent.ganttChartModule.getRecordByTaskBar(element);
var ganttprop = currentRecord.ganttProperties;
var parentleft = this.editElement.parentElement.offsetLeft;
this.currentData = currentRecord;
var resizeElement = createElement('div', { styles: 'height:100%;border-style:dashed;border-bottom:none;border-top:none;border-width:1px;position:absolute;z-index:10000' });
addClass([resizeElement], 'e-taskbar-resize-div');
resizeElement.style.setProperty('width', ganttprop.width + 'px');
var currentindex = this.editElement.getAttribute('data-segment-index');
if (!isNullOrUndefined(ganttprop.segments) && this.parent.allowTaskbarDragAndDrop && this.taskBarEditAction !== 'LeftResizing' && this.taskBarEditAction !== 'RightResizing' && this.taskBarEditAction !== 'ProgressResizing') {
resizeElement.style.setProperty('left', ((!isNullOrUndefined(ganttprop.segments) ? parentleft + 'px' : (ganttprop.left) + 'px')));
}
else {
resizeElement.style.setProperty('left', (((!isNullOrUndefined(ganttprop.segments) && ganttprop.segments.length > 1) ? parentleft + ganttprop.segments[Number(currentindex)].left + 'px' : (ganttprop.left) + 'px')));
}
var resizeTable = this.parent.createElement('table');
var resizetableBody = this.parent.createElement('tbody');
resizetableBody.appendChild(resizeElement);
resizeTable.appendChild(resizetableBody);
var Check = this.parent.ganttChartModule.chartBodyContainer.querySelector('.e-clone-taskbar');
var createTable = null;
if ((this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'LeftResizing') && !isNullOrUndefined(index_1) && !isNullOrUndefined(index_1) ? Number(index_1) === 0 : false) {
cloneTaskBar = this.editElement.parentElement.cloneNode(true);
}
else {
if (this.segmentIndex !== -1 && this.parent.allowTaskbarDragAndDrop && this.taskBarEditAction !== 'LeftResizing' &&
this.taskBarEditAction !== 'RightResizing' && this.taskBarEditAction !== 'ProgressResizing') {
cloneTaskBar = this.editElement.parentElement.cloneNode(true);
}
else {
cloneTaskBar = this.editElement.cloneNode(true);
}
}
if (!Check) {
addClass([cloneTaskBar], 'e-clone-taskbar');
cloneTaskBar.style.setProperty('position', 'absolute');
if (currentRecord.hasChildRecords && !currentRecord.ganttProperties.isAutoSchedule) {
var containerPosition = this.parent.getOffsetRect(this.parent.ganttChartModule.chartBodyContainer);
var taskbarPosition = this.parent.getOffsetRect(this.editElement);
if (this.editElement.classList.contains('e-manualparent-main-container')) {
cloneTaskBar.style.setProperty('left', (currentRecord.ganttProperties.left - currentRecord.ganttProperties.autoLeft) + 'px');
}
else {
cloneTaskBar.style.setProperty(this.parent.enableRtl ?
'right' : 'left', Math.abs(taskbarPosition.left - containerPosition.left + Math.abs(this.parent.ganttChartModule.scrollElement.scrollLeft)) + 'px');
}
}
cloneTaskBar.style.setProperty('top', 0 + 'px');
createTable = this.parent.createElement('table');
var tableBody = this.parent.createElement('tbody');
tableBody.appendChild(cloneTaskBar);
createTable.appendChild(tableBody);
}
if ((this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'LeftResizing') && !isNullOrUndefined(index_1) && !isNullOrUndefined(index_1) ? Number(index_1) === 0 : false) {
var segmentedTasks = cloneTaskBar.getElementsByClassName('e-segmented-taskbar');
this.cloneTaskbarElement = segmentedTasks[Number(index_1)];
}
else {
this.cloneTaskbarElement = cloneTaskBar;
}
this.taskBarEditElement = this.cloneTaskbarElement;
this.taskbarElement = createTable;
this.taskbarResizer = resizeTable;
this.currentIndex = index_1;
this.roundOffDuration = true;
if ((this.taskBarEditAction === 'ConnectorPointLeftDrag' || this.taskBarEditAction === 'ConnectorPointRightDrag') &&
isNullOrUndefined(this.parent.taskFields.dependency)) {
this.taskBarEditAction = null;
}
this.updateMouseDownProperties(e);
if (this.parent.viewType === 'ResourceView' || this.parent.viewType === 'ProjectView') {
if (this.taskBarEditRecord.level === 0) {
return;
}
else if (this.parent.enableMultiTaskbar) {
var parentRecord = this.parent.getTaskByUniqueID(this.taskBarEditRecord.parentItem.uniqueID);
if (!isNullOrUndefined(parentRecord) && !parentRecord.expanded) {
this.prevZIndex = (this.taskBarEditElement).style.zIndex;
(this.taskBarEditElement).style.zIndex = '1000';
if (this.taskBarEditElement.querySelector('.e-gantt-child-taskbar')) {
addClass([this.taskBarEditElement.querySelector('.e-gantt-child-taskbar')], 'e-collapsed-taskbar-drag');
}
}
}
}
}
}
else {
if (this.parent.isAdaptive) {
if (this.taskBarEditElement) {
this.showHideTaskBarEditingElements(element, this.editElement);
}
this.initPublicProp();
}
else {
this.showHideTaskBarEditingElements(element, this.editElement);
}
}
};
/**
* To show/hide taskbar editing elements.
*
* @param {Element} element .
* @param {Element} secondElement .
* @param {boolean} fadeConnectorLine .
* @returns {void} .
* @private
*/
TaskbarEdit.prototype.showHideTaskBarEditingElements = function (element, secondElement, fadeConnectorLine) {
secondElement = secondElement ? secondElement : this.editElement;
var isShowProgressResizer = this.parent.taskFields.progress ? true : false;
var isShowConnectorPoints = true;
if (this.parent.readOnly) {
return;
}
var record = element ? this.parent.ganttChartModule.getRecordByTaskBar(element) :
secondElement ? this.parent.ganttChartModule.getRecordByTaskBar(secondElement) : null;
if (this.parent.enableMultiTaskbar && element) {
var parentRecord = this.parent.getParentTask(record.parentItem);
if (!isNullOrUndefined(parentRecord)) {
if (!parentRecord.expanded) {
isShowConnectorPoints = false;
if (record && record.ganttProperties.segments &&
record.ganttProperties.segments.length > 0) {
addClass([element.parentElement], [cls.collapseMultiTaskBar]);
}
else {
addClass([element], [cls.collapseMultiTaskBar]);
}
}
}
}
if (element) {
if (element.querySelector('.' + cls.taskBarLeftResizer)) {
addClass([element.querySelector('.' + cls.taskBarLeftResizer)], [cls.leftResizeGripper]);
addClass([element.querySelector('.' + cls.taskBarRightResizer)], [cls.rightResizeGripper]);
if (isShowProgressResizer) {
var progressElement = (record && record.ganttProperties.segments &&
record.ganttProperties.segments.length > 0) ?
element.parentElement.querySelector('.' + cls.childProgressResizer) :
element.querySelector('.' + cls.childProgressResizer);
if (!isNullOrUndefined(progressElement)) {
addClass([progressElement], [cls.progressResizeGripper]);
progressElement.style.top = '3px';
}
}
}
else if (this.parent.isAdaptive && isShowProgressResizer) {
var record_1 = this.parent.ganttChartModule.getRecordByTaskBar(element);
if (record_1.hasChildRecords) {
addClass([element], [cls.activeParentTask]);
}
}
addClass(this.parent.ganttChartModule.scrollElement.querySelectorAll('.' + cls.connectorLineContainer), [cls.connectorLineZIndex]);
if (!isNullOrUndefined(this.parent.taskFields.dependency)
&& (element.querySelector('.' + cls.connectorPointLeft)
|| element.parentElement.querySelector('.' + cls.connectorPointLeft))
&& isShowConnectorPoints) {
var connectorElement = !isNullOrUndefined(element.querySelector('.' + cls.connectorPointLeft)) ?
element : element.parentElement;
if (!isNullOrUndefined(connectorElement.querySelector('.' + cls.connectorPointLeft))) {
addClass([connectorElement.querySelector('.' + cls.connectorPointLeft)], [cls.connectorPointLeftHover]);
}
if (!isNullOrUndefined(connectorElement.querySelector('.' + cls.connectorPointRight))) {
addClass([connectorElement.querySelector('.' + cls.connectorPointRight)], [cls.connectorPointRightHover]);
}
}
}
else if (!fadeConnectorLine) {
removeClass(this.parent.ganttChartModule.scrollElement.querySelectorAll('.' + cls.connectorLineContainer), [cls.connectorLineZIndex]);
}
if (secondElement && element !== secondElement) {
if (secondElement.querySelector('.' + cls.taskBarLeftResizer)) {
removeClass([secondElement.querySelector('.' + cls.taskBarLeftResizer)], [cls.leftResizeGripper]);
removeClass([secondElement.querySelector('.' + cls.taskBarRightResizer)], [cls.rightResizeGripper]);
var progressElement = (record && record.ganttProperties.segments && record.ganttProperties.segments.length > 0) ?
secondElement.parentElement : secondElement;
if (progressElement && progressElement.querySelector('.' + cls.childProgressResizer)) {
removeClass([progressElement.querySelector('.' + cls.childProgressResizer)], [cls.progressResizeGripper]);
}
}
if (!isNullOrUndefined(this.parent.taskFields.dependency)
&& (secondElement.querySelector('.' + cls.connectorPointLeft)
|| secondElement.parentElement.querySelector('.' + cls.connectorPointLeft))) {
var connectorElement = !isNullOrUndefined(secondElement.querySelector('.' + cls.connectorPointLeft)) ?
secondElement : secondElement.parentElement;
var leftConnector = connectorElement.querySelector('.' + cls.connectorPointLeft);
var rightConnector = connectorElement.querySelector('.' + cls.connectorPointRight);
if (leftConnector) {
removeClass([leftConnector], [cls.connectorPointLeftHover]);
}
if (rightConnector) {
removeClass([rightConnector], [cls.connectorPointRightHover]);
}
}
else if (this.parent.isAdaptive) {
var record_2 = this.parent.ganttChartModule.getRecordByTaskBar(secondElement);
if (record_2 && record_2.hasChildRecords) {
removeClass([secondElement], [cls.activeParentTask]);
}
}
this.editElement = null;
}
};
/**
* To get taskbar edit actions.
*
* @param {PointerEvent} e .
* @returns {string} .
* @private
*/
TaskbarEdit.prototype.getTaskBarAction = function (e) {
var mouseDownElement = this.getElementByPosition(e);
var data = this.taskBarEditRecord;
var action = '';
if (mouseDownElement.classList.contains(cls.taskBarLeftResizer)) {
action = 'LeftResizing';
}
else if (mouseDownElement.classList.contains(cls.taskBarRightResizer)) {
action = 'RightResizing';
}
else if ((mouseDownElement.classList.contains(cls.childProgressResizer) ||
closest(mouseDownElement, '.' + cls.childProgressResizer)) && (this.parent.taskFields.progress)) {
action = 'ProgressResizing';
}
else if (mouseDownElement.classList.contains(cls.connectorPointLeft)) {
action = 'ConnectorPointLeftDrag';
}
else if (mouseDownElement.classList.contains(cls.connectorPointRight)) {
action = 'ConnectorPointRightDrag';
}
else if (mouseDownElement.classList.contains(cls.manualParentRightResizer)) {
action = 'ParentResizing';
}
else if (mouseDownElement.classList.contains(cls.manualParentTaskBar) ||
mouseDownElement.classList.contains(cls.manualParentMainContainer) ||
mouseDownElement.classList.contains(cls.manualParentMilestone)) {
action = 'ManualParentDrag';
}
else if (data) {
action = data.hasChildRecords ? data[this.parent.taskFields.manual] ? '' : 'ParentDrag'
: data.ganttProperties.isMilestone ? 'MilestoneDrag' : 'ChildDrag';
}
return action;
};
/**
* To update property while perform mouse down.
*
* @param {PointerEvent} event .
* @returns {void} .
* @private
*/
TaskbarEdit.prototype.updateMouseDownProperties = function (event) {
var e = this.getCoordinate(event);
var parentWithZoomStyle = this.parent.element.closest('[style*="zoom"]');
if (parentWithZoomStyle) {
var zoom1 = parseFloat(getComputedStyle(parentWithZoomStyle).zoom);
e.pageX = e.pageX / zoom1;
e.pageY = e.pageY / zoom1;
}
if (e.pageX || e.pageY) {
var containerPosition = this.parent.getOffsetRect(this.parent.ganttChartModule.chartBodyContainer);
if (this.parent.enableRtl) {
this.mouseDownX = Math.abs(e.pageX - (containerPosition.left +
Math.abs(this.parent.ganttChartModule.scrollObject.previousScroll.left)));
}
else {
this.mouseDownX = (e.pageX - containerPosition.left) +
this.parent.ganttChartModule.scrollObject.previousScroll.left;
}
this.tooltipPositionX = this.mouseDownX;
this.mouseDownY = this.dragMoveY = e.pageY - containerPosition.top +
this.parent.ganttChartModule.scrollObject.previousScroll.top;
}
if (this.taskBarEditAction === 'ConnectorPointLeftDrag' || this.taskBarEditAction === 'ConnectorPointRightDrag') {
this.fromPredecessorText = this.taskBarEditAction === 'ConnectorPointLeftDrag' ? 'start' : 'finish';
this.parent.connectorLineModule.tooltipTable.innerHTML = '';
this.parent.connectorLineModule.tooltipTable.appendChild(this.parent.connectorLineModule.getConnectorLineTooltipInnerTd(this.taskBarEditRecord.ganttProperties.taskName, this.fromPredecessorText, '', ''));
}
};
TaskbarEdit.prototype.isMouseDragCheck = function () {
if (!this.isMouseDragged && this.taskBarEditAction && ((this.mouseDownX !== this.mouseMoveX) &&
((this.mouseDownX + 3) < this.mouseMoveX || (this.mouseDownX - 3) > this.mouseMoveX)
|| (this.mouseDownY !== this.mouseMoveY) &&
((this.mouseDownY + 3) < this.mouseMoveY || (this.mouseDownY - 3) > this.mouseMoveY))) {
this.isMouseDragged = true;
this.parent.initiateEditAction(true);
var item = this.taskBarEditRecord.ganttProperties;
this.previousItem = this.parent.timelineModule.extendFunction(item, this.previousItemProperty);
if (this.taskBarEditAction !== 'ConnectorPointLeftDrag' &&
this.taskBarEditAction !== 'ConnectorPointRightDrag' &&
!(this.parent.viewType === 'ResourceView' && this.taskBarEditAction === 'ParentDrag')) {
this.editTooltip.showHideTaskbarEditTooltip(true, this.segmentIndex);
}
this.taskBarEditElement.setAttribute('aria-grabbed', 'true');
}
};
/* eslint-disable-next-line */
TaskbarEdit.prototype.removeFirstBorder = function (element) {
var canremove = this.parent.rowDragAndDropModule['dropPosition'] === 'bottomSegment';
if (this.parent.element.getElementsByClassName('e-firstrow-border').length > 0 && element &&
(element.getAttribute('aria-rowindex') - 1 !== 0 || canremove)) {
this.parent.element.getElementsByClassName('e-firstrow-border')[0].remove();
}
};
TaskbarEdit.prototype.removeLastBorder = function (element) {
var isEmptyRow = element && (element.classList.contains('e-emptyrow') || element.classList.contains('e-columnheader')
|| element.classList.contains('e-detailrow'));
var islastRowIndex;
if (this.parent.enableVirtualization) {
islastRowIndex = element && !isEmptyRow &&
this.parent.treeGrid.getRows()[this.parent.treeGrid.getCurrentViewRecords().length - 1].getAttribute('data-uid') !==
element.getAttribute('data-uid');
}
else {
islastRowIndex = element && !isEmptyRow &&
this.parent.treeGrid.getRowByIndex(this.parent.treeGrid.getCurrentViewRecords().length - 1).getAttribute('data-uid') !==
element.getAttribute('data-uid');
}
var canremove = islastRowIndex || this.parent.rowDragAndDropModule['dropPosition'] === 'topSegment';
if (this.parent.element.getElementsByClassName('e-lastrow-border').length > 0 && element && (islastRowIndex || canremove)) {
this.parent.element.getElementsByClassName('e-lastrow-border')[0].remove();
}
};
TaskbarEdit.prototype.removetopOrBottomBorder = function () {
var border = [].slice.call(this.parent.element.querySelectorAll('.e-dropbottom, .e-droptop'));
if (border.length) {
this.addRemoveClasses(border, false, 'e-dropbottom');
this.addRemoveClasses(border, false, 'e-droptop');
}
};
TaskbarEdit.prototype.topOrBottomBorder = function (target) {
var rowElement;
if (this.parent.enableVirtualization) {
var gridElement = this.parent.treeGrid.getRows().filter(function (data) {
return parseInt(data.getAttribute('aria-rowindex'), 10) - 1 === parseInt(target.getAttribute('aria-rowindex'), 10) - 1;
})[0];
var index = this.parent.treeGrid.getRows().indexOf(gridElement);
rowElement = this.parent.getRowByIndex(index).children;
}
else {
rowElement = this.parent.getRowByIndex(parseInt(target.getAttribute('aria-rowindex'), 10) - 1).children;
}
if (rowElement) {
if (this.parent.rowDragAndDropModule['dropPosition'] === 'above') {
this.addRemoveClasses(rowElement, true, 'e-droptop');
if (this.parent.element.getElementsByClassName('e-lastrow-dragborder').length > 0) {
this.parent.element.getElementsByClassName('e-lastrow-dragborder')[0].remove();
}
}
if (this.parent.rowDragAndDropModule['dropPosition'] === 'below') {
this.addRemoveClasses(rowElement, true, 'e-dropbottom');
}
}
};
TaskbarEdit.prototype.removeChildBorder = function () {
var borderElem = [].slice.call(this.parent.element.querySelectorAll('.e-childborder'));
if (borderElem.length > 0) {
this.addRemoveClasses(borderElem, false, 'e-childborder');
}
};
TaskbarEdit.prototype.addRemoveClasses = function (cells, add, className) {
for (var i = 0, len = cells.length; i < len; i++) {
if (add) {
cells[parseInt(i.toString(), 10)].classList.add(className);
}
else {
cells[parseInt(i.toString(), 10)].classList.remove(className);
}
}
};
TaskbarEdit.prototype.addErrorElem = function () {
var dragelem = document.getElementsByClassName('e-clone-taskbar')[0];
var errorelem = document.querySelectorAll('.e-errorelem').length;
if (!errorelem) {
var ele = document.createElement('div');
classList(ele, ['e-errorcontainer'], []);
classList(ele, ['e-icons', 'e-errorelem'], []);
if (this.taskBarEditRecord.ganttProperties.segments && this.taskBarEditRecord.ganttProperties.segments.length > 0) {
ele.style.paddingTop = this.parent.taskbarHeight + 'px';
}
dragelem.appendChild(ele);
}
};
TaskbarEdit.prototype.removeErrorElem = function () {
var errorelem = document.querySelector('.e-errorelem');
if (errorelem) {
errorelem.remove();
}
};
TaskbarEdit.prototype.ensurePosition = function (draggedRecords, currentRecord) {
var _this = this;
draggedRecords.filter(function (draggedRecord) {
if (draggedRecord.hasChildRecords && !isNullOrUndefined(draggedRecord.childRecords)) {
var valid = draggedRecord.childRecords.indexOf(currentRecord);
if (valid === -1) {
_this.ensurePosition(draggedRecord.childRecords, currentRecord);
}
else {
_this.parent.rowDragAndDropModule['dropPosition'] = 'Invalid';
_this.addErrorElem();
return;
}
}
});
};
/**
* To handle mouse move action in chart
*
* @param {PointerEvent} event .
* @returns {void} .
* @private
*/
TaskbarEdit.prototype.mouseMoveAction = function (event) {
var _this = this;
if (this.parent.isAdaptive) {
if (!this.canDrag) {
return;
}
else {
this.multipleSelectionEnabled();
}
}
var containerPosition = this.parent.getOffsetRect(this.parent.ganttChartModule.chartBodyContainer);
var e = this.getCoordinate(event);
if (this.parent.enableRtl) {
this.mouseMoveX = Math.abs(e.pageX - (containerPosition.left +
Math.abs(this.parent.ganttChartModule.scrollObject.previousScroll.left)));
}
else {
this.mouseMoveX = e.pageX - containerPosition.left +
this.parent.ganttChartModule.scrollObject.previousScroll.left;
}
this.mouseMoveY = e.pageY - containerPosition.top +
this.parent.ganttChartModule.scrollObject.previousScroll.top;
this.dragMouseLeave = false;
var cancel = false;
if (this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'ParentDrag' || this.taskBarEditAction === 'ManualParentDrag' || this.taskBarEditAction === 'MilestoneDrag') {
var ganttRowElement = void 0;
if (this.parent.enableVirtualization) {
var index = this.parent.currentViewData.indexOf(this.taskBarEditRecord);
ganttRowElement = this.parent.getRowByIndex(index);
}
else {
ganttRowElement = this.parent.getRowByIndex(this.taskBarEditRecord.index);
}
var eventArgs = {
cancel: cancel,
cloneElement: this.taskbarElement,
data: this.taskBarEditRecord,
target: event.target,
rows: ganttRowElement
};
this.parent.trigger('rowDrag', eventArgs);
cancel = eventArgs['cancel'];
}
if (!cancel) {
this.isMouseDragCheck();
}
if (this.isMouseDragged && this.taskBarEditAction) {
event.preventDefault();
if (!isNullOrUndefined(this.taskbarElement) && !isNullOrUndefined(this.editElement) && (this.taskBarEditAction !== 'ConnectorPointRightDrag' &&
this.taskBarEditAction !== 'ConnectorPointLeftDrag') && !(this.parent.viewType === 'ResourceView' && this.currentData.hasChildRecords)) {
var currentElement = this.editElement.parentElement;
if (this.parent.enableTimelineVirtualization &&
this.parent.timelineModule.wholeTimelineWidth > this.parent.element.offsetWidth * 3) {
currentElement.style.setProperty('position', 'relative');
}
else {
currentElement.style.setProperty('position', 'absolute');
}
if ((this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'LeftResizing') &&
!isNullOrUndefined(this.currentIndex) && !isNullOrUndefined(this.currentIndex) ? Number(this.currentIndex) === 0 : false) {
this.taskbarElement.childNodes[0].childNodes[0].style.setProperty('top', currentElement.parentElement.offsetTop + 'px');
if (this.parent.allowTaskbarDragAndDrop && this.taskBarEditAction !== 'LeftResizing' && this.taskBarEditAction !== 'RightResizing' && this.taskBarEditAction !== 'ProgressResizing') {
this.parent.chartPane.getElementsByClassName('e-gantt-chart')[0].appendChild(this.taskbarElement);
}
else {
currentElement.parentElement.appendChild(this.taskbarElement);
}
}
else {
if (this.parent.allowTaskbarDragAndDrop && this.taskBarEditAction !== 'LeftResizing' && this.taskBarEditAction !== 'RightResizing' && this.taskBarEditAction !== 'ProgressResizing') {
this.parent.chartPane.getElementsByClassName('e-gantt-chart')[0].appendChild(this.taskbarElement);
}
else {
currentElement.appendChild(this.taskbarElement);
}
}
if (this.taskBarEditAction !== 'ProgressResizing') {
if (this.parent.enableTimelineVirtualization &&
this.parent.timelineModule.wholeTimelineWidth > this.parent.element.offsetWidth * 3) {
var rootElement = this.parent.ganttChartModule.chartBodyContainer.querySelectorAll('.e-chart-scroll-container');
rootElement[0].appendChild(this.taskbarResizer);
}
else {
var rootElement = this.parent.ganttChartModule.chartBodyContainer.querySelectorAll('.e-chart-rows-container');
rootElement[0].appendChild(this.taskbarResizer);
}
}
}
if (this.parent.allowTaskbarDragAndDrop && (this.taskBarEditAction === 'ChildDrag' || this.taskBarEditAction === 'ParentDrag' ||
this.taskBarEditAction === 'MilestoneDrag' || this.taskBarEditAction === 'ManualParentDrag')) {
var taskbarPosition = this.parent.getOffsetRect(this.taskBarEditElement);
var left = (!isNullOrUndefined(document.body.className) && document.body.className.includes('e-bigger')) ? 12 : 0;
var pointerLeft = (3 + this.parent.chartRowsModule.connectorPointWidth + left);
var xValue = void 0;
if (this.parent.enableRtl) {
xValue = Math.abs(taskbarPosition.left + pointerLeft + 1);
}
else {
xValue = Math.abs(taskbarPosition.left - pointerLeft - 1);
}
if (!this.isClonedElement && !this.parent.enableRtl) {
xValue = xValue - this.parent.ganttChartModule.scrollElement.scrollLeft;
this.isClonedElement = true;
}
var rowPositionHeight = 0;
this.parent.rowDragAndDropModule['dropPosition'] = undefined;
var target = void 0;
var yValue = void 0;
if (event.type === 'touchmove' || event.type === 'touchstart' || event.type === 'touchend') {
yValue = event['changedTouches'][0].pageY;
}
else {
yValue = event.y;
}
if (this.parent.enableRtl) {
target = document.elementFromPoint(this.parent.ganttChartModule.chartBodyContainer.offsetWidth, yValue);
if (target.classList.contains('e-taskbar-resize-div')) {
target = document.elementFromPoint(this.parent.ganttChartModule.chartBodyContainer.offsetWidth - target['offsetWidth'], yValue);
}
}
else {
target = document.elementFromPoint(xValue, yValue);
}
var draggedTreeGridRowElement = void 0;
if (this.parent.enableVirtualization) {
if (!this.draggedTreeGridRowElement) {
var currentElement = this.editElement.parentElement;
draggedTreeGridRowElement = currentElement.parentElement;
this.draggedTreeGridRowElement = draggedTreeGridRowElement;
this.draggedTreeGridRowHeight = this.draggedTreeGridRowElement.offsetHeight;
}
}
else {
draggedTreeGridRowElement = this.parent.treeGrid.getRows()[this.parent.flatData.indexOf(this.taskBarEditRecord)];
this.draggedTreeGridRowElement = draggedTreeGridRowElement;
if (this.parent.enableMultiTaskbar) {
if (this.taskBarEditRecord.parentItem &&
!isNullOrUndefined(this.parent.getRowByID(this.taskBarEditRecord.parentItem.taskId))) {
this.draggedTreeGridRowHeight = this.parent.getRowByID(this.taskBarEditRecord.parentItem.taskId).offsetHeight;
if (this.parent.viewType === 'ProjectView' && this.draggedTreeGridRowHeight === 0) {
var nestedParent = this.parent.getRecordByID(this.taskBarEditRecord.parentItem.taskId);
while (nestedParent.parentItem) {
nestedParent = this.parent.getRecordByID(nestedParent.parentItem.taskId);
this.draggedTreeGridRowHeight = this.parent.getRowByID(nestedParent['TaskID']).offsetHeight;
}
}
}
else {
var currentElement = this.editElement.parentElement;
this.draggedTreeGridRowElement = currentElement.parentElement;
this.draggedTreeGridRowHeight = this.draggedTreeGridRowElement.offsetHeight;
}
}
else {
this.draggedTreeGridRowHeight = this.draggedTreeGridRowElement.offsetHeight;
}
}
var chartRowElement_1;
if (target) {
chartRowElement_1 = closest(target, 'tr.' + cls.chartRow);
}
if (chartRowElement_1) {
var droppedTreeGridRowElement = void 0;
if (this.parent.enableVirtualization) {
droppedTreeGridRowElement = this.parent.treeGrid.getRows().filter(function (data) {
return parseInt(data.getAttribute('aria-rowindex'), 10) - 1 === parseInt(chartRowElement_1.getAttribute('aria-rowindex'), 10) - 1;
})[0];
}
else {
droppedTreeGridRowElement = this.parent.treeGrid.getRows()[parseInt(chartRowElement_1.getAttribute('aria-rowindex'), 10) - 1];
}
this.removeFirstBorder(droppedTreeGridRowElement);
this.removeLastBorder(droppedTreeGridRowElement);
if (!isNullOrUndefined(droppedTreeGridRowElement) && droppedTreeGridRowElement.getAttribute('data-uid') === this.draggedTreeGridRowElement.getAttribute('data-uid')
|| !parentsUntil(target, 'e-chart-rows-container')) {
this.parent.rowDragAndDropModule['dropPosition'] = 'Invalid';
this.addErrorElem();
}
var tObj = this.parent;
var rowTop = 0;
var toolHeight = tObj.toolbarModule ?
this.parent.toolbarModule.element.offsetHeight : 0;
var positionOffSet = this.parent.getOffsetRect(tObj.element);
var contentHeight = tObj.treeGrid.getHeaderContent().offsetHeight + positionOffSet.top + toolHeight;
var scrollTop = tObj.treeGrid.getContent().firstElementChild.scrollTop;
if (!isNullOrUndefined(droppedTreeGridRowElement)) {
rowPositionHeight = droppedTreeGridRowElement.offsetTop - scrollTop;
}
if (this.parent.enableVirtualization) {
rowTop = this.parent.getOffsetRect(droppedTreeGridRowElement).top;
}
else {
rowTop = rowPositionHeight + contentHeight;
}
var rowBottom = rowTop + this.draggedTreeGridRowHeight;
var difference = rowBottom - rowTop;
var divide = difference / 3;
var topRo