all files / pivotfieldlist/renderer/ tree-renderer.js

78.5% Statements 482/614
65.2% Branches 311/477
87.76% Functions 43/49
78.5% Lines 482/614
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 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108   99× 99× 99× 99× 99× 99×   105× 105×   105×   105× 102×     102×       102× 102×     102×       102× 102× 102× 102× 102×                           102× 102× 102× 102× 17× 17×     17× 17× 17×   102×         102× 102× 102× 306× 306×                       306× 306× 306×     102×                                             102× 102× 102× 102× 102× 102×                               12273× 12273× 6567×     5706× 74× 74× 74×     5632×     12273× 6088×   12273× 12273× 6567× 6567×   12273× 9344× 9344× 9344×                   9344×   9344×     12273× 2319×   12273× 80× 80× 62× 62× 62× 434×   434× 434× 434× 434×           18× 156× 13× 13×     143×                 6567× 6567× 6567× 1025×   6567×   1776×       1776×     6567×     3766× 702× 702×     3064×             6567×                                                                                                                                                                             124× 14× 14×                                                       18× 18×                                                 17×       17×             17×   13× 13× 13× 13×     13× 13× 13× 11× 11×                           11× 11× 11× 11×                                                                                                                                                                                                     11×             11× 11× 11× 11× 11× 11×     11×                                                                                                                           354× 352× 352×     352×     352× 352× 352× 352×   457× 457× 50×     407× 407× 407× 5757× 5757× 5757× 5757× 137× 137× 137×             407×     54×       407× 407× 5831× 5831× 5831×     457×   50× 50× 50×                                                                                                                       50×     50×   352×                                                                       352× 351× 42× 42× 42×       37× 37×   42×         42×     37×       309×     352×                     306× 306×   306× 306×   99×   99×     99×   99× 99×   99×   99× 99× 99×   99×              
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/base/css-constant", "../../common/base/constant", "@syncfusion/ej2-navigations", "@syncfusion/ej2-popups", "@syncfusion/ej2-inputs", "../../base/util"], function (require, exports, ej2_base_1, ej2_base_2, cls, events, ej2_navigations_1, ej2_popups_1, ej2_inputs_1, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TreeViewRenderer = (function () {
        function TreeViewRenderer(parent) {
            this.selectedNodes = [];
            this.isSearching = false;
            this.parentIDs = [];
            this.isSpaceKey = false;
            this.parent = parent;
            this.addEventListener();
        }
        TreeViewRenderer.prototype.render = function (axis) {
            this.parentElement = this.parent.dialogRenderer.parentElement;
            this.fieldListSort = this.parent.pivotGridModule ?
                this.parent.pivotGridModule.defaultFieldListOrder : this.parent.defaultFieldListOrder;
            this.fieldListSort = this.fieldListSort === 'Ascending' ? 'Ascend' :
                this.fieldListSort === 'Descending' ? 'Descend' : 'None';
            if (!this.parent.isAdaptive) {
                var fieldTable = ej2_base_1.createElement('div', {
                    className: cls.FIELD_TABLE_CLASS + ' ' + (this.parent.dataType === 'olap' ? cls.OLAP_FIELD_TABLE_CLASS : '')
                });
                var treeHeader = ej2_base_1.createElement('div', {
                    className: cls.FIELD_HEADER_CLASS,
                    attrs: { title: this.parent.localeObj.getConstant('allFields') }
                });
                treeHeader.innerText = this.parent.localeObj.getConstant('allFields');
                var treeOuterDiv = ej2_base_1.createElement('div', {
                    className: cls.FIELD_LIST_TREE_OUTER_DIV_CLASS + ' ' + cls.TREE_CONTAINER
                });
                this.treeViewElement = ej2_base_1.createElement('div', {
                    id: this.parent.element.id + '_TreeView',
                    className: cls.FIELD_LIST_CLASS + ' ' + (this.parent.dataType === 'olap' ? cls.OLAP_FIELD_LIST_CLASS : '')
                });
                var fieldHeaderWrappper = ej2_base_1.createElement('div', { className: cls.FIELD_HEADER_CONTAINER_CLASS });
                fieldHeaderWrappper.appendChild(treeHeader);
                fieldTable.appendChild(fieldHeaderWrappper);
                this.updateSortElements(fieldHeaderWrappper);
                if (this.parent.enableFieldSearching) {
                    var searchWrapper = ej2_base_1.createElement('div', {
                        id: this.parent.element.id + '_SearchDiv', attrs: { 'tabindex': '-1' },
                        className: cls.FIELD_LIST_SEARCH_CLASS
                    });
                    var searchInput = ej2_base_1.createElement('input', { attrs: { 'type': 'text' } });
                    searchWrapper.appendChild(searchInput);
                    this.fieldSearch = new ej2_inputs_1.TextBox({
                        placeholder: this.parent.localeObj.getConstant('search'),
                        enableRtl: this.parent.enableRtl,
                        locale: this.parent.locale,
                        cssClass: cls.FIELD_LIST_SEARCH_INPUT_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                        input: this.textChange.bind(this),
                        showClearButton: true
                    });
                    this.fieldSearch.isStringTemplate = true;
                    this.fieldSearch.appendTo(searchInput);
                    this.fieldSearch.addIcon('append', cls.FIELD_LIST_SEARCH_ICON_CLASS + ' ' + cls.ICON);
                    var promptDiv = ej2_base_1.createElement('div', {
                        className: cls.EMPTY_MEMBER_CLASS + ' ' + cls.ICON_DISABLE
                    });
                    promptDiv.innerText = this.parent.localeObj.getConstant('noMatches');
                    fieldTable.appendChild(searchWrapper);
                    fieldTable.appendChild(promptDiv);
                }
                treeOuterDiv.appendChild(this.treeViewElement);
                fieldTable.appendChild(treeOuterDiv);
                this.parentElement.appendChild(fieldTable);
                if (this.parent.renderMode === 'Fixed') {
                    var centerDiv = ej2_base_1.createElement('div', { className: cls.STATIC_CENTER_DIV_CLASS });
                    var axisHeader = ej2_base_1.createElement('div', {
                        className: cls.STATIC_CENTER_HEADER_CLASS
                    });
                    axisHeader.innerText = this.parent.localeObj.getConstant('centerHeader');
                    this.parentElement.appendChild(centerDiv);
                    this.parentElement.appendChild(axisHeader);
                }
                this.renderTreeView();
            }
            else {
                this.renderTreeDialog(axis);
            }
        };
        TreeViewRenderer.prototype.updateSortElements = function (headerWrapper) {
            var options = { 'None': 'sortNone', 'Ascend': 'sortAscending', 'Descend': 'sortDescending' };
            var keys = Object.keys(options);
            for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
                var option = keys_1[_i];
                var spanElement = ej2_base_1.createElement('span', {
                    attrs: {
                        'tabindex': '0',
                        'aria-disabled': 'false',
                        'aria-label': 'Sort ' + option,
                        'data-sort': option,
                        'title': this.parent.localeObj.getConstant(options[option]),
                        'role': 'button'
                    },
                    className: cls.ICON + ' ' + 'e-sort-' + option.toLowerCase() + ' ' +
                        (this.fieldListSort === option ? 'e-selected' : '')
                });
                headerWrapper.appendChild(spanElement);
                this.unWireFieldListEvent(spanElement);
                this.wireFieldListEvent(spanElement);
            }
        };
        TreeViewRenderer.prototype.renderTreeView = function () {
            this.fieldTable = new ej2_navigations_1.TreeView({
                fields: { dataSource: this.getTreeData(), id: 'id', text: 'caption', isChecked: 'isSelected', parentID: 'pid', iconCss: 'spriteCssClass' },
                nodeChecked: this.nodeChecked.bind(this),
                nodeClicked: this.nodeStateChange.bind(this),
                keyPress: this.nodeStateChange.bind(this),
                cssClass: cls.FIELD_LIST_TREE_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                showCheckBox: true,
                allowDragAndDrop: true,
                sortOrder: 'None',
                loadOnDemand: this.parent.dataType === 'olap' ? false : true,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                nodeDragStart: this.dragStart.bind(this),
                nodeDragStop: this.dragStop.bind(this),
                drawNode: this.updateTreeNode.bind(this),
                nodeExpanding: this.updateNodeIcon.bind(this),
                nodeCollapsed: this.updateNodeIcon.bind(this),
                nodeSelected: function (args) {
                    ej2_base_1.removeClass([args.node], 'e-active');
                    args.cancel = true;
                }
            });
            this.treeViewElement.innerHTML = '';
            this.fieldTable.isStringTemplate = true;
            this.fieldTable.appendTo(this.treeViewElement);
            var dragEle = this.parent.renderMode === 'Fixed' ? this.parent.element : this.parentElement;
            Eif (!ej2_base_1.isNullOrUndefined(dragEle.querySelector('.' + cls.FIELD_LIST_CLASS))) {
                ej2_base_1.getInstance(dragEle.querySelector('.' + cls.FIELD_LIST_CLASS), ej2_navigations_1.TreeView)['dragObj']
                    .enableAutoScroll = false;
            }
        };
        TreeViewRenderer.prototype.updateNodeIcon = function (args) {
            Eif (this.parent.dataType === 'olap') {
                Iif (args.node && args.node.querySelector('.e-list-icon') &&
                    (args.node.querySelector('.e-list-icon').className.indexOf('e-folderCDB-icon') > -1)) {
                    var node = args.node.querySelector('.e-list-icon');
                    ej2_base_1.removeClass([node], 'e-folderCDB-icon');
                    ej2_base_1.addClass([node], 'e-folderCDB-open-icon');
                }
                else Iif (args.node && args.node.querySelector('.e-list-icon') &&
                    (args.node.querySelector('.e-list-icon').className.indexOf('e-folderCDB-open-icon') > -1)) {
                    var node = args.node.querySelector('.e-list-icon');
                    ej2_base_1.removeClass([node], 'e-folderCDB-open-icon');
                    ej2_base_1.addClass([node], 'e-folderCDB-icon');
                }
            }
        };
        TreeViewRenderer.prototype.updateTreeNode = function (args) {
            var allowDrag = false;
            if (this.parent.dataType === 'olap') {
                allowDrag = this.updateOlapTreeNode(args);
            }
            else {
                if (args.nodeData.hasChildren) {
                    allowDrag = false;
                    args.node.querySelector('.' + cls.CHECKBOX_CONTAINER).style.display = 'none';
                    ej2_base_1.addClass([args.node], cls.FIELD_TREE_PARENT);
                }
                else {
                    allowDrag = true;
                }
            }
            if (!ej2_base_1.isNullOrUndefined(args.nodeData.pid)) {
                ej2_base_1.addClass([args.node], cls.FIELD_TREE_CHILD);
            }
            var liTextElement = args.node.querySelector('.' + cls.TEXT_CONTENT_CLASS);
            if (args.node.querySelector('.e-list-icon') && liTextElement) {
                var liIconElement = args.node.querySelector('.e-list-icon');
                liTextElement.insertBefore(liIconElement, args.node.querySelector('.e-list-text'));
            }
            if (allowDrag && !this.parent.isAdaptive) {
                var field = util_1.PivotUtil.getFieldInfo(args.nodeData.id, this.parent);
                allowDrag = false;
                var dragElement = ej2_base_1.createElement('span', {
                    attrs: {
                        'tabindex': '-1',
                        title: (field.fieldItem ? field.fieldItem.allowDragAndDrop ?
                            this.parent.localeObj.getConstant('drag') : '' : this.parent.localeObj.getConstant('drag')),
                        'aria-disabled': 'false'
                    },
                    className: cls.ICON + ' ' + cls.DRAG_CLASS + ' ' +
                        (field.fieldItem ? field.fieldItem.allowDragAndDrop ? '' : cls.DRAG_DISABLE_CLASS : '')
                });
                Eif (args.node.querySelector('.' + cls.CHECKBOX_CONTAINER) &&
                    !args.node.querySelector('.cls.DRAG_CLASS') && liTextElement) {
                    liTextElement.insertBefore(dragElement, args.node.querySelector('.' + cls.CHECKBOX_CONTAINER));
                }
            }
            if (args.node.querySelector('.' + cls.NODE_CHECK_CLASS)) {
                ej2_base_1.addClass([args.node.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
            }
            if (this.parent.enableFieldSearching && this.isSearching) {
                var liElement = args.node;
                if (this.parent.dataType === 'olap') {
                    var id = liElement.getAttribute('data-uid');
                    var searchItem = this.parent.pivotCommon.eventBase.searchListItem;
                    for (var i = 0; i < this.parentIDs.length; i++) {
                        if (id === this.parentIDs[i]) {
                            ej2_base_1.addClass([liElement], cls.ICON_DISABLE);
                        }
                        for (var _i = 0, searchItem_1 = searchItem; _i < searchItem_1.length; _i++) {
                            var li2 = searchItem_1[_i];
                            var parentID = this.parent.pivotCommon.eventBase.getParentIDs(this.fieldTable, li2.getAttribute('data-uid'), []);
                            if (util_1.PivotUtil.inArray(id, parentID) > -1) {
                                ej2_base_1.removeClass([liElement], cls.ICON_DISABLE);
                                break;
                            }
                        }
                    }
                }
                else {
                    for (var i = 0; i < this.nonSearchList.length; i++) {
                        if (liElement.textContent === this.nonSearchList[i].textContent) {
                            ej2_base_1.addClass([liElement], cls.ICON_DISABLE);
                            break;
                        }
                        else {
                            Iif (liElement.innerText === this.nonSearchList[i].textContent) {
                                ej2_base_1.addClass([liElement], cls.ICON_DISABLE);
                                break;
                            }
                        }
                    }
                }
            }
        };
        TreeViewRenderer.prototype.updateOlapTreeNode = function (args) {
            var allowDrag = false;
            Eif (this.parent.dataType === 'olap') {
                if (args.node && args.node.querySelector('.e-calcMemberGroupCDB,.e-measureGroupCDB-icon,.e-folderCDB-icon,.e-folderCDB-open-icon,.e-dimensionCDB-icon,.e-kpiCDB-icon')) {
                    args.node.querySelector('.' + cls.CHECKBOX_CONTAINER).style.display = 'none';
                }
                if (args.node && args.node.querySelector('.e-list-icon') &&
                    (args.node.querySelector('.e-list-icon').className.indexOf('e-level-members') > -1)) {
                    Iif (this.parent.isAdaptive) {
                        args.node.querySelector('.' + cls.CHECKBOX_CONTAINER).style.display = 'none';
                    }
                    else {
                        args.node.querySelector('.' + cls.CHECKBOX_CONTAINER).style.visibility = 'hidden';
                    }
                }
                if (args.node && (args.node.querySelector('.e-hierarchyCDB-icon,.e-attributeCDB-icon,.e-namedSetCDB-icon') ||
                    args.node.querySelector('.e-measure-icon,.e-kpiGoal-icon,.e-kpiStatus-icon,.e-kpiTrend-icon,.e-kpiValue-icon') ||
                    args.node.querySelector('.e-calc-measure-icon,.e-calc-dimension-icon'))) {
                    if (args.node.querySelector('.e-measure-icon')) {
                        args.node.querySelector('.e-list-icon').style.display = 'none';
                        allowDrag = true;
                    }
                    else {
                        allowDrag = true;
                    }
                }
            }
            else {
                allowDrag = true;
            }
            return allowDrag;
        };
        TreeViewRenderer.prototype.renderTreeDialog = function (axis) {
            var fieldListDialog = ej2_base_1.createElement('div', {
                id: this.parent.element.id + '_FieldListTreeView',
                className: cls.ADAPTIVE_FIELD_LIST_DIALOG_CLASS + ' ' + (this.parent.dataType === 'olap' ? 'e-olap-editor-dialog' : '')
            });
            this.parentElement.appendChild(fieldListDialog);
            this.fieldDialog = new ej2_popups_1.Dialog({
                animationSettings: { effect: 'Fade' },
                allowDragging: false,
                header: this.parent.localeObj.getConstant('adaptiveFieldHeader'),
                content: this.createTreeView(this.getTreeData(axis)),
                isModal: true,
                visible: true,
                showCloseIcon: false,
                enableRtl: this.parent.enableRtl,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                locale: this.parent.locale,
                width: '320px',
                height: '350px',
                position: { X: 'center', Y: 'center' },
                buttons: [{
                        click: this.closeTreeDialog.bind(this),
                        isFlat: false,
                        buttonModel: {
                            cssClass: cls.CANCEL_BUTTON_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), content: this.parent.localeObj.getConstant('cancel')
                        }
                    }, {
                        click: this.onFieldAdd.bind(this),
                        isFlat: false,
                        buttonModel: {
                            cssClass: cls.OK_BUTTON_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), content: this.parent.localeObj.getConstant('add'),
                            isPrimary: true
                        }
                    }],
                closeOnEscape: false,
                cssClass: this.parent.cssClass,
                close: this.closeTreeDialog.bind(this),
                target: ej2_base_2.closest(this.parentElement, '.' + cls.WRAPPER_CLASS)
            });
            this.fieldDialog.isStringTemplate = true;
            this.fieldDialog.appendTo(fieldListDialog);
        };
        TreeViewRenderer.prototype.createTreeView = function (treeData) {
            var editorTreeWrapper = ej2_base_1.createElement('div', {
                id: this.parent.element.id + 'EditorDiv',
                className: cls.EDITOR_TREE_WRAPPER_CLASS
            });
            var searchWrapper = ej2_base_1.createElement('div', {
                id: this.parent.element.id + '_SearchDiv', attrs: { 'tabindex': '-1' },
                className: cls.EDITOR_SEARCH_WRAPPER_CLASS
            });
            var editorSearch = ej2_base_1.createElement('input', { attrs: { 'type': 'text' } });
            searchWrapper.appendChild(editorSearch);
            var treeOuterDiv = ej2_base_1.createElement('div', { className: cls.FIELD_LIST_TREE_OUTER_DIV_CLASS });
            var treeViewContainer = ej2_base_1.createElement('div', {
                className: cls.EDITOR_TREE_CONTAINER_CLASS + ' ' + (this.parent.dataType === 'olap' ? 'e-olap-field-list-tree' : '')
            });
            editorTreeWrapper.appendChild(searchWrapper);
            this.editorSearch = new ej2_inputs_1.MaskedTextBox({
                showClearButton: true,
                placeholder: this.parent.localeObj.getConstant('search'),
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                cssClass: cls.EDITOR_SEARCH_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                change: this.textChange.bind(this)
            });
            this.editorSearch.isStringTemplate = true;
            this.editorSearch.appendTo(editorSearch);
            var promptDiv = ej2_base_1.createElement('div', {
                className: cls.EMPTY_MEMBER_CLASS + ' ' + cls.ICON_DISABLE
            });
            promptDiv.innerText = this.parent.localeObj.getConstant('noMatches');
            editorTreeWrapper.appendChild(promptDiv);
            treeOuterDiv.appendChild(treeViewContainer);
            editorTreeWrapper.appendChild(treeOuterDiv);
            this.fieldTable = new ej2_navigations_1.TreeView({
                fields: { dataSource: treeData, id: 'id', text: 'caption', isChecked: 'isSelected', parentID: 'pid', iconCss: 'spriteCssClass' },
                showCheckBox: true,
                loadOnDemand: this.parent.dataType === 'olap' ? false : true,
                sortOrder: this.parent.dataType === 'olap' ? 'None' : 'Ascending',
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                cssClass: this.parent.cssClass,
                nodeChecked: this.nodeChecked.bind(this),
                nodeClicked: this.addNode.bind(this),
                keyPress: this.addNode.bind(this),
                drawNode: this.updateTreeNode.bind(this),
                nodeExpanding: this.updateNodeIcon.bind(this),
                nodeCollapsed: this.updateNodeIcon.bind(this),
                nodeSelected: function (args) {
                    ej2_base_1.removeClass([args.node], 'e-active');
                    args.cancel = true;
                }
            });
            this.fieldTable.isStringTemplate = true;
            this.fieldTable.appendTo(treeViewContainer);
            return editorTreeWrapper;
        };
        TreeViewRenderer.prototype.textChange = function (e) {
            this.parent.pivotCommon.eventBase.searchTreeNodes(e, this.fieldTable, true);
            var promptDiv;
            var treeOuterDiv;
            if (this.parent.isAdaptive) {
                promptDiv = this.fieldDialog.element.querySelector('.' + cls.EMPTY_MEMBER_CLASS);
            }
            else {
                promptDiv = this.parentElement.querySelector('.' + cls.EMPTY_MEMBER_CLASS);
                treeOuterDiv = this.parentElement.querySelector('.' + cls.TREE_CONTAINER);
            }
            var liList = [].slice.call(this.fieldTable.element.querySelectorAll('li'));
            var disabledList = [].slice.call(this.fieldTable.element.querySelectorAll('li.' + cls.ICON_DISABLE));
            Iif (liList.length === disabledList.length) {
                ej2_base_1.removeClass([promptDiv], cls.ICON_DISABLE);
                if (!this.parent.isAdaptive) {
                    ej2_base_1.addClass([treeOuterDiv], cls.ICON_DISABLE);
                    ej2_base_1.removeClass([treeOuterDiv], cls.FIELD_LIST_TREE_OUTER_DIV_SEARCH_CLASS);
                }
            }
            else {
                ej2_base_1.addClass([promptDiv], cls.ICON_DISABLE);
                if (!this.parent.isAdaptive) {
                    ej2_base_1.removeClass([treeOuterDiv], cls.ICON_DISABLE);
                    ej2_base_1.addClass([treeOuterDiv], cls.FIELD_LIST_TREE_OUTER_DIV_SEARCH_CLASS);
                }
            }
            this.isSearching = disabledList.length > 0 ? true : false;
            this.nonSearchList = disabledList;
            if (this.parent.dataType === 'olap') {
                this.parentIDs = [];
                for (var i = 0; i < liList.length; i++) {
                    if (liList[i].classList.contains('e-level-1')) {
                        var id = liList[i].getAttribute('data-uid');
                        this.parentIDs.push(id);
                    }
                }
            }
        };
        TreeViewRenderer.prototype.dragStart = function (args) {
            var _this = this;
            if (args.event.target.classList.contains(cls.DRAG_CLASS) &&
                !args.event.target.classList.contains(cls.DRAG_DISABLE_CLASS)) {
                var fieldInfo = util_1.PivotUtil.getFieldInfo(args.draggedNode.getAttribute('data-uid'), this.parent);
                var dragEventArgs = {
                    fieldName: fieldInfo.fieldName, fieldItem: fieldInfo.fieldItem, axis: fieldInfo.axis,
                    dataSourceSettings: this.parent.dataSourceSettings, cancel: false
                };
                var control = this.parent.isPopupView ? this.parent.pivotGridModule : this.parent;
                control.trigger(events.fieldDragStart, dragEventArgs, function (observedArgs) {
                    Eif (!observedArgs.cancel) {
                        _this.parent.isDragging = true;
                        ej2_base_1.addClass([args.draggedNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.SELECTED_NODE_CLASS);
                        var data = void 0;
                        Iif (_this.parent.dataType === 'olap') {
                            data = _this.parent.olapEngineModule.fieldList[args.draggedNode.getAttribute('data-uid')];
                        }
                        else {
                            data = _this.parent.engineModule.fieldList[args.draggedNode.getAttribute('data-uid')];
                        }
                        var axis = [cls.ROW_AXIS_CLASS, cls.COLUMN_AXIS_CLASS, cls.FILTER_AXIS_CLASS];
                        if (data && data.aggregateType === 'CalculatedField') {
                            for (var _i = 0, axis_1 = axis; _i < axis_1.length; _i++) {
                                var axisContent = axis_1[_i];
                                ej2_base_1.addClass([_this.parentElement.querySelector('.' + axisContent)], cls.NO_DRAG_CLASS);
                            }
                        }
                        var dragItem = args.clonedNode;
                        Iif (dragItem && (_this.parent.getModuleName() === 'pivotfieldlist' &&
                            _this.parent.renderMode) === 'Popup') {
                            dragItem.style.zIndex = (_this.parent.dialogRenderer.fieldListDialog.zIndex + 1).toString();
                        }
                    }
                    else {
                        _this.parent.isDragging = false;
                        args.cancel = true;
                    }
                });
            }
            else {
                this.parent.isDragging = false;
                args.cancel = true;
            }
        };
        TreeViewRenderer.prototype.dragStop = function (args) {
            args.cancel = true;
            this.parent.isDragging = false;
            var axis = [cls.ROW_AXIS_CLASS, cls.COLUMN_AXIS_CLASS, cls.FILTER_AXIS_CLASS];
            for (var _i = 0, axis_2 = axis; _i < axis_2.length; _i++) {
                var axisElement = axis_2[_i];
                ej2_base_1.removeClass([this.parentElement.querySelector('.' + axisElement)], cls.NO_DRAG_CLASS);
            }
            ej2_base_1.removeClass([args.draggedNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.SELECTED_NODE_CLASS);
            if (this.parent.pivotCommon.filterDialog.dialogPopUp) {
                this.parent.pivotCommon.filterDialog.dialogPopUp.close();
            }
            var fieldName = args.draggedNodeData.id.toString();
            Iif (!this.isNodeDropped(args, fieldName)) {
                return;
            }
            var list = this.parent.pivotFieldList;
            var selectedNode = list[fieldName];
            this.parent.pivotCommon.dataSourceUpdate.control = this.parent.getModuleName() === 'pivotview' ? this.parent :
                (this.parent.isPopupView && this.parent.pivotGridModule ? this.parent.pivotGridModule
                    : this.parent);
            if (this.parent.pivotCommon.nodeStateModified.onStateModified(args, fieldName)) {
                Iif (this.parent.isDeferLayoutUpdate || (this.parent.pivotGridModule && this.parent.pivotGridModule.pivotDeferLayoutUpdate)) {
                    selectedNode.isSelected = true;
                    this.updateDataSource();
                }
                else {
                    this.parent.updateDataSource();
                }
                var parent_1 = this.parent;
                parent_1.axisFieldModule.render();
            }
        };
        TreeViewRenderer.prototype.isNodeDropped = function (args, targetID) {
            var isDropped = true;
            if (args.draggedNodeData.isChecked === 'true') {
                var target = this.getButton(targetID);
                var axisPanel = ej2_base_2.closest(target, '.' + cls.DROPPABLE_CLASS);
                var droppableElement = ej2_base_2.closest(args.target, '.' + cls.DROPPABLE_CLASS);
                if (target && axisPanel === droppableElement) {
                    var pivotButtons = [].slice.call(axisPanel.querySelectorAll('.' + cls.PIVOT_BUTTON_CLASS));
                    var dropTarget = ej2_base_2.closest(args.target, '.' + cls.PIVOT_BUTTON_WRAPPER_CLASS);
                    var sourcePosition = void 0;
                    var dropPosition = -1;
                    for (var i = 0, n = pivotButtons.length; i < n; i++) {
                        if (pivotButtons[i].id === target.id) {
                            sourcePosition = i;
                        }
                        Eif (dropTarget) {
                            var droppableButton = dropTarget.querySelector('.' + cls.PIVOT_BUTTON_CLASS);
                            if (pivotButtons[i].id === droppableButton.id) {
                                dropPosition = i;
                            }
                        }
                    }
                    Iif (sourcePosition === dropPosition || (sourcePosition === (pivotButtons.length - 1) && dropPosition === -1)) {
                        var parentElement = document.getElementById(this.parent.element.id + '_Container');
                        ej2_base_1.removeClass([].slice.call(parentElement.querySelectorAll('.' + cls.DROP_INDICATOR_CLASS)), cls.INDICATOR_HOVER_CLASS);
                        isDropped = false;
                    }
                }
            }
            return isDropped;
        };
        TreeViewRenderer.prototype.getButton = function (fieldName) {
            var wrapperElement = document.getElementById(this.parent.element.id + '_Container');
            var pivotButtons = [].slice.call(wrapperElement.querySelectorAll('.' + cls.PIVOT_BUTTON_CLASS));
            var buttonElement;
            for (var i = 0, n = pivotButtons.length; i < n; i++) {
                if (pivotButtons[i].getAttribute('data-uid') === fieldName) {
                    buttonElement = pivotButtons[i];
                    break;
                }
            }
            return buttonElement;
        };
        TreeViewRenderer.prototype.nodeChecked = function (args) {
            if (this.isSpaceKey) {
                var node = ej2_base_2.closest(args.node, '.' + cls.TEXT_CONTENT_CLASS);
                Eif (!ej2_base_1.isNullOrUndefined(node)) {
                    var li = ej2_base_2.closest(node, 'li');
                    var id = li.getAttribute('data-uid');
                    Iif (this.parent.isAdaptive) {
                        this.addNode(undefined, id, args.action === 'check', node);
                    }
                    else {
                        this.nodeStateChange(undefined, id, args.action === 'check', node);
                    }
                }
            }
            this.isSpaceKey = false;
        };
        TreeViewRenderer.prototype.nodeStateChange = function (args, id, isChecked, node) {
            var _this = this;
            node = ej2_base_1.isNullOrUndefined(node) ? args.node : node;
            id = ej2_base_1.isNullOrUndefined(id) ? node.getAttribute('data-uid') : id;
            Iif (this.parent.pivotCommon.filterDialog.dialogPopUp) {
                this.parent.pivotCommon.filterDialog.dialogPopUp.close();
            }
            var list = this.parent.pivotFieldList;
            var selectedNode = list[id];
            if (!ej2_base_1.isNullOrUndefined(args)) {
                this.isSpaceKey = args.event.action && args.event.action === 'space';
                if (ej2_base_1.isNullOrUndefined(selectedNode) || node.classList.contains(cls.ICON_DISABLE) || (args.event.target &&
                    (args.event.target.classList.contains(cls.COLLAPSIBLE) ||
                        args.event.target.classList.contains(cls.EXPANDABLE))) ||
                    (args.event.action && args.event.action !== 'enter')) {
                    return;
                }
                isChecked = false;
                var getNodeDetails = this.fieldTable.getNode(node);
                Eif (args.event && args.event.target &&
                    !args.event.target.closest('.' + cls.CHECKBOX_CONTAINER)) {
                    if (getNodeDetails.isChecked === 'true') {
                        this.fieldTable.uncheckAll([node]);
                        isChecked = false;
                    }
                    else {
                        this.fieldTable.checkAll([node]);
                        isChecked = true;
                    }
                }
                else {
                    isChecked = getNodeDetails.isChecked === 'true';
                }
            }
            var control = this.parent.isPopupView ? this.parent.pivotGridModule : this.parent;
            var fieldInfo = util_1.PivotUtil.getFieldInfo(id, this.parent);
            var parentNode = node.closest('.' + cls.FIELD_TREE_PARENT);
            if (isChecked) {
                var eventdrop = {
                    fieldName: id, dropField: fieldInfo.fieldItem,
                    dataSourceSettings: util_1.PivotUtil.getClonedDataSourceSettings(this.parent.dataSourceSettings),
                    dropAxis: (selectedNode.type === 'number' || (selectedNode.type === 'CalculatedField' &&
                        selectedNode.formula && selectedNode.formula.indexOf('Measure') > -1 &&
                        this.parent.dataType === 'olap')) ? 'values' : 'rows',
                    dropPosition: fieldInfo.position, draggedAxis: 'fieldlist', cancel: false
                };
                control.trigger(events.fieldDrop, eventdrop, function (observedArgs) {
                    Eif (!observedArgs.cancel) {
                        ej2_base_1.addClass([node.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                        Iif (parentNode) {
                            ej2_base_1.addClass([parentNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                        }
                        _this.updateSelectedNodes(node, 'check');
                        var addNode = _this.parent.pivotCommon.dataSourceUpdate.getNewField(id, fieldInfo.fieldItem);
                        _this.updateReportSettings(addNode, observedArgs);
                        _this.updateNodeStateChange(id, selectedNode, isChecked);
                    }
                    else {
                        _this.updateCheckState(selectedNode, 'check');
                    }
                });
            }
            else {
                var removeFieldArgs = {
                    cancel: false, fieldName: id,
                    dataSourceSettings: util_1.PivotUtil.getClonedDataSourceSettings(this.parent.dataSourceSettings),
                    fieldItem: fieldInfo.fieldItem, axis: fieldInfo.axis
                };
                control.trigger(events.fieldRemove, removeFieldArgs, function (observedArgs) {
                    Eif (!observedArgs.cancel) {
                        ej2_base_1.removeClass([node.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                        Iif (parentNode && ej2_base_1.isNullOrUndefined(parentNode.querySelector('.' + cls.FIELD_TREE_CHILD + ' .' + cls.NODE_CHECK_CLASS))) {
                            ej2_base_1.removeClass([parentNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                        }
                        _this.updateSelectedNodes(node, 'uncheck');
                        _this.parent.pivotCommon.dataSourceUpdate.removeFieldFromReport(id);
                        Iif (_this.parent.dataType === 'pivot' && _this.parent.showValuesButton && _this.parent.dataSourceSettings.values.length > 1 &&
                            fieldInfo && fieldInfo.position < _this.parent.dataSourceSettings.valueIndex &&
                            ((_this.parent.dataSourceSettings.valueAxis === 'row' && fieldInfo.axis === 'rows') ||
                                (_this.parent.dataSourceSettings.valueAxis === 'column' && fieldInfo.axis === 'columns'))) {
                            control.setProperties({ dataSourceSettings: { valueIndex: _this.parent.dataSourceSettings.valueIndex - 1 } }, true);
                        }
                        Iif (_this.parent.dataType === 'olap' && _this.parent.dataSourceSettings.values.length === 0) {
                            _this.parent.pivotCommon.dataSourceUpdate.removeFieldFromReport('[Measures]');
                        }
                        _this.updateNodeStateChange(id, selectedNode, isChecked);
                    }
                    else {
                        _this.updateCheckState(selectedNode, 'uncheck');
                    }
                });
            }
        };
        TreeViewRenderer.prototype.updateReportSettings = function (newField, dropArgs) {
            var dropPosition = dropArgs.dropPosition;
            var dropClass = dropArgs.dropAxis;
            if (this.parent.dataType === 'pivot' && this.parent.showValuesButton && this.parent.dataSourceSettings.values.length > 1) {
                var dropAxisFields = (this.parent.dataSourceSettings.valueAxis === 'row' &&
                    dropClass === 'rows') ? this.parent.dataSourceSettings.rows : (this.parent.dataSourceSettings.valueAxis === 'column' && dropClass === 'columns') ?
                    this.parent.dataSourceSettings.columns : undefined;
                Iif (!ej2_base_1.isNullOrUndefined(dropAxisFields)) {
                    if (dropPosition === -1 && this.parent.dataSourceSettings.valueIndex === -1) {
                        this.parent.setProperties({ dataSourceSettings: { valueIndex: dropAxisFields.length } }, true);
                    }
                    else if (dropPosition > -1 && dropPosition <= this.parent.dataSourceSettings.valueIndex) {
                        this.parent.setProperties({ dataSourceSettings: { valueIndex: this.parent.dataSourceSettings.valueIndex + 1 } }, true);
                    }
                    else if (this.parent.dataSourceSettings.valueIndex > -1 && dropPosition > this.parent.dataSourceSettings.valueIndex) {
                        dropPosition = dropPosition - 1;
                    }
                }
            }
            switch (dropClass) {
                case 'filters':
                    if (dropPosition !== -1) {
                        this.parent.dataSourceSettings.filters.splice(dropPosition, 0, newField);
                    }
                    else {
                        this.parent.dataSourceSettings.filters.push(newField);
                    }
                    break;
                case 'rows':
                    Iif (dropPosition !== -1) {
                        this.parent.dataSourceSettings.rows.splice(dropPosition, 0, newField);
                    }
                    else {
                        this.parent.dataSourceSettings.rows.push(newField);
                    }
                    break;
                case 'columns':
                    if (dropPosition !== -1) {
                        this.parent.dataSourceSettings.columns.splice(dropPosition, 0, newField);
                    }
                    else {
                        this.parent.dataSourceSettings.columns.push(newField);
                    }
                    break;
                case 'values':
                    Iif (dropPosition !== -1) {
                        this.parent.dataSourceSettings.values.splice(dropPosition, 0, newField);
                    }
                    else {
                        this.parent.dataSourceSettings.values.push(newField);
                    }
                    Iif (this.parent.dataType === 'olap' && this.parent.olapEngineModule &&
                        !(this.parent.olapEngineModule).isMeasureAvail && !(this.parent.dataSourceSettings.values.length > 1)) {
                        var measureField = {
                            name: '[Measures]', caption: 'Measures', baseField: undefined, baseItem: undefined
                        };
                        var fieldAxis = this.parent.dataSourceSettings.valueAxis === 'row' ?
                            this.parent.dataSourceSettings.rows : this.parent.dataSourceSettings.columns;
                        fieldAxis.push(measureField);
                    }
                    break;
            }
        };
        TreeViewRenderer.prototype.updateCheckState = function (selectedNode, action) {
            var chkState = this.fieldTable.element.querySelectorAll('.' + cls.CHECKBOX_CONTAINER);
            var innerText = this.fieldTable.element.querySelectorAll('.e-list-text');
            for (var i = 0; i < chkState.length; i++) {
                if (selectedNode.caption === innerText[i].textContent) {
                    if (action === 'check') {
                        this.fieldTable.uncheckAll([selectedNode['id']]);
                    }
                    else {
                        this.fieldTable.checkAll([selectedNode['id']]);
                    }
                }
            }
        };
        TreeViewRenderer.prototype.updateNodeStateChange = function (id, selectedNode, isChecked) {
            if (this.parent.isDeferLayoutUpdate === false || (this.parent.pivotGridModule &&
                this.parent.pivotGridModule.pivotDeferLayoutUpdate === false)) {
                this.parent.updateDataSource(true);
            }
            else {
                selectedNode.isSelected = isChecked;
                Iif (this.parent.dataType === 'olap') {
                    this.parent.olapEngineModule.updateFieldlistData(id, isChecked);
                }
                this.updateDataSource();
            }
            var selectedLi = this.treeViewElement.querySelector('[data-uid="' + id + '"]');
            selectedLi.focus();
            ej2_base_1.removeClass([selectedLi], 'e-hover');
            var parent = this.parent;
            setTimeout(function () {
                parent.axisFieldModule.render();
            });
        };
        TreeViewRenderer.prototype.updateSelectedNodes = function (li, state) {
            Iif (li && li.querySelector('ul')) {
                for (var _i = 0, _a = [].slice.call(li.querySelectorAll('li')); _i < _a.length; _i++) {
                    var element = _a[_i];
                    if (state === 'check') {
                        ej2_base_1.addClass([element.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                    }
                    else {
                        ej2_base_1.removeClass([element.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.LIST_SELECT_CLASS);
                    }
                }
            }
        };
        TreeViewRenderer.prototype.updateDataSource = function () {
            Iif (this.parent.isPopupView) {
                if (this.parent.dataType === 'olap') {
                    this.parent.pivotGridModule.olapEngineModule = this.parent.olapEngineModule;
                }
                else {
                    this.parent.pivotGridModule.engineModule = this.parent.engineModule;
                }
                this.parent.pivotGridModule.setProperties({ dataSourceSettings: this.parent.dataSourceSettings.properties }, true);
                this.parent.pivotGridModule.notify(events.uiUpdate, this);
            }
            else {
                this.parent.triggerPopulateEvent();
            }
        };
        TreeViewRenderer.prototype.addNode = function (args, id, isChecked, node) {
            var _this = this;
            node = ej2_base_1.isNullOrUndefined(node) ? args.node : node;
            id = ej2_base_1.isNullOrUndefined(id) ? node.getAttribute('data-uid') : id;
            var list = this.parent.pivotFieldList;
            var selectedNode = list[id];
            Eif (!ej2_base_1.isNullOrUndefined(args)) {
                this.isSpaceKey = args.event.key && args.event.key === ' ';
                Iif (ej2_base_1.isNullOrUndefined(selectedNode) || args.node.classList.contains(cls.ICON_DISABLE) || (args.event.target &&
                    (args.event.target.classList.contains(cls.COLLAPSIBLE) ||
                        args.event.target.classList.contains(cls.EXPANDABLE))) ||
                    (args.event.key && args.event.key !== 'Enter')) {
                    return;
                }
                isChecked = false;
                var getNodeDetails = this.fieldTable.getNode(args.node);
                Eif (args.event && args.event.target &&
                    !args.event.target.classList.contains(cls.CHECK_BOX_FRAME_CLASS)) {
                    if (getNodeDetails.isChecked === 'true') {
                        this.fieldTable.uncheckAll([args.node]);
                        isChecked = false;
                    }
                    else {
                        this.fieldTable.checkAll([args.node]);
                        isChecked = true;
                    }
                }
                else {
                    isChecked = getNodeDetails.isChecked === 'true';
                }
            }
            var fieldInfo = util_1.PivotUtil.getFieldInfo(selectedNode.id.toString(), this.parent);
            var control = this.parent.isPopupView ? this.parent.pivotGridModule : this.parent;
            if (isChecked) {
                var axis = ['filters', 'columns', 'rows', 'values'];
                var eventdrop = {
                    fieldName: fieldInfo.fieldName, dropField: fieldInfo.fieldItem,
                    dataSourceSettings: util_1.PivotUtil.getClonedDataSourceSettings(this.parent.dataSourceSettings),
                    dropAxis: axis[this.parent.dialogRenderer.adaptiveElement.selectedItem], draggedAxis: 'fieldlist', cancel: false
                };
                control.trigger(events.fieldDrop, eventdrop, function (observedArgs) {
                    Eif (!observedArgs.cancel) {
                        _this.selectedNodes.push(selectedNode.id.toString());
                    }
                    else {
                        _this.updateCheckState(selectedNode, 'check');
                    }
                });
            }
            else {
                var removeFieldArgs = {
                    cancel: false, fieldName: fieldInfo.fieldName,
                    dataSourceSettings: util_1.PivotUtil.getClonedDataSourceSettings(this.parent.dataSourceSettings),
                    fieldItem: fieldInfo.fieldItem, axis: fieldInfo.axis
                };
                control.trigger(events.fieldRemove, removeFieldArgs, function (observedArgs) {
                    Eif (!observedArgs.cancel) {
                        var count = _this.selectedNodes.length;
                        while (count--) {
                            Eif (_this.selectedNodes[count] === selectedNode.id.toString()) {
                                _this.selectedNodes.splice(count, 1);
                                break;
                            }
                        }
                    }
                    else {
                        _this.updateCheckState(selectedNode, 'uncheck');
                    }
                });
            }
        };
        TreeViewRenderer.prototype.refreshTreeView = function () {
            if (this.fieldTable) {
                var treeData = this.getUpdatedData();
                this.fieldTable.fields = {
                    dataSource: treeData, id: 'id', text: 'caption', isChecked: 'isSelected', parentID: 'pid', iconCss: 'spriteCssClass'
                };
                this.fieldTable.dataBind();
            }
        };
        TreeViewRenderer.prototype.getUpdatedData = function () {
            var treeData = this.getTreeData();
            var expandedNodes = this.fieldTable.expandedNodes;
            this.updateExpandedNodes(treeData, expandedNodes);
            return this.applySorting(treeData, this.fieldListSort);
        };
        TreeViewRenderer.prototype.getTreeData = function (axis) {
            var data = [];
            if (this.parent.dataType === 'olap') {
                data = this.getOlapTreeData(axis);
            }
            else {
                var keys = this.parent.pivotFieldList ? Object.keys(this.parent.pivotFieldList) : [];
                var treeDataInfo = {};
                for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
                    var key = keys_2[_i];
                    var member = this.parent.pivotFieldList[key];
                    treeDataInfo[key] = { id: member.id, pid: member.pid, caption: member.caption, isSelected: member.isSelected };
                    if (!ej2_base_1.isNullOrUndefined(member.pid) && !treeDataInfo[key].hasChildren) {
                        var parentId = member.pid + '_group_name';
                        treeDataInfo[key].pid = parentId;
                        treeDataInfo[parentId] = {
                            id: parentId, caption: member.pid,
                            isSelected: treeDataInfo[parentId] && treeDataInfo[parentId].isSelected
                                ? treeDataInfo[parentId].isSelected : member.isSelected, hasChildren: true
                        };
                    }
                }
                if (this.parent.isAdaptive) {
                    var fields = [this.parent.dataSourceSettings.filters, this.parent.dataSourceSettings.columns,
                        this.parent.dataSourceSettings.rows,
                        this.parent.dataSourceSettings.values];
                    var currentFieldSet = fields[axis];
                    var len = keys.length;
                    while (len--) {
                        treeDataInfo[keys[len]].isSelected = false;
                    }
                    for (var _a = 0, currentFieldSet_1 = currentFieldSet; _a < currentFieldSet_1.length; _a++) {
                        var item = currentFieldSet_1[_a];
                        treeDataInfo[item.name].isSelected = true;
                    }
                }
                var members = Object.keys(treeDataInfo);
                for (var _b = 0, members_1 = members; _b < members_1.length; _b++) {
                    var member = members_1[_b];
                    var obj = treeDataInfo[member];
                    data.push(obj);
                }
            }
            return data;
        };
        TreeViewRenderer.prototype.getOlapTreeData = function (axis) {
            var data = [];
            var fieldListData = this.parent.olapEngineModule.fieldListData ? this.parent.olapEngineModule.fieldListData : [];
            Iif (this.parent.isAdaptive) {
                var fields = [
                    this.parent.dataSourceSettings.filters, this.parent.dataSourceSettings.columns,
                    this.parent.dataSourceSettings.rows, this.parent.dataSourceSettings.values
                ];
                var currentFieldSet = fields[axis];
                var i = 0;
                while (i < fieldListData.length) {
                    var item = fieldListData[i];
                    var framedSet = void 0;
                    if (axis === 3) {
                        if (item.id.toLowerCase() !== '[measures]' &&
                            (item.id.toLowerCase().indexOf('[measures]') === 0 ||
                                (item.spriteCssClass && item.spriteCssClass.indexOf('e-measureCDB') !== -1)) ||
                            (item.id.toLowerCase() === '[calculated members].[_0]' ||
                                (item.spriteCssClass && item.spriteCssClass.indexOf('e-calc-measure-icon') !== -1))) {
                            framedSet = {
                                id: item.id, caption: item.caption, hasChildren: item.hasChildren,
                                type: item.type, aggregateType: item.aggregateType,
                                isSelected: item.isSelected, pid: item.pid, spriteCssClass: item.spriteCssClass
                            };
                            framedSet.isSelected = false;
                            if (framedSet.spriteCssClass && framedSet.spriteCssClass.indexOf('e-measureCDB') !== -1) {
                                framedSet.spriteCssClass = framedSet.spriteCssClass.replace('e-folderCDB-icon', 'e-measureGroupCDB-icon');
                                framedSet.pid = undefined;
                            }
                            for (var _i = 0, currentFieldSet_2 = currentFieldSet; _i < currentFieldSet_2.length; _i++) {
                                var field = currentFieldSet_2[_i];
                                if (framedSet.id === field.name) {
                                    framedSet.isSelected = true;
                                    break;
                                }
                            }
                            data.push(framedSet);
                        }
                    }
                    else {
                        if (!(item.id.toLowerCase().indexOf('[measures]') === 0) &&
                            !(item.spriteCssClass && item.spriteCssClass.indexOf('e-measureCDB') !== -1) &&
                            !(item.spriteCssClass && item.spriteCssClass.indexOf('e-calc-measure-icon') !== -1)) {
                            framedSet = {
                                id: item.id, caption: item.caption, hasChildren: item.hasChildren,
                                type: item.type, aggregateType: item.aggregateType,
                                isSelected: item.isSelected, pid: item.pid, spriteCssClass: item.spriteCssClass
                            };
                            framedSet.isSelected = false;
                            for (var _a = 0, currentFieldSet_3 = currentFieldSet; _a < currentFieldSet_3.length; _a++) {
                                var item_1 = currentFieldSet_3[_a];
                                if (framedSet.id === item_1.name) {
                                    framedSet.isSelected = true;
                                    break;
                                }
                            }
                            data.push(framedSet);
                        }
                    }
                    i++;
                }
            }
            else {
                data = ej2_base_1.isNullOrUndefined(this.parent.olapEngineModule.fieldListData) ? [] :
                    util_1.PivotUtil.getClonedData(this.parent.olapEngineModule.fieldListData);
            }
            return data;
        };
        TreeViewRenderer.prototype.updateExpandedNodes = function (data, expandedNodes) {
            Iif (expandedNodes.length > 0) {
                var i = 0;
                for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
                    var field = data_1[_i];
                    if (expandedNodes.indexOf(field.id) > -1) {
                        i++;
                        field.expanded = true;
                        field.spriteCssClass = (field.spriteCssClass &&
                            field.spriteCssClass.toString().indexOf('e-folderCDB-icon') > -1 ?
                            field.spriteCssClass.toString().replace('e-folderCDB-icon', 'e-folderCDB-open-icon') :
                            field.spriteCssClass);
                        if (i === (expandedNodes.length)) {
                            break;
                        }
                    }
                }
            }
        };
        TreeViewRenderer.prototype.updateSorting = function (args) {
            var target = args.target;
            var option = target.getAttribute('data-sort');
            this.parent.actionObj.actionName = events.sortFieldTree;
            Iif (this.parent.actionBeginMethod()) {
                return;
            }
            try {
                Eif (target.className.indexOf('e-selected') === -1) {
                    switch (option) {
                        case 'None':
                            this.fieldListSort = 'None';
                            ej2_base_1.addClass([target], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-ascend')], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-descend')], 'e-selected');
                            break;
                        case 'Ascend':
                            this.fieldListSort = 'Ascend';
                            ej2_base_1.addClass([target], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-none')], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-descend')], 'e-selected');
                            break;
                        case 'Descend':
                            this.fieldListSort = 'Descend';
                            ej2_base_1.addClass([target], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-ascend')], 'e-selected');
                            ej2_base_1.removeClass([this.parentElement.querySelector('.e-sort-none')], 'e-selected');
                            break;
                    }
                    this.refreshTreeView();
                }
            }
            catch (execption) {
                this.parent.actionFailureMethod(execption);
            }
            this.parent.actionObj.actionName = this.parent.getActionCompleteName();
            Eif (this.parent.actionObj.actionName) {
                this.parent.actionCompleteMethod();
            }
        };
        TreeViewRenderer.prototype.applySorting = function (treeData, sortOrder) {
            if (treeData.length > 0) {
                if (this.parent.dataType === 'olap') {
                    var measure = void 0;
                    var calcMember = void 0;
                    if (this.parent.dataSourceSettings.calculatedFieldSettings.length > 0 &&
                        treeData[0].id.toLowerCase() === '[calculated members].[_0]') {
                        calcMember = treeData[0];
                        measure = treeData[1];
                        treeData.splice(0, 2);
                    }
                    else {
                        measure = treeData[0];
                        treeData.splice(0, 1);
                    }
                    treeData = sortOrder === 'Ascend' ?
                        (treeData.sort(function (a, b) { return (a.caption > b.caption) ? 1 :
                            ((b.caption > a.caption) ? -1 : 0); })) : sortOrder === 'Descend' ?
                        (treeData.sort(function (a, b) { return (a.caption < b.caption) ? 1 :
                            ((b.caption < a.caption) ? -1 : 0); })) : treeData;
                    if (calcMember) {
                        treeData.splice(0, 0, calcMember, measure);
                    }
                    else {
                        treeData.splice(0, 0, measure);
                    }
                }
                else {
                    this.fieldTable.sortOrder = ((sortOrder === 'Ascend' ? 'Ascending' : (sortOrder === 'Descend' ? 'Descending' : 'None')));
                }
            }
            return treeData;
        };
        TreeViewRenderer.prototype.onFieldAdd = function () {
            this.parent.dialogRenderer.updateDataSource(this.selectedNodes);
            this.closeTreeDialog();
        };
        TreeViewRenderer.prototype.closeTreeDialog = function () {
            this.selectedNodes = [];
            this.fieldDialog.hide();
            this.fieldDialog.destroy();
            Eif (document.getElementById(this.parent.element.id + '_FieldListTreeView')) {
                ej2_base_1.remove(document.getElementById(this.parent.element.id + '_FieldListTreeView'));
            }
            this.fieldDialog = null;
        };
        TreeViewRenderer.prototype.keyPress = function (e) {
            if (e.keyCode === 13 && e.target) {
                e.target.click();
                e.preventDefault();
                return;
            }
        };
        TreeViewRenderer.prototype.wireFieldListEvent = function (element) {
            ej2_base_1.EventHandler.add(element, 'keydown', this.keyPress, this);
            ej2_base_1.EventHandler.add(element, 'click', this.updateSorting, this);
        };
        TreeViewRenderer.prototype.unWireFieldListEvent = function (element) {
            ej2_base_1.EventHandler.remove(element, 'keydown', this.keyPress);
            ej2_base_1.EventHandler.remove(element, 'click', this.updateSorting);
        };
        TreeViewRenderer.prototype.addEventListener = function () {
            this.parent.on(events.treeViewUpdate, this.refreshTreeView, this);
        };
        TreeViewRenderer.prototype.removeEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.treeViewUpdate, this.refreshTreeView);
        };
        TreeViewRenderer.prototype.destroy = function () {
            this.removeEventListener();
            if (this.editorSearch && !this.editorSearch.isDestroyed) {
                this.editorSearch.destroy();
                this.editorSearch = null;
            }
            if (this.fieldSearch && !this.fieldSearch.isDestroyed) {
                this.fieldSearch.destroy();
                this.fieldSearch = null;
            }
            Eif (this.fieldTable && !this.fieldTable.isDestroyed) {
                this.fieldTable.destroy();
                this.fieldTable = null;
            }
            Iif (this.fieldDialog && !this.fieldDialog.isDestroyed) {
                this.fieldDialog.destroy();
                this.fieldDialog = null;
            }
        };
        return TreeViewRenderer;
    }());
    exports.TreeViewRenderer = TreeViewRenderer;
});