all files / actions/ context-menu.js

92.07% Statements 441/479
85.32% Branches 337/395
100% Functions 35/35
92.07% Lines 441/479
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776   370× 370× 370× 370×     370× 57× 57× 57×     52×     370× 370× 370× 370× 370× 370× 370×   370×     370× 370× 370× 370×         371×     371× 371× 371×                       371× 371×   66× 66× 66× 66× 66× 66× 66× 66× 66× 66×   66×         66×                 20× 17× 17× 17× 17× 15×   17× 10×   17× 16×   17×   17×   17× 17× 17×       20×     12× 11×           12×                                                                                                                                                                   65× 65×     65×     65× 64×   65× 65×   65× 65× 65× 65× 65×           65×     65×           65× 60× 60× 53×     60×   60× 60×   60× 704× 704× 668×     666×       60× 60× 60× 60× 60× 60×       60× 60× 60× 60× 60× 60×       60× 59×   60× 19×   60×       60×     666× 666× 666× 666×   666×           666×   59×   59×     59×   59×   59×     118× 118×   59× 13×   46×     43× 35×       43×   59×     59×     60× 60×     60× 44×   16× 16×   60×     59×   59×     59×   39× 36×             39×     39×       39× 39×   39× 39×     23×     39×       39×       39× 39×   39×   20×     39×       38× 38×   33×   38×     38× 33×       38×                                       202× 202× 179×     23×     59× 59× 59× 58×     371×   371× 5888× 5888× 5825×   63× 63×     63×     61×       371×   5868×           5868×   5871× 5871×   5825× 5825×         1476× 1476×   369× 369×   353× 353×   353× 353×   369× 369×   369× 369×   369× 369× 369× 369× 369× 344×   369× 369×   369× 369×   370× 370× 370× 370×   369× 369× 369× 369×   353× 353× 353× 353×   353× 353×   353× 353× 353×   5825× 4349×     3290×   60× 60× 60× 60× 60× 20× 20× 20× 20× 20× 20× 20×   60×   6241×           27962×   369× 365×     28× 28× 28×     28× 28× 28× 28× 28×   373× 373× 373× 373× 373×   5868×   736× 736× 673×     63×     370× 369× 369× 369× 369×        
define(["require", "exports", "./../base/css-constants", "@syncfusion/ej2-treegrid", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "@syncfusion/ej2-navigations"], function (require, exports, cons, ej2_treegrid_1, ej2_base_1, ej2_data_1, ej2_navigations_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ContextMenu = (function () {
        function ContextMenu(parent) {
            var _this = this;
            this.segmentIndex = -1;
            this.isCntxtMenuDependencyDelete = false;
            this.headerContextMenuClick = function (args) {
                var gridRow = ej2_base_1.closest(args.event.target, '.e-row');
                var chartRow = ej2_base_1.closest(args.event.target, '.e-chart-row');
                Eif (ej2_base_1.isNullOrUndefined(gridRow) && ej2_base_1.isNullOrUndefined(chartRow)) {
                    args.type = 'Header';
                    _this.parent.trigger('contextMenuClick', args);
                }
            };
            this.headerContextMenuOpen = function (args) {
                var gridRow = ej2_base_1.closest(args.event.target, '.e-row');
                var chartRow = ej2_base_1.closest(args.event.target, '.e-chart-row');
                if (ej2_base_1.isNullOrUndefined(gridRow) && ej2_base_1.isNullOrUndefined(chartRow)) {
                    args.type = 'Header';
                    _this.parent.trigger('contextMenuOpen', args);
                }
                else {
                    args.cancel = true;
                }
            };
            this.parent = parent;
            this.ganttID = parent.element.id;
            ej2_treegrid_1.TreeGrid.Inject(ej2_treegrid_1.ContextMenu);
            this.parent.treeGrid.contextMenuClick = this.headerContextMenuClick.bind(this);
            this.parent.treeGrid.contextMenuOpen = this.headerContextMenuOpen.bind(this);
            this.addEventListener();
            this.resetItems();
        }
        ContextMenu.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on('initiate-contextMenu', this.render, this);
            this.parent.on('reRender-contextMenu', this.reRenderContextMenu, this);
            this.parent.on('contextMenuClick', this.contextMenuItemClick, this);
            this.parent.on('contextMenuOpen', this.contextMenuBeforeOpen, this);
        };
        ContextMenu.prototype.reRenderContextMenu = function (e) {
            Eif (e.module === this.getModuleName() && e.enable) {
                if (this.contextMenu) {
                    this.contextMenu.destroy();
                    ej2_base_1.remove(this.element);
                }
                this.resetItems();
                this.render();
            }
        };
        ContextMenu.prototype.render = function () {
            this.element = this.parent.createElement('ul', {
                id: this.ganttID + '_contextmenu', className: cons.focusCell
            });
            this.parent.element.appendChild(this.element);
            var target = '#' + this.ganttID;
            this.contextMenu = new ej2_navigations_1.ContextMenu({
                items: this.getMenuItems(),
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                target: target,
                animationSettings: { effect: 'None' },
                select: this.contextMenuItemClick.bind(this),
                beforeOpen: this.contextMenuBeforeOpen.bind(this),
                onOpen: this.contextMenuOpen.bind(this),
                onClose: this.contextMenuOnClose.bind(this),
                cssClass: 'e-gantt'
            });
            this.contextMenu.appendTo(this.element);
            this.parent.treeGrid.contextMenuItems = this.headerMenuItems;
        };
        ContextMenu.prototype.contextMenuItemClick = function (args) {
            this.item = this.getKeyFromId(args.item.id);
            var position;
            var data;
            var taskfields;
            var parentItem = ej2_base_1.getValue('parentObj', args.item);
            var index = -1;
            args.type = 'Content';
            args.rowData = this.rowData;
            this.parent.trigger('contextMenuClick', args);
            if (parentItem && !ej2_base_1.isNullOrUndefined(parentItem.id) && this.getKeyFromId(parentItem.id) === 'DeleteDependency') {
                index = parentItem.items.indexOf(args.item);
            }
            if (this.parent.isAdaptive) {
                if (this.item === 'TaskInformation' || this.item === 'Above' || this.item === 'Below'
                    || this.item === 'Child' || this.item === 'DeleteTask') {
                    Eif (this.parent.selectionModule && this.parent.selectionSettings.type === 'Multiple') {
                        this.parent.selectionModule.hidePopUp();
                        document.getElementsByClassName('e-gridpopup')[0].style.display = 'none';
                    }
                }
            }
            switch (this.item) {
                case 'TaskInformation':
                    Eif (!ej2_base_1.isNullOrUndefined(this.rowData)) {
                        if (typeof this.rowData.ganttProperties.taskId === 'string') {
                            this.parent.openEditDialog(this.rowData.ganttProperties.rowUniqueID);
                        }
                        else {
                            this.parent.openEditDialog(Number(this.rowData.ganttProperties.rowUniqueID));
                        }
                    }
                    break;
                case 'Above':
                case 'Below':
                case 'Child':
                    if (!ej2_base_1.isNullOrUndefined(this.rowData)) {
                        position = this.item;
                        data = ej2_base_1.extend({}, {}, this.rowData.taskData, true);
                        taskfields = this.parent.taskFields;
                        if (data[taskfields.startDate]) {
                            this.parent.setRecordValue(taskfields.startDate, this.rowData.ganttProperties.startDate, data, true);
                        }
                        if (data[taskfields.endDate]) {
                            this.parent.setRecordValue(taskfields.endDate, this.rowData.ganttProperties.endDate, data, true);
                        }
                        if (!ej2_base_1.isNullOrUndefined(taskfields.dependency)) {
                            data[taskfields.dependency] = null;
                        }
                        if (!ej2_base_1.isNullOrUndefined(taskfields.child) && data[taskfields.child]) {
                            delete data[taskfields.child];
                        }
                        if (!ej2_base_1.isNullOrUndefined(taskfields.parentID) && data[taskfields.parentID]) {
                            data[taskfields.parentID] = null;
                        }
                        Eif (this.rowData) {
                            var rowIndex = this.parent.updatedRecords.indexOf(this.rowData);
                            this.parent.addRecord(data, position, rowIndex);
                        }
                    }
                    else if (this.parent.flatData.length === 0) {
                        this.parent.addRecord();
                    }
                    break;
                case 'Milestone':
                case 'ToMilestone':
                    if (!ej2_base_1.isNullOrUndefined(this.rowData)) {
                        this.parent.convertToMilestone(this.rowData.ganttProperties.rowUniqueID);
                    }
                    else Eif (this.parent.flatData.length === 0 && this.item === 'Milestone') {
                        var data_1 = this.parent.editModule.createNewRecord();
                        var taskSettings = this.parent.taskFields;
                        Eif (this.parent.taskFields['duration']) {
                            data_1[taskSettings['duration']] = 0;
                        }
                        Iif (this.parent.taskFields['milestone']) {
                            data_1[taskSettings['milestone']] = true;
                        }
                        this.parent.addRecord(data_1);
                    }
                    break;
                case 'DeleteTask':
                    if ((this.parent.selectionSettings.mode !== 'Cell' && this.parent.selectionModule.selectedRowIndexes.length > 1)
                        || (this.parent.selectionSettings.mode === 'Cell' && this.parent.selectionModule.getSelectedRowCellIndexes().length)) {
                        this.parent.editModule.startDeleteAction();
                    }
                    else {
                        this.parent.editModule.deleteRecord(this.rowData);
                    }
                    break;
                case 'ToTask':
                    Eif (!ej2_base_1.isNullOrUndefined(this.rowData)) {
                        data = ej2_base_1.extend({}, {}, this.rowData.taskData, true);
                        taskfields = this.parent.taskFields;
                        Eif (!ej2_base_1.isNullOrUndefined(taskfields.duration)) {
                            data[taskfields.duration] = parseInt(data[taskfields.duration], 10) <= 0 ? 1 : data[taskfields.duration];
                        }
                        else {
                            data[taskfields.startDate] = new Date(this.rowData.taskData[taskfields.startDate]);
                            var endDate = new Date(this.rowData.taskData[taskfields.startDate]);
                            endDate.setDate(endDate.getDate() + 1);
                            data[taskfields.endDate] = endDate;
                        }
                        if (!ej2_base_1.isNullOrUndefined(data[taskfields.milestone])) {
                            Eif (data[taskfields.milestone] === true) {
                                data[taskfields.milestone] = false;
                            }
                        }
                        if (data[taskfields.startDate]) {
                            this.parent.setRecordValue(taskfields.startDate, this.rowData.ganttProperties.startDate, data, true);
                        }
                        this.parent.updateRecordByID(data);
                    }
                    break;
                case 'Cancel':
                    this.parent.cancelEdit();
                    break;
                case 'Save':
                    this.parent.editModule.cellEditModule.isCellEdit = false;
                    this.parent.treeGrid.grid.saveCell();
                    break;
                case 'Dependency' + index:
                    this.isCntxtMenuDependencyDelete = true;
                    this.parent.connectorLineEditModule.removePredecessorByIndex(this.rowData, index);
                    break;
                case 'Auto':
                case 'Manual':
                    this.parent.changeTaskMode(this.rowData);
                    break;
                case 'Indent':
                    this.parent.indent();
                    break;
                case 'Outdent':
                    this.parent.outdent();
                    break;
                case 'Left':
                case 'Right':
                    this.mergeCall(this.item);
                    break;
                case 'SplitTask':
                    this.splitTaskCall(args);
                    break;
            }
        };
        ContextMenu.prototype.splitTaskCall = function (args) {
            var _this = this;
            this.isEdit = true;
            var taskSettings = this.parent.taskFields;
            var currentClickedDate = this.getClickedDate(args.element);
            Iif (ej2_base_1.isNullOrUndefined(this.parent.timelineSettings.bottomTier) && this.parent.timelineSettings.bottomTier.unit !== 'Hour') {
                currentClickedDate.setHours(0, 0, 0, 0);
            }
            var eventArgs = {
                rowData: this.rowData,
                requestType: 'splitTaskbar',
                splitDate: currentClickedDate,
                cancel: false,
                target: this.targetElement
            };
            this.parent.trigger('actionBegin', eventArgs, function (eventArgs) {
                Iif (!ej2_base_1.isNullOrUndefined(_this.parent.loadingIndicator) && _this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                    _this.parent.showMaskRow();
                }
                else {
                    _this.parent.showSpinner();
                }
                _this.parent.chartRowsModule.splitTask(_this.rowData[taskSettings.id], currentClickedDate);
                _this.parent.chartRowsModule.updateSegment(_this.rowData.ganttProperties.segments, _this.rowData.ganttProperties.taskId);
            });
        };
        ContextMenu.prototype.mergeCall = function (item) {
            var _this = this;
            this.isEdit = true;
            var taskSettings = this.parent.taskFields;
            var segments = this.rowData.ganttProperties.segments;
            var firstSegment = item === 'Right' ? this.segmentIndex : segments[this.segmentIndex - 1].segmentIndex;
            var secondSegment = item === 'Left' ? this.segmentIndex : segments[this.segmentIndex + 1].segmentIndex;
            var segmentIndexes = [
                { 'firstSegmentIndex': firstSegment, 'secondSegmentIndex': secondSegment }
            ];
            var eventArgs = {
                rowData: this.rowData,
                mergeSegmentIndexes: segmentIndexes,
                requestType: 'mergeSegment',
                cancel: false,
                target: this.targetElement
            };
            this.parent.trigger('actionBegin', eventArgs, function (eventArgs) {
                Iif (!ej2_base_1.isNullOrUndefined(_this.parent.loadingIndicator) && _this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                    _this.parent.showMaskRow();
                }
                else {
                    _this.parent.showSpinner();
                }
                Eif (eventArgs.cancel === false) {
                    _this.parent.chartRowsModule.mergeTask(_this.rowData[taskSettings.id], segmentIndexes);
                }
            });
        };
        ContextMenu.prototype.getClickedDate = function (element) {
            var ganttElementPositionLeft;
            if (this.parent.enableRtl) {
                var box = this.parent.element.getBoundingClientRect();
                var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft ||
                    document.body.scrollLeft;
                var clientLeft = document.documentElement.clientLeft || document.body.clientLeft || 0;
                ganttElementPositionLeft = box.left + scrollLeft - clientLeft;
            }
            else {
                ganttElementPositionLeft = this.parent.getOffsetRect(this.parent.element).left;
            }
            var pageLeft;
            var currentTaskDifference;
            if (this.parent.enableRtl) {
                pageLeft = Math.abs(ganttElementPositionLeft + this.parent.ganttChartModule.chartElement.offsetWidth -
                    this.rowData.ganttProperties.left - this.parent.ganttChartModule.scrollElement.scrollLeft);
                currentTaskDifference = Math.abs(this.clickedPosition - pageLeft);
            }
            else {
                pageLeft = ganttElementPositionLeft + this.parent.ganttChartModule.chartElement.offsetLeft +
                    this.rowData.ganttProperties.left - this.parent.ganttChartModule.scrollElement.scrollLeft;
                currentTaskDifference = this.clickedPosition - pageLeft;
            }
            var splitTaskDuration = Math.ceil(currentTaskDifference / this.parent.perDayWidth);
            var startDate = this.rowData.ganttProperties.startDate;
            Iif (!ej2_base_1.isNullOrUndefined(this.parent.timelineSettings.bottomTier) && this.parent.timelineSettings.bottomTier.unit === 'Hour') {
                splitTaskDuration = Math.ceil(currentTaskDifference / this.parent.timelineSettings.timelineUnitSize);
                splitTaskDuration -= 1;
            }
            var contextMenuClickDate;
            Iif (!ej2_base_1.isNullOrUndefined(this.parent.timelineSettings.bottomTier) && (this.parent.timelineSettings.bottomTier.unit === 'Minutes' || this.parent.timelineSettings.bottomTier.unit === 'Hour')) {
                splitTaskDuration = Math.ceil(currentTaskDifference / this.parent.timelineSettings.timelineUnitSize);
                splitTaskDuration -= 1;
                contextMenuClickDate = this.parent.dataOperation.getEndDate(startDate, splitTaskDuration, this.parent.timelineSettings.bottomTier.unit.toLocaleLowerCase(), this.rowData, false);
            }
            else {
                contextMenuClickDate =
                    this.parent.dataOperation.getEndDate(startDate, splitTaskDuration, this.rowData.ganttProperties.duration > 1 ?
                        this.rowData.ganttProperties.durationUnit : (this.parent.timelineSettings.bottomTier.unit !== 'None') ?
                        this.parent.timelineSettings.bottomTier.unit.toLocaleLowerCase() :
                        this.parent.timelineSettings.topTier.unit.toLocaleLowerCase(), this.rowData, false);
            }
            return contextMenuClickDate;
        };
        ContextMenu.prototype.contextMenuBeforeOpen = function (args) {
            var _this = this;
            var target = args.event ? args.event.target :
                !this.parent.focusModule ? this.parent.focusModule.getActiveElement() :
                    this.parent.ganttChartModule.targetElement;
            Iif ((!ej2_base_1.isNullOrUndefined(this.parent.editModule) && this.parent.editModule.cellEditModule && this.parent.editModule.cellEditModule.isCellEdit && target.parentElement.classList.contains('e-row')) || target.parentElement.classList.contains('e-treecolumn-container')) {
                this.parent.treeGrid.closeEdit();
            }
            if (!ej2_base_1.isNullOrUndefined(args.element) && args.element.id === this.parent.element.id + '_contextmenu') {
                this.clickedPosition = ej2_base_1.getValue('event', args).clientX;
            }
            var targetElement = ej2_base_1.closest(target, '.e-gantt-child-taskbar');
            if (targetElement) {
                this.targetElement = args.target = targetElement;
            }
            args.gridRow = ej2_base_1.closest(target, '.e-row');
            args.chartRow = ej2_base_1.closest(target, '.e-chart-row');
            var menuElement = ej2_base_1.closest(target, '.e-gantt');
            var editForm = ej2_base_1.closest(target, cons.editForm);
            Iif (!editForm && this.parent.editModule && this.parent.editModule.cellEditModule
                && this.parent.editModule.cellEditModule.isCellEdit && this.parent.editModule.dialogModule.dialogObj
                && !this.parent.editModule.dialogModule.dialogObj.open) {
                this.parent.treeGrid.grid.saveCell();
                this.parent.editModule.cellEditModule.isCellEdit = false;
            }
            Iif (this.parent.readOnly) {
                this.contextMenu.enableItems(['Add', 'Save', 'Convert', 'Delete Dependency', 'Delete Task', 'TaskMode', 'Indent', 'Outdent', 'SplitTask', 'MergeTask'], false);
            }
            if ((ej2_base_1.isNullOrUndefined(args.gridRow) && ej2_base_1.isNullOrUndefined(args.chartRow)) || this.contentMenuItems.length === 0) {
                Iif (!ej2_base_1.isNullOrUndefined(args.parentItem) && !ej2_base_1.isNullOrUndefined(menuElement) || !ej2_base_1.isNullOrUndefined(ej2_base_1.closest(target, '.e-content'))) {
                    args.cancel = false;
                }
                else {
                    args.cancel = true;
                }
            }
            if (!args.cancel) {
                var rowIndex = -1;
                if (args.gridRow) {
                    rowIndex = parseInt(args.gridRow.getAttribute('data-rowindex'), 0);
                }
                else Eif (args.chartRow) {
                    rowIndex = parseInt(args.chartRow.getAttribute('data-rowindex'), 0);
                }
                if (this.parent.selectionModule && this.parent.allowSelection && !args.parentItem && !ej2_base_1.isNullOrUndefined(args.chartRow)) {
                    this.parent.selectionModule.selectRow(rowIndex);
                }
                Eif (!args.parentItem) {
                    this.rowData = this.parent.updatedRecords[parseInt(rowIndex.toString(), 10)];
                }
                for (var _i = 0, _a = args.items; _i < _a.length; _i++) {
                    var item = _a[_i];
                    if (!item.separator) {
                        if ((target.classList.contains('e-gantt-unscheduled-taskbar')) && ((item.text === this.getLocale('splitTask')) || (item.text === this.getLocale('mergeTask')))) {
                            this.hideItems.push(item.text);
                        }
                        else {
                            this.updateItemStatus(item, target, rowIndex);
                        }
                    }
                }
                args.rowData = this.rowData;
                args.type = 'Content';
                args.disableItems = this.disableItems;
                args.hideItems = this.hideItems;
                args.hideChildItems = [];
                Iif (!ej2_base_1.isNullOrUndefined(args.rowData) && args.rowData.level === 0 && this.parent.viewType === 'ResourceView') {
                    args.cancel = true;
                    return;
                }
                var callBackPromise_1 = new ej2_data_1.Deferred();
                this.parent.trigger('contextMenuOpen', args, function (arg) {
                    callBackPromise_1.resolve(arg);
                    _this.hideItems = arg.hideItems;
                    _this.disableItems = arg.disableItems;
                    Iif (!arg.parentItem && arg.hideItems.length === arg.items.length) {
                        _this.revertItemStatus();
                        arg.cancel = true;
                    }
                    if (_this.hideItems.length > 0) {
                        _this.contextMenu.hideItems(_this.hideItems);
                    }
                    if (_this.disableItems.length > 0) {
                        _this.contextMenu.enableItems(_this.disableItems, false);
                    }
                    Iif (args.hideChildItems.length > 0) {
                        _this.contextMenu.hideItems(args.hideChildItems);
                    }
                });
                return callBackPromise_1;
            }
        };
        ContextMenu.prototype.updateItemStatus = function (item, target, rowIndex) {
            var key = this.getKeyFromId(item.id);
            var editForm = ej2_base_1.closest(target, cons.editForm);
            var subMenu = [];
            var taskbarElement = ej2_base_1.closest(target, '.e-gantt-child-taskbar') ||
                ej2_base_1.closest(target, 'e-taskbar-right-resizer') || ej2_base_1.closest(target, 'e-taskbar-left-resizer');
            Iif (editForm) {
                if (!(key === 'Save' || key === 'Cancel')) {
                    this.hideItems.push(item.text);
                }
            }
            else {
                switch (key) {
                    case 'TaskInformation':
                        if (!this.parent.editSettings.allowEditing || !this.parent.editModule) {
                            this.updateItemVisibility(item.text);
                        }
                        Iif (this.parent.flatData.length === 0) {
                            this.hideItems.push(item.text);
                        }
                        break;
                    case 'Add':
                        if (!this.parent.editSettings.allowAdding || !this.parent.editModule) {
                            this.updateItemVisibility(item.text);
                        }
                        break;
                    case 'Save':
                    case 'Cancel':
                        this.hideItems.push(item.text);
                        break;
                    case 'Convert':
                        if (!ej2_base_1.isNullOrUndefined(this.rowData) && this.rowData.hasChildRecords) {
                            this.hideItems.push(item.text);
                        }
                        else if (!this.parent.editSettings.allowEditing || !this.parent.editModule) {
                            this.updateItemVisibility(item.text);
                        }
                        else {
                            if (!ej2_base_1.isNullOrUndefined(this.rowData) && !this.rowData.ganttProperties.isMilestone) {
                                subMenu.push(this.createItemModel(cons.content, 'ToMilestone', this.getLocale('toMilestone')));
                            }
                            else {
                                subMenu.push(this.createItemModel(cons.content, 'ToTask', this.getLocale('toTask')));
                            }
                            item.items = subMenu;
                        }
                        Iif (this.parent.flatData.length === 0) {
                            this.hideItems.push(item.text);
                        }
                        break;
                    case 'DeleteDependency':
                        {
                            var items = this.getPredecessorsItems();
                            Iif (!ej2_base_1.isNullOrUndefined(this.rowData) && this.rowData.hasChildRecords && !this.parent.allowParentDependency) {
                                this.hideItems.push(item.text);
                            }
                            else if (!this.parent.editSettings.allowDeleting || items.length === 0 || !this.parent.editModule) {
                                this.updateItemVisibility(item.text);
                            }
                            else Eif (items.length > 0) {
                                item.items = items;
                            }
                            break;
                        }
                    case 'DeleteTask':
                        if (!this.parent.editSettings.allowDeleting || !this.parent.editModule) {
                            this.updateItemVisibility(item.text);
                        }
                        Iif (this.parent.flatData.length === 0) {
                            this.hideItems.push(item.text);
                        }
                        break;
                    case 'TaskMode':
                        if (this.parent.taskMode !== 'Custom') {
                            this.updateItemVisibility(item.text);
                        }
                        else {
                            if (this.rowData.ganttProperties.isAutoSchedule) {
                                subMenu.push(this.createItemModel(cons.content, 'Manual', this.getLocale('manual')));
                            }
                            else {
                                subMenu.push(this.createItemModel(cons.content, 'Auto', this.getLocale('auto')));
                            }
                            item.items = subMenu;
                        }
                        break;
                    case 'Indent':
                        {
                            Iif (!this.parent.allowSelection || !this.parent.editModule || !this.parent.editSettings) {
                                this.hideItems.push(item.text);
                            }
                            else {
                                var index = this.parent.selectedRowIndex;
                                var isSelected = this.parent.selectionModule ? this.parent.selectionModule.selectedRowIndexes.length === 1 ||
                                    this.parent.selectionModule.getSelectedRowCellIndexes().length === 1 ? true : false : false;
                                var prevRecord = this.parent.updatedRecords[this.parent.selectionModule.getSelectedRowIndexes()[0] - 1];
                                if (!this.parent.editSettings.allowEditing || index === 0 || index === -1 || !isSelected ||
                                    this.parent.viewType === 'ResourceView' ||
                                    this.parent.updatedRecords[parseInt(index.toString(), 10)].level - prevRecord.level === 1) {
                                    this.updateItemVisibility(item.text);
                                }
                            }
                            break;
                        }
                    case 'Outdent':
                        {
                            Iif (!this.parent.allowSelection || !this.parent.editModule || !this.parent.editSettings) {
                                this.hideItems.push(item.text);
                            }
                            else {
                                var ind = this.parent.selectionModule.getSelectedRowIndexes()[0];
                                var isSelect = this.parent.selectionModule ? this.parent.selectionModule.selectedRowIndexes.length === 1 ||
                                    this.parent.selectionModule.getSelectedRowCellIndexes().length === 1 ? true : false : false;
                                if (!this.parent.editSettings.allowEditing || ind === -1 || ind === 0 || !isSelect ||
                                    this.parent.viewType === 'ResourceView' || this.parent.updatedRecords[parseInt(ind.toString(), 10)].level === 0) {
                                    this.updateItemVisibility(item.text);
                                }
                            }
                            break;
                        }
                    case 'SplitTask':
                        {
                            var taskSettings = this.parent.taskFields;
                            if (this.parent.readOnly || !taskbarElement || ej2_base_1.isNullOrUndefined(taskSettings.segments) ||
                                this.parent.currentViewData[parseInt(rowIndex.toString(), 10)].hasChildRecords) {
                                this.updateItemVisibility(item.text);
                            }
                            break;
                        }
                    case 'MergeTask':
                        if (this.parent.readOnly || !taskbarElement) {
                            this.updateItemVisibility(item.text);
                        }
                        else {
                            this.mergeItemVisiblity(target, item);
                        }
                        break;
                }
            }
        };
        ContextMenu.prototype.mergeItemVisiblity = function (target, item) {
            var subMenu = [];
            var taskfields = this.parent.taskFields;
            var currentClickedDate = this.getClickedDate(target);
            this.segmentIndex = this.parent.chartRowsModule.getSegmentIndex(currentClickedDate, this.rowData);
            var segments = this.rowData.ganttProperties.segments;
            if (!ej2_base_1.isNullOrUndefined(segments) && segments.length > 0) {
                Iif (ej2_base_1.isNullOrUndefined(taskfields.segments) && this.segmentIndex === -1) {
                    this.updateItemVisibility(item.text);
                }
                else {
                    Eif (this.segmentIndex === 0) {
                        subMenu.push(this.createItemModel(cons.content, 'Right', this.getLocale('right')));
                    }
                    else if (this.segmentIndex === segments.length - 1) {
                        subMenu.push(this.createItemModel(cons.content, 'Left', this.getLocale('left')));
                    }
                    else {
                        subMenu.push(this.createItemModel(cons.content, 'Right', this.getLocale('right')));
                        subMenu.push(this.createItemModel(cons.content, 'Left', this.getLocale('left')));
                    }
                    item.items = subMenu;
                }
            }
            else {
                this.hideItems.push(item.text);
            }
        };
        ContextMenu.prototype.updateItemVisibility = function (text) {
            var isDefaultItem = !ej2_base_1.isNullOrUndefined(this.parent.contextMenuItems) ? false : true;
            if (isDefaultItem) {
                this.hideItems.push(text);
            }
            else {
                this.disableItems.push(text);
            }
        };
        ContextMenu.prototype.contextMenuOpen = function (args) {
            this.isOpen = true;
            var firstMenuItem = this.parent['args'] = args.element.querySelectorAll('li:not(.e-menu-hide):not(.e-disabled)')[0];
            if (!ej2_base_1.isNullOrUndefined(firstMenuItem)) {
                ej2_base_1.addClass([firstMenuItem], 'e-focused');
            }
        };
        ContextMenu.prototype.getMenuItems = function () {
            var menuItems = !ej2_base_1.isNullOrUndefined(this.parent.contextMenuItems) ?
                this.parent.contextMenuItems : this.getDefaultItems();
            for (var _i = 0, menuItems_1 = menuItems; _i < menuItems_1.length; _i++) {
                var item = menuItems_1[_i];
                if (typeof item === 'string' && this.getDefaultItems().indexOf(item) !== -1) {
                    this.buildDefaultItems(item);
                }
                else Eif (typeof item !== 'string') {
                    Iif (this.getDefaultItems().indexOf(item.text) !== -1) {
                        this.buildDefaultItems(item.text, item.iconCss);
                    }
                    else if (item.target === cons.columnHeader) {
                        this.headerMenuItems.push(item);
                    }
                    else {
                        this.contentMenuItems.push(item);
                    }
                }
            }
            return this.contentMenuItems;
        };
        ContextMenu.prototype.createItemModel = function (target, item, text, iconCss) {
            var itemModel = {
                text: text,
                id: this.generateID(item),
                target: target,
                iconCss: iconCss ? 'e-icons ' + iconCss : null
            };
            return itemModel;
        };
        ContextMenu.prototype.getLocale = function (text) {
            var localeText = this.parent.localeObj.getConstant(text);
            return localeText;
        };
        ContextMenu.prototype.buildDefaultItems = function (item, iconCSS) {
            var contentMenuItem;
            switch (item) {
                case 'AutoFitAll':
                case 'AutoFit':
                case 'SortAscending':
                case 'SortDescending':
                    this.headerMenuItems.push(item);
                    break;
                case 'TaskInformation':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('taskInformation'), this.getIconCSS(cons.editIcon, iconCSS));
                    break;
                case 'Indent':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('indent'), this.getIconCSS(cons.indentIcon, iconCSS));
                    break;
                case 'Outdent':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('outdent'), this.getIconCSS(cons.outdentIcon, iconCSS));
                    break;
                case 'Save':
                    contentMenuItem = this.createItemModel(cons.editIcon, item, this.getLocale('save'), this.getIconCSS(cons.saveIcon, iconCSS));
                    break;
                case 'Cancel':
                    contentMenuItem = this.createItemModel(cons.editIcon, item, this.getLocale('cancel'), this.getIconCSS(cons.cancelIcon, iconCSS));
                    break;
                case 'Add':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('add'), this.getIconCSS(cons.addIcon, iconCSS));
                    contentMenuItem.items = [];
                    contentMenuItem.items.push(this.createItemModel(cons.content, 'Above', this.getLocale('above'), this.getIconCSS(cons.addAboveIcon, iconCSS)));
                    contentMenuItem.items.push(this.createItemModel(cons.content, 'Below', this.getLocale('below'), this.getIconCSS(cons.addBelowIcon, iconCSS)));
                    if (this.parent.viewType !== 'ResourceView') {
                        contentMenuItem.items.push(this.createItemModel(cons.content, 'Child', this.getLocale('child')));
                    }
                    contentMenuItem.items.push(this.createItemModel(cons.content, 'Milestone', this.getLocale('milestone')));
                    break;
                case 'DeleteTask':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('deleteTask'), this.getIconCSS(cons.deleteIcon, iconCSS));
                    break;
                case 'DeleteDependency':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('deleteDependency'));
                    contentMenuItem.items = [];
                    contentMenuItem.items.push({});
                    break;
                case 'Convert':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('convert'));
                    contentMenuItem.items = [];
                    contentMenuItem.items.push({});
                    break;
                case 'TaskMode':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('changeScheduleMode'));
                    contentMenuItem.items = [];
                    contentMenuItem.items.push({});
                    break;
                case 'SplitTask':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('splitTask'));
                    break;
                case 'MergeTask':
                    contentMenuItem = this.createItemModel(cons.content, item, this.getLocale('mergeTask'));
                    contentMenuItem.items = [];
                    contentMenuItem.items.push({});
            }
            if (contentMenuItem) {
                this.contentMenuItems.push(contentMenuItem);
            }
        };
        ContextMenu.prototype.getIconCSS = function (menuClass, iconString) {
            return ej2_base_1.isNullOrUndefined(iconString) ? menuClass : iconString;
        };
        ContextMenu.prototype.getPredecessorsItems = function () {
            this.predecessors = this.parent.predecessorModule.getValidPredecessor(this.rowData);
            var items = [];
            var itemModel;
            var increment = 0;
            for (var _i = 0, _a = this.predecessors; _i < _a.length; _i++) {
                var predecessor = _a[_i];
                var ganttData = this.parent.getRecordByID(predecessor.from);
                var ganttProp = ganttData.ganttProperties;
                var text = ganttProp.rowUniqueID + ' - ' + ganttProp.taskName;
                var id = 'Dependency' + increment++;
                itemModel = this.createItemModel(cons.content, id, text);
                items.push(itemModel);
            }
            return items;
        };
        ContextMenu.prototype.getDefaultItems = function () {
            return ['AutoFitAll', 'AutoFit',
                'TaskInformation', 'DeleteTask', 'Save', 'Cancel',
                'SortAscending', 'SortDescending', 'Add',
                'DeleteDependency', 'Convert', 'TaskMode', 'Indent', 'Outdent', 'SplitTask', 'MergeTask'
            ];
        };
        ContextMenu.prototype.getModuleName = function () {
            return 'contextMenu';
        };
        ContextMenu.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off('initiate-contextMenu', this.render);
            this.parent.off('reRender-contextMenu', this.reRenderContextMenu);
            this.parent.off('contextMenuClick', this.contextMenuItemClick);
            this.parent.off('contextMenuOpen', this.contextMenuOpen);
        };
        ContextMenu.prototype.contextMenuOnClose = function (args) {
            var parent = 'parentObj';
            Eif (args.items.length > 0 && args.items[0]["" + parent] instanceof ej2_navigations_1.ContextMenu) {
                this.revertItemStatus();
            }
        };
        ContextMenu.prototype.revertItemStatus = function () {
            this.contextMenu.showItems(this.hideItems);
            this.contextMenu.enableItems(this.disableItems);
            this.hideItems = [];
            this.disableItems = [];
            this.isOpen = false;
        };
        ContextMenu.prototype.resetItems = function () {
            this.hideItems = [];
            this.disableItems = [];
            this.headerMenuItems = [];
            this.contentMenuItems = [];
            this.item = null;
        };
        ContextMenu.prototype.generateID = function (item) {
            return this.ganttID + '_contextMenu_' + item;
        };
        ContextMenu.prototype.getKeyFromId = function (id) {
            var idPrefix = this.ganttID + '_contextMenu_';
            if (id.indexOf(idPrefix) > -1) {
                return id.replace(idPrefix, '');
            }
            else {
                return 'Custom';
            }
        };
        ContextMenu.prototype.destroy = function () {
            this.contextMenu.destroy();
            ej2_base_1.remove(this.element);
            this.removeEventListener();
            this.contextMenu = null;
            this.element = null;
        };
        return ContextMenu;
    }());
    exports.ContextMenu = ContextMenu;
});