all files / actions/ rowdragdrop.js

93.19% Statements 643/690
85.27% Branches 434/509
100% Functions 42/42
93.19% Lines 643/690
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 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023   286× 286× 286× 286× 286× 286× 286× 286× 286× 286×   27959×     286× 286× 286× 286×                                                                                                                           53× 53× 53× 53× 53× 53× 30× 25×   25×         25×   25× 25× 28× 470×     25× 25× 28×   25× 25× 25×       25×   25× 25× 25× 25× 25× 10×   15×     25× 25× 25×   30× 30×     53× 53× 53× 53×       53×   53× 53× 53× 56× 56× 56× 56× 56× 19× 19× 14×     56×   55× 55×   55× 55× 18×   55× 14× 14× 11×   11× 11× 11×             14× 14× 14× 14×   14× 10× 10× 10× 10×       55× 23× 23× 23× 23×     55× 55× 974× 974× 756× 756×       55× 49×     55× 53× 53× 53× 53× 53× 53× 18× 18× 40× 636×   40× 15× 15×     18× 40× 40× 15×       35× 35× 90× 1301×   90× 20× 20×     35× 90× 90× 20×     53× 241× 241× 241× 176× 3011×   176×       53× 241×     55×   53× 53× 56× 56×   52× 23× 16× 16× 21× 18× 18× 18× 18×                 23×         52× 16× 16×     11×     16× 16× 16× 16× 16× 16× 16× 16×   16×     15×   16× 16×     15×     52× 47× 47× 47× 47× 41×       47× 38×       47× 47×   41× 689× 413× 413×           276×   41× 41×             143×               52× 130×   52×           52× 52×   52× 52×   52× 28×     52×   18× 18× 18× 18× 18× 18×   18×             16× 16× 12× 13×   11× 11×         15× 259× 19× 19× 19×   18×         19×                       55× 55× 55× 55× 55× 55× 55×       55×   55× 39×     38×                 46× 39× 21× 21× 21× 21×     55× 11× 10×   10× 10× 10×             55×         23× 23× 23×     23× 23×   23× 23× 23×   23×   23× 23×           23× 23× 23× 23× 23× 20× 20× 20× 20× 15×       23× 23× 23× 23×             23× 23× 23× 23×   18×   23× 17×       23×     55×   55×       55×     55× 55×                   50×   55×   19× 19× 19× 19× 19× 19× 39×     19×     18× 18× 18×   18× 18× 18× 18× 18× 18×   18×   18× 16× 16× 16× 16×   18× 16×       11× 11× 11× 11×     11× 11× 24× 24× 24× 22× 22×   24× 24× 24×         11×   11× 11× 11× 11×     11× 11× 24× 24× 24× 24× 24×   24×       11×   56× 56× 56×       56×   56× 56× 56× 55× 45× 45× 45×   45× 45× 45×   45× 45× 45× 36×   45×     55× 44× 44× 44× 42×     55× 11×   11× 11×   11× 99× 44×       55×       11× 11× 11×   11× 11× 11× 11×   11×       55× 55× 44× 44× 44× 44× 44×       44× 13×     55× 12× 12×               45×                   53× 53× 51× 13×   51× 15×   51× 23×   51× 51× 30×   51× 51× 54×     49×     51× 51×         51×                
define(["require", "exports", "@syncfusion/ej2-treegrid", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../base/common"], function (require, exports, ej2_treegrid_1, ej2_base_1, ej2_data_1, common_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RowDD = (function () {
        function RowDD(gantt) {
            this.isTest = false;
            this.updateParentRecords = [];
            this.isaddtoBottom = false;
            this.updateCollection = {};
            this.isSharedTask = false;
            this.canDrop = true;
            this.parent = gantt;
            ej2_treegrid_1.TreeGrid.Inject(ej2_treegrid_1.RowDD);
            this.parent.treeGrid.allowRowDragAndDrop = this.parent.allowRowDragAndDrop;
            this.bindEvents();
        }
        RowDD.prototype.getModuleName = function () {
            return 'rowDragAndDrop';
        };
        RowDD.prototype.destroy = function () {
        };
        RowDD.prototype.bindEvents = function () {
            this.parent.treeGrid.rowDragStart = this.rowDragStart.bind(this);
            this.parent.treeGrid.rowDragStartHelper = this.rowDragStartHelper.bind(this);
            this.parent.treeGrid.rowDrag = this.rowDrag.bind(this);
            this.parent.treeGrid.rowDrop = this.rowDrop.bind(this);
        };
        RowDD.prototype.rowDragStart = function (args) {
            this.parent.trigger('rowDragStart', args);
            this.parent.element.style.position = 'relative';
        };
        RowDD.prototype.addErrorElem = function () {
            var dragelem = document.getElementsByClassName('e-ganttdrag')[0];
            var errorelem = dragelem.querySelectorAll('.e-errorelem').length;
            Iif (!errorelem) {
                var ele = document.createElement('div');
                ej2_base_1.classList(ele, ['e-errorcontainer'], []);
                ej2_base_1.classList(ele, ['e-icons', 'e-errorelem'], []);
                var errorVal = dragelem.querySelector('.errorValue');
                var content = dragelem.querySelector('.e-rowcell').innerHTML;
                if (errorVal) {
                    content = errorVal.innerHTML;
                    errorVal.parentNode.removeChild(errorVal);
                }
                dragelem.querySelector('.e-rowcell').innerHTML = '';
                var spanContent = document.createElement('span');
                spanContent.className = 'errorValue';
                spanContent.style.paddingLeft = '16px';
                spanContent.innerHTML = content;
                dragelem.querySelector('.e-rowcell').appendChild(ele);
                dragelem.querySelector('.e-rowcell').appendChild(spanContent);
            }
        };
        RowDD.prototype.removeErrorElem = function () {
            var errorelem = document.querySelector('.e-errorelem');
            Iif (errorelem) {
                errorelem.remove();
            }
        };
        RowDD.prototype.rowDrag = function (args) {
            var cloneElement = this.parent.element.querySelector('.e-cloneproperties');
            cloneElement.style.display = 'none';
            var ganttDragElement = cloneElement.cloneNode(true);
            ganttDragElement.classList.add('e-ganttdrag');
            ganttDragElement.style.display = '';
            Eif (this.parent.element.querySelectorAll('.e-cloneproperties').length <= 1) {
                this.parent.element.appendChild(ganttDragElement);
            }
            else {
                if (document.getElementsByClassName('e-cloneproperties')[0].querySelectorAll('.e-errorelem').length) {
                    this.addErrorElem();
                }
                else {
                    this.removeErrorElem();
                }
            }
            if (this.parent.gridLines === 'Both') {
                ej2_base_1.addClass(this.parent.element.querySelectorAll('.e-ganttdrag .e-rowcell'), ['e-bothganttlines']);
            }
            var dragElement = this.parent.element.querySelector('.e-ganttdrag');
            var ganttTop = this.parent.element.getClientRects()[0].top;
            var ganttLeft = this.parent.element.getClientRects()[0].left;
            var left;
            var top;
            Iif (this.parent.isAdaptive) {
                left = args.originalEvent.event.touches[0].clientX - ganttLeft;
                top = args.originalEvent.event.touches[0].clientY - ganttTop;
            }
            else {
                left = ej2_base_1.getValue('event', args.originalEvent).clientX - ganttLeft;
                top = ej2_base_1.getValue('event', args.originalEvent).clientY - ganttTop;
            }
            dragElement.style.left = left + 20 + 'px';
            dragElement.style.top = top + 20 + 'px';
            this.parent.trigger('rowDrag', args);
        };
        RowDD.prototype.rowDragStartHelper = function (args) {
            this.parent.trigger('rowDragStartHelper', args);
            Iif (this.parent.readOnly) {
                args.cancel = true;
            }
            Iif (this.parent.viewType === 'ResourceView' && ej2_base_1.getValue('level', args.data[0]) === 0) {
                args.cancel = true;
            }
        };
        RowDD.prototype.rowDrop = function (args) {
            var gridRow = ej2_base_1.closest(args.target, '.e-row');
            this.parent['oldRecords'] = ej2_base_1.extend([], [], args.data, true);
            var dropIndex = gridRow ? parseInt(gridRow.getAttribute('data-rowindex'), 10) : args.dropIndex;
            args.dropIndex = dropIndex;
            args.dropRecord = this.parent.updatedRecords[args.dropIndex];
            this.parent.trigger('rowDrop', args);
            Iif (this.parent.viewType === 'ResourceView') {
                if (args.dropPosition === 'middleSegment') {
                    if (args.dropRecord.level === 1 || args.dropRecord.uniqueID === ej2_base_1.getValue('parentItem', args.data[0]).uniqueID) {
                        args.cancel = true;
                    }
                }
                if (args.dropPosition !== 'middleSegment') {
                    if (args.dropRecord.level === 0 || ej2_base_1.getValue('parentItem', args.data[0]).uniqueID === args.dropRecord.parentItem.uniqueID) {
                        args.cancel = true;
                    }
                }
            }
            Eif (!args.cancel) {
                args.requestType = 'beforeDrop';
                this.parent.trigger('actionBegin', args);
                if (!ej2_base_1.isNullOrUndefined(this.parent.loadingIndicator) && this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                    this.parent.showMaskRow();
                }
                else {
                    this.parent.showSpinner();
                }
                Eif (!args.cancel) {
                    this.dropRows(args, true);
                    args.cancel = true;
                }
            }
        };
        RowDD.prototype.dropRows = function (args, isByMethod) {
            Eif (!this.parent.readOnly) {
                this.dropPosition = args.dropPosition;
                Eif (args.dropPosition !== 'Invalid' && this.parent.editModule) {
                    var gObj = this.parent;
                    this.droppedRecord = gObj.updatedRecords[args.dropIndex];
                    if (this.parent.undoRedoModule && (this.parent['isUndoRedoItemPresent']('RowDragAndDrop'))) {
                        if (!this.parent.undoRedoModule['isUndoRedoPerformed']) {
                            if (this.parent.undoRedoModule['redoEnabled']) {
                                this.parent.undoRedoModule['disableRedo']();
                                this.parent.undoRedoModule['createUndoCollection']();
                            }
                            Iif (!args.target && this.parent.editModule && this.parent.editModule.taskbarEditModule &&
                                this.parent.editModule.taskbarEditModule.taskBarEditAction) {
                                this.parent.undoRedoModule['getUndoCollection'][this.parent.undoRedoModule['getUndoCollection'].length - 1] = [];
                            }
                            else {
                                this.parent.undoRedoModule['createUndoCollection']();
                            }
                            var datas = [];
                            var _loop_1 = function (i) {
                                datas.push(this_1.parent.flatData.filter(function (data) {
                                    return args.data[i]['ganttProperties'].taskId === data.ganttProperties.taskId;
                                })[0]);
                            };
                            var this_1 = this;
                            for (var i = 0; i < args.data.length; i++) {
                                _loop_1(i);
                            }
                            var rowItems = ej2_base_1.extend([], [], datas, true);
                            var records = {};
                            Iif (args['name']) {
                                records['action'] = 'RowDragAndDrop';
                            }
                            else {
                                records['action'] = 'TaskbarDragAndDrop';
                            }
                            records['beforeDrop'] = [];
                            var previousDetails = {};
                            previousDetails['dropRecord'] = ej2_base_1.extend([], [], [args.dropRecord ? args.dropRecord : this.droppedRecord], true)[0];
                            previousDetails['data'] = ej2_base_1.extend([], [], args.data, true);
                            if (args.dropPosition === 'middleSegment') {
                                previousDetails['dropPosition'] = 'child';
                            }
                            else if (args.dropPosition === 'topSegment') {
                                previousDetails['dropPosition'] = 'above';
                            }
                            else Eif (args.dropPosition === 'bottomSegment') {
                                previousDetails['dropPosition'] = 'below';
                            }
                            records['afterDrop'] = previousDetails;
                            this.parent.undoRedoModule['findPosition'](rowItems, records, 'beforeDrop');
                            this.parent.undoRedoModule['getUndoCollection'][this.parent.undoRedoModule['getUndoCollection'].length - 1] = records;
                        }
                        Eif (this.parent.toolbarModule) {
                            this.parent.toolbarModule.enableItems([this.parent.controlId + '_undo'], true);
                        }
                    }
                    var draggedRecord = void 0;
                    var dragRecords = [];
                    var droppedRecord = this.droppedRecord;
                    Iif (!args.data[0]) {
                        dragRecords.push(args.data);
                    }
                    else {
                        dragRecords = args.data;
                    }
                    var count = 0;
                    var dragLength = dragRecords.length;
                    var _loop_2 = function (i) {
                        this_2.parent.isOnEdit = true;
                        draggedRecord = dragRecords[i];
                        this_2.draggedRecord = draggedRecord;
                        Eif (this_2.dropPosition !== 'Invalid') {
                            if (this_2.parent.viewType === 'ResourceView') {
                                this_2.checkisSharedTask();
                                if (this_2.draggedRecord.level !== 0) {
                                    this_2.previousParent = this_2.draggedRecord.parentItem.uniqueID;
                                }
                            }
                            if (this_2.isSharedTask) {
                                return { value: void 0 };
                            }
                            Eif (isByMethod) {
                                this_2.deleteDragRow();
                            }
                            var recordIndex1 = this_2.treeGridData.indexOf(droppedRecord);
                            if (this_2.dropPosition === 'topSegment') {
                                this_2.dropAtTop(recordIndex1);
                            }
                            if (this_2.dropPosition === 'bottomSegment') {
                                Eif (!this_2.isSharedTask) {
                                    if (!droppedRecord.hasChildRecords) {
                                        if (this_2.parent.taskFields.parentID && this_2.ganttData.length > 0) {
                                            this_2.ganttData.splice(recordIndex1 + 1, 0, this_2.draggedRecord.taskData);
                                        }
                                        this_2.treeGridData.splice(recordIndex1 + 1, 0, this_2.draggedRecord);
                                        this_2.parent.ids.splice(recordIndex1 + 1, 0, this_2.draggedRecord.ganttProperties.rowUniqueID.toString());
                                        if (this_2.parent.viewType === 'ResourceView') {
                                            var taskId = this_2.draggedRecord.level === 0 ? 'R' + this_2.draggedRecord.ganttProperties.taskId : 'T' + this_2.draggedRecord.ganttProperties.taskId;
                                            this_2.parent.getTaskIds().splice(recordIndex1 + 1, 0, taskId);
                                        }
                                    }
                                    else {
                                        count = this_2.parent.editModule.getChildCount(droppedRecord, 0);
                                        if (this_2.parent.taskFields.parentID && this_2.ganttData.length > 0) {
                                            this_2.ganttData.splice(recordIndex1 + count + 1, 0, this_2.draggedRecord.taskData);
                                        }
                                        this_2.treeGridData.splice(recordIndex1 + count + 1, 0, this_2.draggedRecord);
                                        this_2.parent.ids.splice(recordIndex1 + count + 1, 0, this_2.draggedRecord.ganttProperties.rowUniqueID.toString());
                                        if (this_2.parent.viewType === 'ResourceView') {
                                            var spliceId = this_2.draggedRecord.level === 0 ? 'R' + this_2.draggedRecord.ganttProperties.taskId : 'T' + this_2.draggedRecord.ganttProperties.taskId;
                                            this_2.parent.getTaskIds().splice(recordIndex1 + count + 1, 0, spliceId);
                                        }
                                    }
                                    this_2.parent.setRecordValue('parentItem', this_2.treeGridData[recordIndex1].parentItem, draggedRecord);
                                    this_2.parent.setRecordValue('parentUniqueID', this_2.treeGridData[recordIndex1].parentUniqueID, draggedRecord);
                                    this_2.parent.setRecordValue('level', this_2.treeGridData[recordIndex1].level, draggedRecord);
                                    if (draggedRecord.hasChildRecords) {
                                        var level = 1;
                                        this_2.updateChildRecordLevel(draggedRecord, level);
                                        this_2.updateChildRecord(draggedRecord, recordIndex1 + count + 1);
                                    }
                                    if (droppedRecord.parentItem) {
                                        var rec = this_2.parent.getParentTask(droppedRecord.parentItem).childRecords;
                                        var childRecords = rec;
                                        var droppedRecordIndex = childRecords.indexOf(droppedRecord) + 1;
                                        childRecords.splice(droppedRecordIndex, 0, draggedRecord);
                                    }
                                }
                            }
                            if (this_2.dropPosition === 'middleSegment') {
                                this_2.dropMiddle(recordIndex1);
                                Eif (droppedRecord.childRecords.length > 0) {
                                    delete droppedRecord.ganttProperties.segments;
                                    delete droppedRecord.taskData[this_2.parent.taskFields.segments];
                                }
                            }
                            Eif (this_2.treeGridData.length !== 0) {
                                for (var i_1 = 0; i_1 < this_2.treeGridData.length; i_1++) {
                                    this_2.treeGridData[parseInt(i_1.toString(), 10)].index = i_1;
                                    if (!ej2_base_1.isNullOrUndefined(this_2.treeGridData[parseInt(i_1.toString(), 10)].parentItem)) {
                                        var updatedParent = ej2_base_1.getValue('uniqueIDCollection.' + this_2.treeGridData[parseInt(i_1.toString(), 10)].parentUniqueID, this_2.parent.treeGrid);
                                        this_2.treeGridData[parseInt(i_1.toString(), 10)].parentItem.index = updatedParent.index;
                                    }
                                }
                            }
                            if (!ej2_base_1.isNullOrUndefined(draggedRecord.parentItem && this_2.updateParentRecords.indexOf(draggedRecord.parentItem) !== -1)) {
                                this_2.updateParentRecords.push(draggedRecord.parentItem);
                            }
                        }
                        if (!this_2.parent.enableVirtualization) {
                            var data_1 = gObj.flatData;
                            var startIndex = void 0;
                            var endIndex = void 0;
                            var ganttData_1 = this_2.parent.dataSource;
                            var uniqueTaskID_1 = this_2.parent.taskFields.id;
                            if (draggedRecord.index < droppedRecord.index) {
                                startIndex = draggedRecord.index;
                                var _loop_4 = function (i_2) {
                                    var currentData = this_2.parent.currentViewData.filter(function (e) {
                                        return e[uniqueTaskID_1] === ganttData_1[i_2][uniqueTaskID_1];
                                    })[0];
                                    if (currentData && currentData.index > droppedRecord.index) {
                                        endIndex = currentData.index;
                                        return "break";
                                    }
                                };
                                for (var i_2 = 0; i_2 < ganttData_1.length; i_2++) {
                                    var state_2 = _loop_4(i_2);
                                    if (state_2 === "break")
                                        break;
                                }
                            }
                            else {
                                startIndex = droppedRecord.index;
                                var _loop_5 = function (i_3) {
                                    var currentData = this_2.parent.currentViewData.filter(function (e) {
                                        return e[uniqueTaskID_1] === ganttData_1[i_3][uniqueTaskID_1];
                                    })[0];
                                    if (currentData && currentData.index > draggedRecord.index) {
                                        endIndex = currentData.index;
                                        return "break";
                                    }
                                };
                                for (var i_3 = 0; i_3 < ganttData_1.length; i_3++) {
                                    var state_3 = _loop_5(i_3);
                                    if (state_3 === "break")
                                        break;
                                }
                            }
                            var _loop_6 = function (i_4) {
                                Eif (!ej2_base_1.isNullOrUndefined(data_1[i_4])) {
                                    data_1[i_4].index = i_4;
                                    if (!ej2_base_1.isNullOrUndefined(data_1[i_4].parentItem)) {
                                        var updatedParent = data_1.filter(function (e) {
                                            return e.uniqueID === data_1[i_4].parentUniqueID;
                                        })[0];
                                        data_1[i_4].parentItem.index = updatedParent.index;
                                    }
                                }
                            };
                            for (var i_4 = startIndex; i_4 <= endIndex; i_4++) {
                                _loop_6(i_4);
                            }
                        }
                        gObj.rowDragAndDropModule.refreshDataSource();
                    };
                    var this_2 = this;
                    for (var i = 0; i < dragLength; i++) {
                        var state_1 = _loop_2(i);
                        if (typeof state_1 === "object")
                            return state_1.value;
                    }
                    if (this.dropPosition === 'middleSegment') {
                        if (droppedRecord.ganttProperties.predecessor) {
                            var len = droppedRecord.ganttProperties.predecessor.length;
                            for (var count_1 = 0; count_1 < len; count_1++) {
                                if (droppedRecord.ganttProperties.predecessor && droppedRecord.ganttProperties.predecessor[count_1]) {
                                    var fromRecord = this.parent.getRecordByID(droppedRecord.ganttProperties.predecessor[count_1].from);
                                    var toRecord = this.parent.getRecordByID(droppedRecord.ganttProperties.predecessor[count_1].to);
                                    var validPredecessor = this.parent.connectorLineEditModule.validateParentPredecessor(fromRecord, toRecord);
                                    if (droppedRecord.ganttProperties.predecessor && (!validPredecessor ||
                                        !this.parent.allowParentDependency)) {
                                        this.parent.editModule.removePredecessorOnDelete(droppedRecord);
                                        droppedRecord.ganttProperties.predecessor.splice(0, 1);
                                        if (droppedRecord.ganttProperties.predecessorsName) {
                                            var splittedName = droppedRecord.ganttProperties.predecessorsName.split(',');
                                            for (var i = 0; i < splittedName.length; i++) {
                                                Eif (splittedName[i].indexOf(draggedRecord.ganttProperties.taskId + '') !== -1) {
                                                    splittedName.splice(i, 1);
                                                }
                                            }
                                            var validatedPredecessorNames = splittedName.join();
                                            droppedRecord.ganttProperties.predecessorsName = validatedPredecessorNames;
                                            droppedRecord[this.parent.taskFields.dependency] = validatedPredecessorNames;
                                            droppedRecord.taskData[this.parent.taskFields.dependency] = validatedPredecessorNames;
                                        }
                                    }
                                }
                            }
                        }
                        if (droppedRecord.ganttProperties.isMilestone) {
                            this.parent.setRecordValue('isMilestone', false, droppedRecord.ganttProperties, true);
                            if (!ej2_base_1.isNullOrUndefined(droppedRecord.taskData[this.parent.taskFields.milestone])) {
                                Eif (droppedRecord.taskData[this.parent.taskFields.milestone] === true) {
                                    droppedRecord.taskData[this.parent.taskFields.milestone] = false;
                                }
                            }
                        }
                    }
                    if (this.parent.viewType === 'ResourceView' && !this.isSharedTask) {
                        var parentUniqueID = void 0;
                        if (this.dropPosition === 'middleSegment') {
                            parentUniqueID = this.droppedRecord.uniqueID;
                        }
                        else {
                            parentUniqueID = this.droppedRecord.parentItem ?
                                this.droppedRecord.parentItem.uniqueID : this.droppedRecord.uniqueID;
                        }
                        var droppedParentItem = this.parent.getTaskByUniqueID(parentUniqueID);
                        var editedObj = {};
                        editedObj[this.parent.taskFields.resourceInfo] = [];
                        editedObj[this.parent.taskFields.resourceInfo].push(droppedParentItem.ganttProperties.taskId);
                        this.removeExistingResources();
                        var tempResourceInfo = this.parent.dataOperation.setResourceInfo(editedObj);
                        var currentTask = this.draggedRecord;
                        if (ej2_base_1.isNullOrUndefined(currentTask.ganttProperties.resourceInfo)) {
                            currentTask.ganttProperties.resourceInfo = [];
                        }
                        if (droppedParentItem.ganttProperties.taskName === 'Unassigned Task') {
                            currentTask.ganttProperties.resourceInfo = [];
                            currentTask.ganttProperties.sharedTaskUniqueIds = [currentTask.ganttProperties.rowUniqueID];
                        }
                        else {
                            currentTask.ganttProperties.resourceInfo.push(tempResourceInfo[0]);
                        }
                        this.updateCurrentTask(currentTask);
                        if (droppedParentItem.ganttProperties.taskName === 'Unassigned Task') {
                            this.deleteSharedResourceTask();
                        }
                        else {
                            this.updateSharedResourceTask();
                        }
                    }
                    if (this.parent.taskFields.dependency && this.parent.allowParentDependency) {
                        var isValidPredecessor = true;
                        var draggedParent = void 0;
                        var toParent_1;
                        if (draggedRecord.parentItem) {
                            draggedParent = this.parent.flatData[this.parent.ids.indexOf(draggedRecord.parentItem.taskId)];
                        }
                        else {
                            draggedParent = draggedRecord;
                        }
                        if (droppedRecord.parentItem) {
                            toParent_1 = this.parent.flatData[this.parent.ids.indexOf(droppedRecord.parentItem.taskId)];
                        }
                        else {
                            toParent_1 = droppedRecord;
                        }
                        var validateRecords = void 0;
                        if (toParent_1.uniqueID === draggedParent.uniqueID || (draggedParent.parentItem &&
                            toParent_1.uniqueID === this.parent.flatData[this.parent.ids.indexOf(draggedParent.parentItem.taskId)].uniqueID)) {
                            validateRecords = this.parent.currentViewData.filter(function (data) {
                                if ((data.ganttProperties.predecessor && data.ganttProperties.predecessor.length > 0)) {
                                    for (var i = 0; i < data.ganttProperties.predecessor.length; i++) {
                                        return (parseInt(data.ganttProperties.predecessor[i].to, 10) ===
                                            parseInt(toParent_1.ganttProperties.taskId, 10) ||
                                            parseInt(data.ganttProperties.predecessor[i].from, 10) ===
                                                parseInt(toParent_1.ganttProperties.taskId, 10));
                                    }
                                }
                                return null;
                            });
                            var predName = [];
                            for (var i = 0; i < validateRecords.length; i++) {
                                predName = [];
                                Eif (validateRecords[i].ganttProperties.predecessor) {
                                    for (var k = 0; k < validateRecords[i].ganttProperties.predecessor.length; k++) {
                                        if (parseInt(validateRecords[i].ganttProperties.taskId, 10) !==
                                            parseInt(validateRecords[i].ganttProperties.predecessor[k].from, 10)) {
                                            predName.push(validateRecords[i].ganttProperties.predecessor[k].from);
                                        }
                                        else {
                                            predName.push(validateRecords[i].ganttProperties.predecessor[k].to);
                                        }
                                    }
                                }
                                var _loop_3 = function (j) {
                                    var name_1 = predName[j].replace(/\D/g, '');
                                    var toRec = this_3.parent.currentViewData.filter(function (data) {
                                        return parseInt(data.ganttProperties.taskId, 10) === parseInt(name_1, 10);
                                    });
                                    isValidPredecessor = this_3.parent.connectorLineEditModule.validateParentPredecessor(validateRecords[i], toRec[0]);
                                    if (!isValidPredecessor) {
                                        this_3.parent.dataOperation['resetDependency'](validateRecords[i]);
                                        this_3.parent.dataOperation['resetDependency'](toRec[0]);
                                    }
                                };
                                var this_3 = this;
                                for (var j = 0; j < predName.length; j++) {
                                    _loop_3(j);
                                }
                            }
                        }
                    }
                    for (var j = 0; j < this.updateParentRecords.length; j++) {
                        this.parent.dataOperation.updateParentItems(this.updateParentRecords[j]);
                    }
                    if (this.parent.viewType === 'ProjectView' && this.parent.editModule &&
                        this.parent.editModule.taskbarEditModule && this.parent.undoRedoModule &&
                        this.parent.undoRedoModule['isUndoRedoPerformed'] && this.parent.predecessorModule &&
                        this.parent.undoRedoModule['currentAction']['action'] === 'TaskbarDragAndDrop' &&
                        this.parent.undoRedoModule['currentAction']['beforeDrop'][0].position !== 'child') {
                        var dropRec = this.parent.flatData[this.parent.ids.indexOf(this.parent.undoRedoModule['currentAction']['afterDrop'].dropRecord.ganttProperties.taskId.toString())];
                        this.parent.editModule.taskbarEditModule.taskBarEditRecord = dropRec;
                        this.parent.editModule.taskbarEditModule.taskBarEditAction = 'ChildDrag';
                        this.parent.predecessorModule.validatePredecessor(dropRec, [], '');
                        this.parent.editModule.taskbarEditModule.taskBarEditAction = null;
                    }
                    this.updateParentRecords = [];
                    this.parent.isOnEdit = false;
                }
                Eif (!ej2_base_1.isNullOrUndefined(this.parent.editModule)) {
                    this.parent.editModule.refreshRecord(args, true);
                }
                if (!this.parent.undoRedoModule || (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed'])) {
                    this.parent.previousFlatData = ej2_base_1.extend([], [], this.parent.flatData, true);
                }
            }
            this.parent['oldRecords'] = [];
        };
        RowDD.prototype.updateCurrentTask = function (currentTask) {
            this.parent.dataOperation.updateMappingData(currentTask, 'resourceInfo');
            this.parent.editModule.updateResourceRelatedFields(currentTask, 'resource');
            this.parent.editModule.dialogModule.dialogEditValidationFlag = false;
            this.parent.editModule.dialogModule.validateDuration(currentTask);
            this.parent.dataOperation.updateWidthLeft(currentTask);
            this.parent.dataOperation.updateTaskData(currentTask);
        };
        RowDD.prototype.deleteSharedResourceTask = function () {
            for (var i = 0; i < this.parent.getTaskIds().length; i++) {
                if (this.parent.getTaskIds()[i] === 'T' + this.draggedRecord.ganttProperties.taskId) {
                    if (this.parent.getTaskByUniqueID(this.parent.flatData[i].parentItem.uniqueID).ganttProperties.taskName !== 'Unassigned Task') {
                        this.removeRecords(this.parent.flatData[i]);
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(this.parent.flatData[parseInt(i.toString(), 10)].parentItem &&
                        this.updateParentRecords.indexOf(this.parent.flatData[parseInt(i.toString(), 10)].parentItem) !== -1)) {
                        this.updateParentRecords.push(this.parent.flatData[i].parentItem);
                    }
                }
            }
        };
        RowDD.prototype.removeExistingResources = function () {
            var preParentRecord = this.parent.getTaskByUniqueID(this.previousParent);
            if (this.draggedRecord.ganttProperties.resourceInfo) {
                for (var count = 0; count < this.draggedRecord.ganttProperties.resourceInfo.length; count++) {
                    if (this.draggedRecord.ganttProperties.resourceInfo[parseInt(count.toString(), 10)][this.parent.resourceFields.id] ===
                        preParentRecord.ganttProperties.taskId) {
                        this.draggedRecord.ganttProperties.resourceInfo.splice(count, 1);
                        break;
                    }
                }
            }
        };
        RowDD.prototype.updateSharedResourceTask = function () {
            for (var i = 0; i < this.parent.getTaskIds().length; i++) {
                if (this.parent.getTaskIds()[i] === 'T' + this.draggedRecord.ganttProperties.taskId) {
                    this.parent.editModule.updateGanttProperties(this.draggedRecord, this.parent.flatData[i]);
                    this.parent.dataOperation.updateTaskData(this.parent.flatData[i]);
                    if (!ej2_base_1.isNullOrUndefined(this.parent.flatData[parseInt(i.toString(), 10)].parentItem &&
                        this.updateParentRecords.indexOf(this.parent.flatData[parseInt(i.toString(), 10)].parentItem) !== -1)) {
                        this.updateParentRecords.push(this.parent.flatData[i].parentItem);
                    }
                }
            }
        };
        RowDD.prototype._getExistingTaskWithID = function (record) {
            var existingTasks = [];
            for (var i = 0; i < this.parent.getTaskIds().length; i++) {
                if (this.parent.getTaskIds()[i] === 'T' + record.ganttProperties.taskId) {
                    existingTasks.push(this.parent.flatData[i]);
                }
            }
            return existingTasks;
        };
        RowDD.prototype.removeResourceInfo = function (record) {
            var droppedParentItem = this.parent.getTaskByUniqueID(this.draggedRecord.parentItem.uniqueID);
            Eif (record.ganttProperties.resourceInfo && record.ganttProperties.resourceInfo.length > 1) {
                var sameIdTasks = this._getExistingTaskWithID(record);
                var currentTask = void 0;
                Iif (sameIdTasks === null) {
                    return;
                }
                for (var i = 0; i < sameIdTasks.length; i++) {
                    currentTask = sameIdTasks[i];
                    var resources = currentTask.ganttProperties.resourceInfo;
                    for (var count = 0; count < resources.length; count++) {
                        Eif (resources[count][this.parent.resourceFields.id] === droppedParentItem.ganttProperties.taskId) {
                            resources.splice(count, 1);
                            this.parent.setRecordValue('resourceInfo', resources, currentTask.ganttProperties, true);
                            this.updateCurrentTask(currentTask);
                            Eif (!ej2_base_1.isNullOrUndefined(currentTask.parentItem && this.updateParentRecords.indexOf(currentTask.parentItem) !== -1)) {
                                this.updateParentRecords.push(currentTask.parentItem);
                            }
                            break;
                        }
                    }
                }
            }
        };
        RowDD.prototype.refreshDataSource = function () {
            var draggedRecord = this.draggedRecord;
            var droppedRecord = this.droppedRecord;
            var proxy = this.parent;
            var tempDataSource;
            var idx;
            var ganttFields = this.parent.taskFields;
            Iif (this.parent.dataSource instanceof ej2_data_1.DataManager) {
                tempDataSource = ej2_base_1.getValue('dataOperation.dataArray', this.parent);
            }
            else {
                tempDataSource = proxy.dataSource;
            }
            if (tempDataSource.length > 0 && (!ej2_base_1.isNullOrUndefined(droppedRecord) && !droppedRecord.parentItem)) {
                for (var i = 0; i < Object.keys(tempDataSource).length; i++) {
                    if (!ej2_base_1.isNullOrUndefined(droppedRecord.taskData[ganttFields.child]) &&
                        tempDataSource[i][ganttFields.child] === droppedRecord.taskData[ganttFields.child]) {
                        idx = i;
                    }
                    else if (ej2_base_1.isNullOrUndefined(droppedRecord.taskData[ganttFields.child]) &&
                        droppedRecord.taskData[ganttFields.id] === tempDataSource[i][ganttFields.id]) {
                        idx = i;
                    }
                }
                if (this.dropPosition === 'topSegment') {
                    if (!this.parent.taskFields.parentID) {
                        tempDataSource.splice(idx, 0, draggedRecord.taskData);
                    }
                }
                else if (this.dropPosition === 'bottomSegment') {
                    Eif (!this.parent.taskFields.parentID) {
                        tempDataSource.splice(idx + 1, 0, draggedRecord.taskData);
                    }
                }
            }
            else if (!this.parent.taskFields.parentID && (!ej2_base_1.isNullOrUndefined(droppedRecord) && droppedRecord.parentItem)) {
                if (this.dropPosition === 'topSegment' || this.dropPosition === 'bottomSegment') {
                    var rowPosition = this.dropPosition === 'topSegment' ? 'Above' : 'Below';
                    this.parent.editModule.addRowSelectedItem = droppedRecord;
                    this.parent.editModule.updateRealDataSource([draggedRecord], rowPosition);
                    delete this.parent.editModule.addRowSelectedItem;
                }
            }
            if (this.parent.taskFields.parentID) {
                if (draggedRecord.parentItem) {
                    var droppedId = this.dropPosition === 'middleSegment' ? this.parent.taskFields.id :
                        this.parent.taskFields.parentID;
                    draggedRecord[this.parent.taskFields.parentID] = droppedRecord[droppedId];
                    draggedRecord.ganttProperties.parentId = droppedRecord[droppedId];
                    if ((this.parent.viewType === 'ResourceView' && !(this.dropPosition === 'middleSegment')) ||
                        this.parent.viewType === 'ProjectView') {
                        draggedRecord.taskData[this.parent.taskFields.parentID] = droppedRecord.taskData[droppedId];
                    }
                }
                else {
                    draggedRecord[this.parent.taskFields.parentID] = null;
                    draggedRecord.taskData[this.parent.taskFields.parentID] = null;
                    draggedRecord.ganttProperties.parentId = null;
                }
            }
            if (this.parent.viewType === 'ProjectView' && this.parent.editModule && this.parent.editModule.taskbarEditModule &&
                this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed'] && this.parent.predecessorModule &&
                this.parent.undoRedoModule['currentAction']['action'] === 'TaskbarDragAndDrop') {
                var dragRec = this.parent.flatData[this.parent.ids.indexOf(this.parent.undoRedoModule['currentAction']['afterDrop'].data[0].ganttProperties.taskId.toString())];
                this.parent.editModule.taskbarEditModule.taskBarEditRecord = dragRec;
                this.parent.editModule.taskbarEditModule.taskBarEditAction = 'ChildDrag';
                this.parent.predecessorModule.validatePredecessor(dragRec, [], '');
                this.parent.editModule.taskbarEditModule.taskBarEditAction = null;
            }
        };
        RowDD.prototype.dropMiddle = function (recordIndex1) {
            var gObj = this.parent;
            var childRecords = this.parent.editModule.getChildCount(this.droppedRecord, 0);
            var childRecordsLength = (ej2_base_1.isNullOrUndefined(childRecords) ||
                childRecords === 0) ? recordIndex1 + 1 :
                childRecords + recordIndex1 + 1;
            Eif (this.dropPosition === 'middleSegment' && !this.isSharedTask) {
                if (gObj.taskFields.parentID && this.ganttData.length > 0) {
                    this.ganttData.splice(childRecordsLength, 0, this.draggedRecord.taskData);
                }
                this.treeGridData.splice(childRecordsLength, 0, this.draggedRecord);
                this.parent.ids.splice(childRecordsLength, 0, this.draggedRecord.ganttProperties.rowUniqueID.toString());
                if (this.parent.viewType === 'ResourceView') {
                    var recordId = this.draggedRecord.level === 0 ? 'R' + this.draggedRecord.ganttProperties.taskId : 'T' + this.draggedRecord.ganttProperties.taskId;
                    this.parent.getTaskIds().splice(childRecordsLength, 0, recordId);
                }
                if (this.draggedRecord.hasChildRecords) {
                    this.updateChildRecord(this.draggedRecord, childRecordsLength, this.droppedRecord.expanded);
                }
                this.recordLevel();
                Iif (ej2_base_1.isNullOrUndefined(this.draggedRecord.parentItem &&
                    this.updateParentRecords.indexOf(this.draggedRecord.parentItem) !== -1)) {
                    this.updateParentRecords.push(this.draggedRecord.parentItem);
                }
            }
        };
        RowDD.prototype.recordLevel = function () {
            var gObj = this.parent;
            var draggedRecord = this.draggedRecord;
            var droppedRecord = this.droppedRecord;
            var childItem = gObj.taskFields.child;
            if (!droppedRecord.hasChildRecords) {
                droppedRecord.hasChildRecords = true;
                Eif (!droppedRecord.childRecords.length) {
                    droppedRecord.childRecords = [];
                    if (!gObj.taskFields.parentID && ej2_base_1.isNullOrUndefined(droppedRecord.taskData[childItem])) {
                        droppedRecord.taskData[childItem] = [];
                    }
                }
            }
            Eif (this.dropPosition === 'middleSegment') {
                var parentItem = ej2_base_1.extend({}, droppedRecord);
                delete parentItem.childRecords;
                var createParentItem = {
                    uniqueID: parentItem.uniqueID,
                    expanded: parentItem.expanded,
                    level: parentItem.level,
                    index: parentItem.index,
                    taskId: parentItem.ganttProperties.rowUniqueID
                };
                this.parent.setRecordValue('parentItem', createParentItem, draggedRecord);
                this.parent.setRecordValue('parentUniqueID', droppedRecord.uniqueID, draggedRecord);
                droppedRecord.childRecords.splice(droppedRecord.childRecords.length, 0, draggedRecord);
                if (!ej2_base_1.isNullOrUndefined(draggedRecord) && !gObj.taskFields.parentID &&
                    !ej2_base_1.isNullOrUndefined(droppedRecord.taskData[childItem])) {
                    droppedRecord.taskData[gObj.taskFields.child].splice(droppedRecord.childRecords.length, 0, draggedRecord.taskData);
                }
                if (!draggedRecord.hasChildRecords) {
                    draggedRecord.level = droppedRecord.level + 1;
                }
                else {
                    var level = 1;
                    draggedRecord.level = droppedRecord.level + 1;
                    this.parent.setRecordValue('level', this.draggedRecord.level, this.draggedRecord);
                    this.updateChildRecordLevel(draggedRecord, level);
                }
                droppedRecord.expanded = true;
            }
        };
        RowDD.prototype.deleteDragRow = function () {
            this.treeGridData = common_1.isCountRequired(this.parent) ? ej2_base_1.getValue('result', this.parent.treeGrid.dataSource) :
                this.parent.treeGrid.dataSource;
            Iif (this.parent.dataSource instanceof ej2_data_1.DataManager) {
                this.ganttData = ej2_base_1.getValue('dataOperation.dataArray', this.parent);
            }
            else {
                this.ganttData = common_1.isCountRequired(this.parent) ? ej2_base_1.getValue('result', this.parent.dataSource) :
                    this.parent.dataSource;
            }
            var deletedRow;
            if (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed']) {
                if (this.parent.viewType === 'ProjectView') {
                    deletedRow = this.parent.flatData[this.parent.ids.indexOf(this.draggedRecord.ganttProperties.taskId.toString())];
                }
                else {
                    Iif (this.draggedRecord.hasChildRecords) {
                        deletedRow = this.parent.flatData['R' + this.parent.taskIds.indexOf(this.draggedRecord.ganttProperties.taskId)];
                    }
                    else {
                        deletedRow = this.parent.flatData['T' + this.parent.taskIds.indexOf(this.draggedRecord.ganttProperties.taskId)];
                    }
                }
            }
            else {
                deletedRow = this.parent.getTaskByUniqueID(this.draggedRecord.uniqueID);
            }
            this.removeRecords(deletedRow);
        };
        RowDD.prototype.checkisSharedTask = function () {
            this.isSharedTask = false;
            var sharedTask = null;
            var parentUniqueID = this.droppedRecord.level === 0 ? this.droppedRecord.uniqueID : this.droppedRecord.parentItem.uniqueID;
            var droppedParentItem = this.parent.getTaskByUniqueID(parentUniqueID);
            var childTasks = droppedParentItem.childRecords;
            for (var i = 0; i < childTasks.length; i++) {
                if ('T' + this.draggedRecord.ganttProperties.taskId === 'T' + childTasks[i].ganttProperties.taskId) {
                    this.isSharedTask = true;
                    sharedTask = childTasks[i];
                }
            }
            if (this.isSharedTask) {
                this.removeResourceInfo(sharedTask);
            }
        };
        RowDD.prototype.dropAtTop = function (recordIndex1) {
            var gObj = this.parent;
            Eif (!this.isSharedTask) {
                if (gObj.taskFields.parentID && this.ganttData.length > 0) {
                    this.ganttData.splice(recordIndex1, 0, this.draggedRecord.taskData);
                }
                this.treeGridData.splice(recordIndex1, 0, this.draggedRecord);
                this.parent.ids.splice(recordIndex1, 0, this.draggedRecord.ganttProperties.rowUniqueID.toString());
                this.parent.setRecordValue('parentItem', this.droppedRecord.parentItem, this.draggedRecord);
                this.parent.setRecordValue('parentUniqueID', this.droppedRecord.parentUniqueID, this.draggedRecord);
                this.parent.setRecordValue('level', this.droppedRecord.level, this.draggedRecord);
                if (this.parent.viewType === 'ResourceView') {
                    var id = this.draggedRecord.level === 0 ? 'R' + this.draggedRecord.ganttProperties.taskId : 'T' + this.draggedRecord.ganttProperties.taskId;
                    this.parent.getTaskIds().splice(recordIndex1, 0, id);
                }
                if (this.draggedRecord.hasChildRecords) {
                    var level = 1;
                    this.updateChildRecord(this.draggedRecord, recordIndex1);
                    this.updateChildRecordLevel(this.draggedRecord, level);
                }
                if (this.droppedRecord.parentItem) {
                    var rec = this.parent.getParentTask(this.droppedRecord.parentItem).childRecords;
                    var childRecords = rec;
                    var droppedRecordIndex = childRecords.indexOf(this.droppedRecord);
                    childRecords.splice(droppedRecordIndex, 0, this.draggedRecord);
                }
                if (!ej2_base_1.isNullOrUndefined(this.draggedRecord.parentItem && this.updateParentRecords.indexOf(this.draggedRecord.parentItem) !== -1)) {
                    this.updateParentRecords.push(this.draggedRecord.parentItem);
                }
            }
        };
        RowDD.prototype.updateChildRecordLevel = function (record, level) {
            var length = 0;
            var currentRecord;
            level++;
            Iif (!record.hasChildRecords) {
                return 0;
            }
            length = record.childRecords.length;
            for (var i = 0; i < length; i++) {
                currentRecord = record.childRecords[i];
                var parentData = void 0;
                if (record.parentItem) {
                    var id = 'uniqueIDCollection';
                    parentData = this.parent.treeGrid[id][record.parentItem.uniqueID];
                }
                currentRecord.level = record.parentItem ? parentData.level + level : record.level + 1;
                this.parent.setRecordValue('level', currentRecord.level, currentRecord);
                Iif (currentRecord.hasChildRecords) {
                    level--;
                    level = this.updateChildRecordLevel(currentRecord, level);
                }
            }
            return level;
        };
        RowDD.prototype.updateChildRecord = function (record, count, expanded) {
            var currentRecord;
            var gObj = this.parent;
            var length = 0;
            Iif (!record.hasChildRecords) {
                return 0;
            }
            length = record.childRecords.length;
            for (var i = 0; i < length; i++) {
                currentRecord = record.childRecords[i];
                count++;
                gObj.flatData.splice(count, 0, currentRecord);
                this.parent.ids.splice(count, 0, currentRecord.ganttProperties.rowUniqueID.toString());
                if (gObj.taskFields.parentID && gObj.dataSource.length > 0) {
                    this.ganttData.splice(count, 0, currentRecord.taskData);
                }
                Iif (currentRecord.hasChildRecords) {
                    count = this.updateChildRecord(currentRecord, count);
                }
            }
            return count;
        };
        RowDD.prototype.removeRecords = function (record) {
            var gObj = this.parent;
            var dataSource;
            Iif (this.parent.dataSource instanceof ej2_data_1.DataManager) {
                dataSource = ej2_base_1.getValue('dataOperation.dataArray', this.parent);
            }
            else {
                dataSource = this.parent.dataSource;
            }
            var deletedRow = record;
            var flatParentData = deletedRow && deletedRow.parentItem ? this.parent.getParentTask(deletedRow.parentItem) : null;
            if (deletedRow) {
                if (deletedRow.parentItem) {
                    var childRecords = [];
                    Eif (flatParentData) {
                        childRecords = flatParentData.childRecords;
                    }
                    var childIndex = 0;
                    Eif (childRecords && childRecords.length > 0) {
                        if (this.parent.viewType === 'ResourceView' && childRecords.length === 1) {
                            this.parent.isOnDelete = true;
                            childRecords[0].isDelete = true;
                            this.parent.dataOperation.updateParentItems(flatParentData);
                            this.parent.isOnDelete = false;
                            childRecords[0].isDelete = false;
                        }
                        childIndex = childRecords.indexOf(deletedRow);
                        flatParentData.childRecords.splice(childIndex, 1);
                        if (!this.parent.taskFields.parentID && flatParentData.taskData[this.parent.taskFields.child]) {
                            flatParentData.taskData[this.parent.taskFields.child].splice(childIndex, 1);
                        }
                        this.updateParentRecords.push(flatParentData);
                    }
                }
                if (!this.parent.taskFields.parentID) {
                    var deleteRecordIDs = [];
                    deleteRecordIDs.push(deletedRow.ganttProperties.taskId.toString());
                    if (this.parent.viewType === 'ProjectView' || (this.parent.viewType === 'ResourceView' && this.dropPosition !== 'middleSegment')) {
                        this.parent.editModule.removeFromDataSource(deleteRecordIDs);
                    }
                }
                if (gObj.taskFields.parentID) {
                    if (deletedRow.hasChildRecords && deletedRow.childRecords.length > 0) {
                        this.removeChildItem(deletedRow);
                    }
                    var idx = void 0;
                    var ganttData = dataSource.length > 0 && this.parent.viewType !== 'ResourceView' ?
                        dataSource : this.parent.updatedRecords;
                    for (var i = 0; i < ganttData.length; i++) {
                        if (this.parent.viewType === 'ResourceView') {
                            if (ganttData[i].ganttProperties.rowUniqueID === deletedRow.ganttProperties.rowUniqueID) {
                                idx = i;
                            }
                        }
                        else {
                            if (ganttData[i][this.parent.taskFields.id] === deletedRow.taskData[this.parent.taskFields.id]) {
                                idx = i;
                            }
                        }
                    }
                    Eif (idx !== -1) {
                        Eif (dataSource.length > 0) {
                            dataSource.splice(idx, 1);
                        }
                        var tempIndex = this.treeGridData.indexOf(deletedRow);
                        this.treeGridData.splice(tempIndex, 1);
                        this.parent.ids.splice(tempIndex, 1);
                        if (this.parent.treeGrid.parentData.indexOf(deletedRow) !== -1) {
                            this.parent.treeGrid.parentData.splice(this.parent.treeGrid.parentData.indexOf(deletedRow), 1);
                        }
                        if (this.parent.viewType === 'ResourceView') {
                            this.parent.getTaskIds().splice(idx, 1);
                        }
                    }
                }
                var recordIndex = this.treeGridData.indexOf(deletedRow);
                if (!gObj.taskFields.parentID) {
                    var deletedRecordCount = this.parent.editModule.getChildCount(deletedRow, 0);
                    this.treeGridData.splice(recordIndex, deletedRecordCount + 1);
                    this.parent.ids.splice(recordIndex, deletedRecordCount + 1);
                    var parentIndex = this.ganttData.indexOf(deletedRow.taskData);
                    Iif (parentIndex !== -1) {
                        this.ganttData.splice(parentIndex, 1);
                        this.parent.treeGrid.parentData.splice(parentIndex, 1);
                    }
                    if (this.parent.viewType === 'ResourceView') {
                        this.parent.getTaskIds().splice(recordIndex, deletedRecordCount + 1);
                    }
                }
                if (deletedRow.parentItem && flatParentData && flatParentData.childRecords && !flatParentData.childRecords.length) {
                    flatParentData.expanded = false;
                    flatParentData.hasChildRecords = false;
                }
            }
        };
        RowDD.prototype.removeChildItem = function (record) {
            var currentRecord;
            var idx;
            for (var i = 0; i < record.childRecords.length; i++) {
                currentRecord = record.childRecords[i];
                var ganttData = void 0;
                Iif (this.parent.dataSource instanceof ej2_data_1.DataManager) {
                    ganttData = ej2_base_1.getValue('dataOperation.dataArray', this.parent);
                }
                else {
                    ganttData = this.parent.dataSource;
                }
                for (var j = 0; j < ganttData.length; j++) {
                    if (ganttData[j][this.parent.taskFields.id] === currentRecord.taskData[this.parent.taskFields.id]) {
                        idx = j;
                    }
                }
                Eif (idx !== -1) {
                    Eif (ganttData.length > 0) {
                        ganttData.splice(idx, 1);
                    }
                    var tempIndex = this.treeGridData.indexOf(currentRecord);
                    this.treeGridData.splice(tempIndex, 1);
                    this.parent.ids.splice(tempIndex, 1);
                    if (this.parent.viewType === 'ResourceView') {
                        this.parent.getTaskIds().splice(idx, 1);
                    }
                }
                Iif (currentRecord.hasChildRecords) {
                    this.removeChildItem(currentRecord);
                }
            }
        };
        RowDD.prototype.reorderRows = function (fromIndexes, toIndex, position) {
            Eif (!this.parent.readOnly) {
                if (fromIndexes[0] !== toIndex && (position === 'above' || position === 'below' || position === 'child')) {
                    if (position === 'above') {
                        this.dropPosition = 'topSegment';
                    }
                    if (position === 'below') {
                        this.dropPosition = 'bottomSegment';
                    }
                    if (position === 'child') {
                        this.dropPosition = 'middleSegment';
                    }
                    var prevData = void 0;
                    if (this.parent.undoRedoModule) {
                        prevData = ej2_base_1.extend([], [], [this.parent.undoRedoModule['currentAction']], true)[0];
                    }
                    var data = [];
                    for (var i = 0; i < fromIndexes.length; i++) {
                        if (this.parent.undoRedoModule && this.parent.undoRedoModule['isUndoRedoPerformed'] && (prevData['action'] === 'RowDragAndDrop' || prevData['action'] === 'TaskbarDragAndDrop')) {
                            data[i] = prevData['beforeDrop'][i].data;
                        }
                        else {
                            data[i] = this.parent.flatData[fromIndexes[i]];
                        }
                    }
                    var isByMethod = true;
                    var args = {
                        data: data,
                        dropIndex: toIndex,
                        dropPosition: this.dropPosition
                    };
                    this.dropRows(args, isByMethod);
                }
                else {
                    return;
                }
            }
        };
        return RowDD;
    }());
    exports.RowDD = RowDD;
});