all files / renderer/ edit-tooltip.js

93.23% Statements 124/133
87.18% Branches 102/117
100% Functions 11/11
93.23% Lines 124/133
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249   805× 805×   153× 153×                   153× 153× 153×         153×   153× 149×   153× 153×   150× 150× 150× 150× 150× 150× 150×     150× 150× 150×                 328× 153× 153× 153× 153×   153×   151×       151×     175× 151× 151×     316× 316×   316×   316×   316× 303×           301×   301× 301×         301×   301× 47×     45×     254×   64×     62×     190× 18×       18×     172× 10×   162× 158×   301×           303× 303× 303× 303×   28×   303×       295× 295× 295× 295× 295×       295× 295×       295× 293×       295×     12×   12×   12×       47×   47×         64×   64×             170× 170× 170× 170×   170× 170×   170× 170×                     303× 293× 293×   293×     10×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-popups", "../base/css-constants"], function (require, exports, ej2_base_1, ej2_popups_1, cls) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var EditTooltip = (function () {
        function EditTooltip(gantt, taskbarEdit) {
            this.parent = gantt;
            this.taskbarEdit = taskbarEdit;
        }
        EditTooltip.prototype.createTooltip = function (opensOn, mouseTrail, target) {
            var _this = this;
            this.toolTipObj = new ej2_popups_1.Tooltip({
                opensOn: opensOn,
                position: 'TopRight',
                enableRtl: this.parent.enableRtl,
                mouseTrail: mouseTrail,
                cssClass: cls.ganttTooltip,
                windowCollision: true,
                target: target ? target : null,
                animation: { open: { effect: 'None' }, close: { effect: 'None' } }
            });
            this.toolTipObj.target = '.e-connectorpoint-left, .e-connectorpoint-right';
            this.toolTipObj.beforeRender = function (args) {
                var argsData = {
                    data: _this.taskbarEdit.taskBarEditRecord,
                    args: args,
                    content: _this.toolTipObj.content
                };
                _this.parent.trigger('beforeTooltipRender', argsData);
            };
            this.toolTipObj.afterOpen = function (args) {
                _this.updateTooltipPosition(args);
            };
            this.toolTipObj.isStringTemplate = true;
            this.toolTipObj.appendTo(this.parent.chartPane);
        };
        EditTooltip.prototype.updateTooltipPosition = function (args) {
            args.element.style.visibility = 'visible';
            var parentWithZoomStyle = this.parent.element.closest('[style*="zoom"]');
            Eif (ej2_base_1.isNullOrUndefined(parentWithZoomStyle)) {
                var containerPosition = this.parent.getOffsetRect(this.parent.chartPane);
                var leftEnd = containerPosition.left + this.parent.chartPane.offsetWidth;
                var tooltipPositionX = args.element.offsetLeft;
                Iif (leftEnd < (tooltipPositionX + args.element.offsetWidth)) {
                    tooltipPositionX += leftEnd - (tooltipPositionX + args.element.offsetWidth);
                }
                args.element.style.left = tooltipPositionX + 'px';
                args.element.style.visibility = 'visible';
                if (args.target && this.parent.tooltipSettings.editing) {
                    var top_1 = args.target.getBoundingClientRect().top + window.scrollY;
                    var tooltipPositionY = void 0;
                    Iif (args.target.classList.contains('e-connectorpoint-left') ||
                        args.target.classList.contains('e-connectorpoint-right')) {
                        tooltipPositionY = top_1 - (args.element.offsetHeight) - 14;
                    }
                    else {
                        tooltipPositionY = top_1 - (args.element.offsetHeight) - 8;
                    }
                    this.toolTipHeight = args.element.style.top = tooltipPositionY + 'px';
                }
            }
        };
        EditTooltip.prototype.showHideTaskbarEditTooltip = function (bool, segmentIndex) {
            if (bool && this.parent.tooltipSettings.showTooltip) {
                this.createTooltip('Custom', false);
                this.parent.tooltipModule.toolTipObj.close();
                this.updateTooltip(segmentIndex);
                if (this.parent.tooltipSettings.editing) {
                    this.toolTipObj.openDelay = 500;
                }
                if (this.taskbarEdit.connectorSecondAction === 'ConnectorPointLeftDrag') {
                    this.toolTipObj.open(this.taskbarEdit.connectorSecondElement.querySelector('.' + cls.connectorPointLeft));
                }
                else Iif (this.taskbarEdit.connectorSecondAction === 'ConnectorPointRightDrag') {
                    this.toolTipObj.open(this.taskbarEdit.connectorSecondElement.querySelector('.' + cls.connectorPointRight));
                }
                else {
                    this.toolTipObj.open(this.taskbarEdit.taskBarEditElement);
                }
            }
            else if (!ej2_base_1.isNullOrUndefined(this.toolTipObj)) {
                this.toolTipObj.destroy();
                this.toolTipObj = null;
            }
        };
        EditTooltip.prototype.updateTooltip = function (segmentIndex) {
            var ganttProp = this.taskbarEdit.taskBarEditRecord.ganttProperties;
            var taskWidth = (ej2_base_1.isNullOrUndefined(segmentIndex) || segmentIndex === -1) ? ganttProp.width :
                ganttProp.segments[segmentIndex].width;
            var progressWidth = (ej2_base_1.isNullOrUndefined(segmentIndex) || segmentIndex === -1) ? ganttProp.progressWidth :
                ganttProp.segments[segmentIndex].progressWidth;
            var left = (ej2_base_1.isNullOrUndefined(segmentIndex) || segmentIndex === -1) ? ganttProp.left : ganttProp.left +
                ganttProp.segments[segmentIndex].left;
            if (!ej2_base_1.isNullOrUndefined(this.toolTipObj)) {
                if (this.taskbarEdit.taskBarEditAction === 'ConnectorPointLeftDrag' ||
                    this.taskbarEdit.taskBarEditAction === 'ConnectorPointRightDrag') {
                    this.toolTipObj.content = this.getTooltipText(segmentIndex);
                    Iif (this.parent.tooltipSettings.editing) {
                        this.toolTipObj.openDelay = 500;
                    }
                    this.toolTipObj.offsetY = -3;
                }
                else {
                    if (this.parent.tooltipSettings.editing) {
                        this.toolTipObj.openDelay = 500;
                    }
                    this.toolTipObj.content = this.getTooltipText(segmentIndex);
                    Iif (ganttProp.segments && ganttProp.segments.length > 0 && this.taskbarEdit['mainElement'] && this.taskbarEdit.taskBarEditAction === 'ProgressResizing') {
                        var segments = this.taskbarEdit['mainElement'].querySelectorAll('.e-segmented-taskbar');
                        this.toolTipObj.refresh(segments[segmentIndex]);
                    }
                    else {
                        this.toolTipObj.refresh(this.taskbarEdit.taskBarEditElement);
                    }
                    if (this.taskbarEdit.taskBarEditAction === 'LeftResizing') {
                        if (this.parent.enableRtl) {
                            this.toolTipObj.offsetX = 0;
                        }
                        else {
                            this.toolTipObj.offsetX = -taskWidth;
                        }
                    }
                    else if (this.taskbarEdit.taskBarEditAction === 'RightResizing' ||
                        this.taskbarEdit.taskBarEditAction === 'ParentResizing') {
                        if (this.parent.enableRtl) {
                            this.toolTipObj.offsetX = -taskWidth;
                        }
                        else {
                            this.toolTipObj.offsetX = 0;
                        }
                    }
                    else if (this.taskbarEdit.taskBarEditAction === 'ProgressResizing') {
                        Iif (this.parent.enableRtl) {
                            this.toolTipObj.offsetX = -(progressWidth);
                        }
                        else {
                            this.toolTipObj.offsetX = -(taskWidth - progressWidth);
                        }
                    }
                    else if (this.taskbarEdit.taskBarEditAction === 'MilestoneDrag') {
                        this.toolTipObj.offsetX = -(this.parent.chartRowsModule.milestoneHeight / 2);
                    }
                    else if (taskWidth > 5) {
                        this.toolTipObj.offsetX = -(taskWidth + left - this.taskbarEdit.tooltipPositionX);
                    }
                    Iif (this.parent.tooltipSettings.editing && document.getElementsByClassName('e-gantt-tooltip')[0] && this.toolTipHeight) {
                        document.getElementsByClassName('e-gantt-tooltip')[0].style.top = this.toolTipHeight;
                    }
                }
            }
        };
        EditTooltip.prototype.getTooltipText = function (segmentIndex) {
            var tooltipString = '';
            var instance = this.parent.globalize;
            var editRecord = this.taskbarEdit.taskBarEditRecord.ganttProperties;
            if (!ej2_base_1.isNullOrUndefined(editRecord.segments) && editRecord.segments.length > 0 && segmentIndex !== -1
                && this.taskbarEdit.taskBarEditAction !== 'ProgressResizing') {
                editRecord = editRecord.segments[segmentIndex];
            }
            if (this.parent.tooltipSettings.editing) {
                var templateNode = this.parent.tooltipModule.templateCompiler(this.parent.tooltipSettings.editing, this.parent, this.taskbarEdit.taskBarEditRecord, 'TooltipEditingTemplate');
                if (ej2_base_1.getValue('tooltipEle', this.toolTipObj)) {
                    this.parent.renderTemplates();
                }
                tooltipString = templateNode[0];
            }
            else {
                var startDate = void 0;
                var endDate = void 0;
                var duration = void 0;
                Eif (!ej2_base_1.isNullOrUndefined(editRecord) && !ej2_base_1.isNullOrUndefined(editRecord.startDate)) {
                    startDate = '<tr><td class = "e-gantt-tooltip-label">' + this.parent.localeObj.getConstant('startDate') +
                        '</td><td style="padding: 2px;">:</td><td class = "e-gantt-tooltip-value">' +
                        instance.formatDate(editRecord.startDate, { format: this.parent.getDateFormat() }) + '</td></tr>';
                }
                Eif (!ej2_base_1.isNullOrUndefined(editRecord) && !ej2_base_1.isNullOrUndefined(editRecord.endDate)) {
                    endDate = '<tr><td class = "e-gantt-tooltip-label">' + this.parent.localeObj.getConstant('endDate') +
                        '</td><td style="padding: 2px;">:</td><td class = "e-gantt-tooltip-value">' +
                        instance.formatDate(editRecord.endDate, { format: this.parent.getDateFormat() }) + '</td></tr>';
                }
                if (!ej2_base_1.isNullOrUndefined(editRecord) && !ej2_base_1.isNullOrUndefined(editRecord.duration)) {
                    duration = '<tr><td class = "e-gantt-tooltip-label">' + this.parent.localeObj.getConstant('duration') +
                        '</td><td style="padding: 2px;">:</td><td class = "e-gantt-tooltip-value">' +
                        this.parent.getDurationString(editRecord.duration, editRecord.durationUnit) + '</td></tr>';
                }
                switch (this.taskbarEdit.taskBarEditAction) {
                    case 'ProgressResizing':
                        {
                            var progress = '<tr><td class = "e-gantt-tooltip-label">' + this.parent.localeObj.getConstant('progress') +
                                '</td><td style="padding: 2px;">:</td><td class = "e-gantt-tooltip-value">' + editRecord.progress + '</td></tr>';
                            tooltipString = '<table class = "e-gantt-tooltiptable"><tbody>' +
                                progress + '</tbody></table>';
                            break;
                        }
                    case 'LeftResizing':
                        {
                            tooltipString = '<table class = "e-gantt-tooltiptable"><tbody>' +
                                startDate + duration + '</tbody></table>';
                            break;
                        }
                    case 'RightResizing':
                    case 'ParentResizing':
                        {
                            tooltipString = '<table class = "e-gantt-tooltiptable"><tbody>' +
                                endDate + duration + '</tbody></table>';
                            break;
                        }
                    case 'ChildDrag':
                    case 'ParentDrag':
                    case 'MilestoneDrag':
                    case 'ManualParentDrag':
                        {
                            var sDate = '';
                            var eDate = '';
                            Eif (!ej2_base_1.isNullOrUndefined(this.taskbarEdit.taskBarEditRecord.ganttProperties.startDate)) {
                                sDate = startDate;
                            }
                            Eif (!ej2_base_1.isNullOrUndefined(this.taskbarEdit.taskBarEditRecord.ganttProperties.endDate)) {
                                eDate = endDate;
                            }
                            tooltipString = '<table class = "e-gantt-tooltiptable"><tbody>' + sDate + eDate + '</tbody></table>';
                            break;
                        }
                    case 'ConnectorPointLeftDrag':
                    case 'ConnectorPointRightDrag':
                        {
                            tooltipString = this.parent.connectorLineModule.tooltipTable;
                            Iif (ej2_base_1.isNullOrUndefined(this.toolTipObj)) {
                                this.parent.connectorLineModule.tooltipTable.innerHTML =
                                    this.parent.connectorLineModule.getConnectorLineTooltipInnerTd(this.parent.editModule.taskbarEditModule.taskBarEditRecord.ganttProperties.taskName, this.parent.editModule.taskbarEditModule.fromPredecessorText, '', '');
                            }
                            break;
                        }
                }
            }
            if (typeof tooltipString === 'string') {
                var contentTemp = function () {
                    return tooltipString;
                };
                return ej2_base_1.initializeCSPTemplate(contentTemp);
            }
            else {
                return tooltipString;
            }
        };
        return EditTooltip;
    }());
    exports.EditTooltip = EditTooltip;
});