all files / common/calculatedfield/ calculated-field.js

79.56% Statements 985/1238
66.41% Branches 615/926
89.86% Functions 62/69
79.56% Lines 985/1238
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 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157   87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87× 87×   2043×                                                                               12× 12×                                                                                                       57×               11× 11× 11× 11× 11× 11×                                                                                                     81× 81×                                                                       36× 36× 36× 36×                                                             16× 16× 16× 16× 16× 16×   16×           16×   16× 16× 16× 16× 12×           10× 179× 179×           16×   15× 15× 15×   14× 14×                                                                                                                           12×         12×       12×     12× 12× 24×               16×             11×   11×   13×                                 16× 16× 16× 16× 16×   16× 16×         16× 16× 16×       16×   14× 14× 14×                               14×     15× 15× 15× 15×       15× 15×     15× 15×   15× 15× 12×   12× 12×         12×               12× 12× 12× 12×                                               62×         16× 16×     319× 319×     216×   103×     99×           12× 221× 221× 221× 221× 221× 147×     74×     221× 221×                             16×                                                                         16× 16×       16×       16× 16×                                     16×                 16×                                         16× 16×     32× 32×   15×     15× 15× 15×   15×     15×     15×                   27×       27× 27× 27×                   24×       24× 24×         24× 24×     20×   24× 24× 16×     16×   16×                                         12×     24× 24× 24× 24× 24×     20×   24× 16×     16×   16×     12×     24×                 24×     20×   24×         24×                                 24× 16×     16× 16×   24×     24×     16×   24×       24×         24× 24× 24×     16×   24×       16×   16×     27×                                                                                         24× 24× 24×   24× 24× 24× 120× 120×   24×   319× 319×     84×                                                         24×                 24× 24× 24×                 24× 24×   114× 114× 112×   20× 20×   20× 20×   20× 20×                                       114×   16× 16× 16×   16×                                                                         12×                                       16× 16×                             81× 81×                                                                 256× 35×     35× 35× 35× 35× 35×                                 35×                         35×           221× 221× 221× 221× 221× 221× 221×     221×       221×     221× 221× 221×       221×   221× 17× 17× 17× 17× 17× 17× 17× 17×       54× 54× 54× 258×         258×   54×   332× 332× 332× 332× 7304× 3984×   1734×       332×   335×           57× 57×                       11× 11× 11× 11× 11×   11×     11×       11× 11× 11×   11×                                                                                                           57× 57×   57× 57× 26×                 26× 26×                         57× 57× 57×       39×     18×     57×         57× 57× 57× 57×                                                 24×   16× 16× 16× 16×             16× 16×     16×   16× 16× 16× 16× 16×         16× 16× 16× 16× 16× 16×                                                                                                                                               87×     87×   87×     87×   179× 15×   179× 15×   179× 16×   179×   179× 15×   179× 15×   179× 179× 15×   179× 179× 15×   179× 179×   179× 179×     179× 179×          
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-inputs", "../../common/base/css-constant", "@syncfusion/ej2-navigations", "@syncfusion/ej2-navigations", "../../common/base/constant", "@syncfusion/ej2-navigations", "@syncfusion/ej2-dropdowns", "../../base/util"], function (require, exports, ej2_popups_1, ej2_base_1, ej2_base_2, ej2_buttons_1, ej2_inputs_1, cls, ej2_navigations_1, ej2_navigations_2, events, ej2_navigations_3, ej2_dropdowns_1, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var COUNT = 'Count';
    var AVG = 'Avg';
    var MEDIAN = 'Median';
    var MIN = 'Min';
    var MAX = 'Max';
    var SUM = 'Sum';
    var DISTINCTCOUNT = 'DistinctCount';
    var PRODUCT = 'Product';
    var STDEV = 'SampleStDev';
    var STDEVP = 'PopulationStDev';
    var VAR = 'SampleVar';
    var VARP = 'PopulationVar';
    var CALC = 'CalculatedField';
    var AGRTYPE = 'AggregateType';
    var CalculatedField = (function () {
        function CalculatedField(parent) {
            this.isFormula = false;
            this.isRequireUpdate = false;
            this.formatTypes = ['Standard', 'Currency', 'Percent', 'Custom', 'None'];
            this.parent = parent;
            this.existingReport = null;
            this.parent.calculatedFieldModule = this;
            this.removeEventListener();
            this.addEventListener();
            this.parentID = this.parent.element.id;
            this.treeObj = null;
            this.droppable = null;
            this.newFields = null;
            this.isFieldExist = true;
            this.formulaText = null;
            this.fieldText = null;
            this.formatText = null;
            this.formatType = null;
            this.fieldType = null;
            this.parentHierarchy = null;
            this.isEdit = false;
            this.currentFieldName = null;
        }
        CalculatedField.prototype.getModuleName = function () {
            return 'calculatedField';
        };
        CalculatedField.prototype.keyActionHandler = function (e) {
            var node = e.currentTarget.querySelector('.e-node-focus');
            Eif (node) {
                switch (e.action) {
                    case 'moveRight':
                    case 'shiftE':
                        Eif (this.parent.dataType === 'pivot') {
                            this.displayMenu(node);
                        }
                        break;
                    case 'delete':
                        if (node.tagName === 'LI' && !node.querySelector('.e-list-icon.e-format') && !node.querySelector('.e-list-icon').classList.contains('.e-icons') && (node.querySelector('.' + cls.GRID_REMOVE) &&
                            node.querySelector('.' + cls.GRID_REMOVE).classList.contains('e-list-icon'))) {
                            this.createConfirmDialog(this.parent.localeObj.getConstant('alert'), this.parent.localeObj.getConstant('removeCalculatedField'), {}, true, node);
                        }
                        break;
                    case 'enter':
                        {
                            var field = node.getAttribute('data-field');
                            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
                            var type = node.getAttribute('data-type');
                            var dropField = ej2_base_1.select('#' + this.parentID + 'droppable', dialog.element);
                            Eif (this.parent.dataType === 'pivot') {
                                if (dropField.value === '') {
                                    Iif (type === CALC) {
                                        dropField.value = node.getAttribute('data-uid');
                                    }
                                    else {
                                        dropField.value = '"' + type + '(' + field + ')' + '"';
                                    }
                                }
                                else Eif (dropField.value !== '') {
                                    Iif (type === CALC) {
                                        dropField.value = dropField.value + node.getAttribute('data-uid');
                                    }
                                    else {
                                        dropField.value = dropField.value + '"' + type + '(' + field + ')' + '"';
                                    }
                                }
                            }
                            else {
                                if (this.parent.olapEngineModule && this.parent.olapEngineModule.fieldList[field] &&
                                    this.parent.olapEngineModule.fieldList[field].isCalculatedField) {
                                    field = this.parent.olapEngineModule.fieldList[field].tag;
                                }
                                if (dropField.value === '') {
                                    dropField.value = field;
                                }
                                else if (dropField.value !== '') {
                                    dropField.value = dropField.value + field;
                                }
                            }
                        }
                        break;
                }
            }
        };
        CalculatedField.prototype.fieldClickHandler = function (e) {
            var node = ej2_base_1.closest(e.event.target, 'li');
            if (e.event.target.classList.contains(cls.FORMAT) ||
                e.event.target.classList.contains(cls.CALC_EDIT) ||
                e.event.target.classList.contains(cls.CALC_EDITED) ||
                e.event.target.classList.contains(cls.GRID_REMOVE)) {
                Eif (!this.parent.isAdaptive) {
                    this.displayMenu(node, e.node, e.event.target);
                }
                else if (this.parent.dataType === 'olap' && this.parent.isAdaptive) {
                    if (node.tagName === 'LI' && node.querySelector('.e-list-edit-icon').classList.contains(cls.CALC_EDIT) && e.event.target.classList.contains(cls.CALC_EDIT)) {
                        this.isEdit = true;
                        this.currentFieldName = node.getAttribute('data-field');
                        this.fieldText = node.getAttribute('data-caption');
                        this.formulaText = node.getAttribute('data-formula');
                        this.formatType = node.getAttribute('data-formatString');
                        this.formatText = this.formatType === 'Custom' ? node.getAttribute('data-customformatstring') : null;
                        this.fieldType = node.getAttribute('data-membertype');
                        this.parentHierarchy = this.fieldType === 'Dimension' ? node.getAttribute('data-hierarchy') : null;
                        ej2_base_1.addClass([node.querySelector('.e-list-edit-icon')], cls.CALC_EDITED);
                        ej2_base_2.removeClass([node.querySelector('.e-list-edit-icon')], cls.CALC_EDIT);
                        this.renderMobileLayout(this.parent.dialogRenderer.adaptiveElement);
                    }
                    else if (node.tagName === 'LI' && node.querySelector('.e-list-edit-icon').classList.contains(cls.CALC_EDITED) && e.event.target.classList.contains(cls.CALC_EDITED)) {
                        this.isEdit = false;
                        this.fieldText = this.formatText = this.formulaText = this.currentFieldName = null;
                        this.parentHierarchy = this.fieldType = this.formatType = null;
                        ej2_base_1.addClass([node.querySelector('.e-list-edit-icon')], cls.CALC_EDIT);
                        ej2_base_2.removeClass([node.querySelector('.e-list-edit-icon')], cls.CALC_EDITED);
                    }
                    else if (node.tagName === 'LI' && node.querySelector('.' + cls.GRID_REMOVE).classList.contains('e-icons') && e.event.target.classList.contains(cls.GRID_REMOVE)) {
                        this.createConfirmDialog(this.parent.localeObj.getConstant('alert'), this.parent.localeObj.getConstant('removeCalculatedField'), {}, true, e.node);
                    }
                }
            }
        };
        CalculatedField.prototype.accordionClickHandler = function (e) {
            if (e.item && e.item.iconCss.indexOf('e-list-icon') !== -1 &&
                ej2_base_1.closest(e.originalEvent.target, '.e-acrdn-header-icon')) {
                var node = ej2_base_1.closest(e.originalEvent.target, '.e-acrdn-header').querySelector('.' + cls.CALCCHECK);
                var fieldName = node.getAttribute('data-field');
                var captionName = node.getAttribute('data-caption');
                var formatObj = util_1.PivotUtil.getFieldByName(fieldName, this.parent.dataSourceSettings.formatSettings);
                var optionElement = ej2_base_1.closest(e.originalEvent.target, '.e-acrdn-header-icon');
                Iif (formatObj) {
                    var pivotFormat = this.getFormat(formatObj.format);
                    var formatString = (pivotFormat ? this.formatTypes.indexOf(pivotFormat) > -1 ?
                        formatObj.format : 'Custom' : 'None');
                    this.formatType = formatString;
                }
                Eif (optionElement.querySelector('.' + cls.CALC_EDIT) && e.originalEvent.target.classList.contains(cls.CALC_EDIT)) {
                    this.isEdit = true;
                    this.currentFieldName = fieldName;
                    this.fieldText = captionName ? captionName : fieldName;
                    this.formulaText = this.parent.engineModule.fieldList[fieldName].formula;
                    this.formatText = formatObj ? formatObj.format : '';
                    ej2_base_1.addClass([optionElement.querySelector('.e-list-icon')], cls.CALC_EDITED);
                    ej2_base_2.removeClass([optionElement.querySelector('.e-list-icon')], cls.CALC_EDIT);
                    this.renderMobileLayout(this.parent.dialogRenderer.adaptiveElement);
                }
                else if (optionElement.querySelector('.' + cls.CALC_EDITED) &&
                    e.originalEvent.target.classList.contains(cls.CALC_EDITED)) {
                    this.isEdit = false;
                    this.fieldText = this.formatText = this.formulaText = this.currentFieldName = null;
                    ej2_base_1.addClass([optionElement.querySelector('.e-list-icon')], cls.CALC_EDIT);
                    ej2_base_2.removeClass([optionElement.querySelector('.e-list-icon')], cls.CALC_EDITED);
                }
                else if (optionElement.querySelector('.' + cls.GRID_REMOVE) &&
                    e.originalEvent.target.classList.contains(cls.GRID_REMOVE)) {
                    this.createConfirmDialog(this.parent.localeObj.getConstant('alert'), this.parent.localeObj.getConstant('removeCalculatedField'), {}, true, node);
                }
            }
        };
        CalculatedField.prototype.accordionCreated = function () {
            var accordion = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'accordDiv', document), ej2_navigations_3.Accordion);
            var allElement = accordion.element.querySelectorAll('.e-acrdn-item');
            for (var i = 0; i < allElement.length; i++) {
                if (allElement[i].querySelector('.' + cls.CALC_EDIT) || allElement[i].querySelector('.' + cls.CALC_EDITED)) {
                    var element = ej2_base_1.createElement('span', {
                        className: 'e-list-icon ' + cls.GRID_REMOVE + ' e-icons'
                    });
                    ej2_base_2.append([element], allElement[i].querySelector('.e-acrdn-header-icon'));
                    ej2_base_1.addClass([allElement[i]], cls.SELECT_CLASS);
                }
            }
        };
        CalculatedField.prototype.clearFormula = function () {
            Eif (this.treeObj && this.treeObj.element.querySelector('li')) {
                ej2_base_2.removeClass(this.treeObj.element.querySelectorAll('li'), 'e-active');
                this.displayMenu(this.treeObj.element.querySelector('li'));
            }
        };
        CalculatedField.prototype.displayMenu = function (node, treeNode, target) {
            var edit = target ? target.classList.contains(cls.CALC_EDIT) : true;
            var edited = target ? target.classList.contains(cls.CALC_EDITED) : true;
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
            try {
                if (this.parent.dataType === 'pivot' && node.querySelector('.e-list-icon.e-format') &&
                    node.querySelector('.e-list-icon.e-format').classList.contains(cls.ICON) &&
                    !node.querySelector('.e-list-icon').classList.contains(cls.CALC_EDITED) &&
                    !node.querySelector('.e-list-icon').classList.contains(cls.GRID_REMOVE) &&
                    !node.querySelector('.e-list-icon').classList.contains(cls.CALC_EDIT) && node.tagName === 'LI') {
                    var menuObj = ej2_base_1.select('#' + this.parentID + 'CalcContextmenu', document) ?
                        ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'CalcContextmenu', document), ej2_navigations_2.ContextMenu) : null;
                    Iif (menuObj && !menuObj.isDestroyed) {
                        menuObj.destroy();
                    }
                    this.curMenu = node.querySelector('.' + cls.LIST_TEXT_CLASS);
                    this.openContextMenu(node);
                }
                else if (node.tagName === 'LI' && (node.querySelector('.' + cls.CALC_EDIT) &&
                    node.querySelector('.' + cls.CALC_EDIT).classList.contains('e-list-icon') && edit ||
                    (this.parent.dataType === 'olap' && node.getAttribute('data-type') === CALC && node.classList.contains('e-active') && ((target && !target.classList.contains(cls.GRID_REMOVE)) || !target)))) {
                    this.isEdit = true;
                    var fieldName = node.getAttribute('data-field');
                    var caption = node.getAttribute('data-caption');
                    this.currentFieldName = fieldName;
                    inputObj.value = caption;
                    inputObj.dataBind();
                    var formatString = node.getAttribute('data-formatString');
                    var dialogElement = dialog.element;
                    var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                    var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement), ej2_inputs_1.MaskedTextBox);
                    var customFormatString = node.getAttribute('data-customformatstring');
                    if (this.parent.dataType === 'olap') {
                        var memberType = node.getAttribute('data-membertype');
                        var parentHierarchy = node.getAttribute('data-hierarchy');
                        var expression = node.getAttribute('data-formula');
                        var fieldTitle = ej2_base_1.select('#' + this.parentID + '_' + 'FieldNameTitle', dialogElement);
                        var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                        var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                        fieldTitle.innerText = this.parent.localeObj.getConstant('caption');
                        ej2_base_1.select('#' + this.parentID + 'droppable', document).value = expression;
                        memberTypeDrop.readonly = true;
                        memberTypeDrop.value = memberType;
                        memberTypeDrop.dataBind();
                        Iif (memberType === 'Dimension') {
                            hierarchyDrop.value = parentHierarchy;
                        }
                    }
                    else {
                        ej2_base_1.addClass(this.treeObj.element.querySelectorAll('.' + cls.CALC_EDITED), cls.CALC_EDIT);
                        ej2_base_2.removeClass(this.treeObj.element.querySelectorAll('.' + cls.CALC_EDITED), cls.CALC_EDITED);
                        ej2_base_1.addClass([node.querySelector('.e-list-icon')], cls.CALC_EDITED);
                        ej2_base_2.removeClass([node.querySelector('.e-list-icon')], cls.CALC_EDIT);
                        node.querySelector('.' + cls.CALC_EDITED).setAttribute('title', this.parent.localeObj.getConstant('clearCalculatedField'));
                        ej2_base_1.select('#' + this.parentID + 'droppable', document).value = node.getAttribute('data-uid');
                    }
                    if (formatString !== '') {
                        ddlFormatTypes.value = formatString;
                        ddlFormatTypes.dataBind();
                    }
                    customFormat.value = customFormatString;
                    customFormat.dataBind();
                }
                else if (node.tagName === 'LI' && (node.querySelector('.' + cls.CALC_EDITED) &&
                    node.querySelector('.' + cls.CALC_EDITED).classList.contains('e-list-icon') && edited ||
                    (this.parent.dataType === 'olap' && !node.classList.contains('e-active')))) {
                    this.isEdit = false;
                    inputObj.value = '';
                    inputObj.dataBind();
                    var dialogElement = dialog.element;
                    var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement), ej2_inputs_1.MaskedTextBox);
                    customFormat.value = '';
                    customFormat.dataBind();
                    if (this.parent.dataType === 'olap') {
                        var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                        var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                        var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                        var fieldTitle = ej2_base_1.select('#' + this.parentID + '_' + 'FieldNameTitle', dialogElement);
                        fieldTitle.innerText = this.parent.localeObj.getConstant('fieldTitle');
                        hierarchyDrop.index = 0;
                        hierarchyDrop.dataBind();
                        ddlFormatTypes.index = 0;
                        ddlFormatTypes.dataBind();
                        memberTypeDrop.index = 0;
                        memberTypeDrop.readonly = false;
                        memberTypeDrop.dataBind();
                    }
                    else {
                        ej2_base_1.addClass(this.treeObj.element.querySelectorAll('.' + cls.CALC_EDITED), cls.CALC_EDIT);
                        ej2_base_2.removeClass(this.treeObj.element.querySelectorAll('.' + cls.CALC_EDITED), cls.CALC_EDITED);
                        node.querySelector('.' + cls.CALC_EDIT).setAttribute('title', this.parent.localeObj.getConstant('edit'));
                    }
                    ej2_base_1.select('#' + this.parentID + 'droppable', document).value = '';
                }
                else Eif (node.tagName === 'LI' && (node.querySelector('.' + cls.GRID_REMOVE) &&
                    node.querySelector('.' + cls.GRID_REMOVE).classList.contains('e-list-icon')) && !edit && !edited) {
                    this.parent.actionObj.actionName = events.removeField;
                    Iif (this.parent.actionBeginMethod()) {
                        return;
                    }
                    var dropField = ej2_base_1.select('#' + this.parentID + 'droppable', document);
                    var field = {
                        name: this.isEdit ? this.currentFieldName : inputObj.value,
                        caption: inputObj.value,
                        formula: dropField.value
                    };
                    this.createConfirmDialog(this.parent.localeObj.getConstant('alert'), this.parent.localeObj.getConstant('removeCalculatedField'), field, true, treeNode);
                }
            }
            catch (execption) {
                this.parent.actionFailureMethod(execption);
            }
        };
        CalculatedField.prototype.removeCalcField = function (node) {
            var dataSourceSettings = this.parent.dataSourceSettings;
            var fieldName = node.getAttribute('data-field');
            var calcfields = dataSourceSettings.calculatedFieldSettings;
            var engineModule;
            Iif (this.parent.dataType === 'pivot') {
                if (!this.parent.isAdaptive) {
                    this.treeObj.removeNodes([node]);
                }
                else {
                    var index = parseInt(node.getAttribute('id').split(this.parentID + '_')[1], 10);
                    if (typeof index === 'number') {
                        var accordion = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'accordDiv', document), ej2_navigations_3.Accordion);
                        accordion.hideItem(index);
                    }
                }
            }
            for (var i = 0; i < calcfields.length; i++) {
                if (calcfields[i] && calcfields[i].name === fieldName) {
                    calcfields.splice(i, 1);
                    break;
                }
            }
            Eif (this.parent.dataType === 'olap') {
                engineModule = this.parent.olapEngineModule;
                var fields_1 = engineModule.fieldListData ?
                    engineModule.fieldListData : [];
                for (var _i = 0, _a = Object.keys(fields_1); _i < _a.length; _i++) {
                    var item = _a[_i];
                    if (fields_1[parseInt(item, 10)].name === fieldName) {
                        var index = parseInt(item, 10);
                        Eif (typeof (index) === 'number') {
                            fields_1.splice(index, 1);
                            break;
                        }
                    }
                }
                var parentID = this.treeObj.getNode(node).parentID;
                this.treeObj.removeNodes([node]);
                Iif (calcfields.length <= 0) {
                    this.treeObj.removeNodes([parentID]);
                }
            }
            else {
                engineModule = this.parent.engineModule;
            }
            Iif (engineModule.fields) {
                for (var i = 0; i < engineModule.fields.length; i++) {
                    if (engineModule.fields[i] === fieldName) {
                        engineModule.fields.splice(i, 1);
                        break;
                    }
                }
            }
            Eif (engineModule.savedFieldList && engineModule.savedFieldList[fieldName]) {
                delete engineModule.savedFieldList[fieldName];
            }
            Iif (engineModule.fieldList && engineModule.fieldList[fieldName]) {
                delete engineModule.fieldList[fieldName];
            }
            var formatFields = dataSourceSettings.formatSettings;
            for (var i = 0; i < formatFields.length; i++) {
                if (formatFields[i] && formatFields[i].name === fieldName) {
                    formatFields.splice(i, 1);
                    break;
                }
            }
            var fields = [dataSourceSettings.values, dataSourceSettings.rows, dataSourceSettings.columns, dataSourceSettings.filters];
            for (var i = 0, n = fields.length; i < n; i++) {
                for (var j = 0, length_1 = fields[i].length; j < length_1; j++) {
                    Iif (fields[i][j].name === fieldName) {
                        fields[i].splice(j, 1);
                        break;
                    }
                }
            }
            Eif (this.isEdit && this.currentFieldName === fieldName) {
                var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
                this.isEdit = false;
                inputObj.value = '';
                this.currentFieldName = this.formatText = this.fieldText = this.formatType = null;
                this.formulaText = this.fieldType = this.parentHierarchy = null;
            }
            Eif ((!ej2_base_2.isNullOrUndefined(this.parent.isDeferLayoutUpdate) &&
                !this.parent.isDeferLayoutUpdate) || (this.parent.pivotGridModule &&
                !this.parent.pivotGridModule.pivotDeferLayoutUpdate) || this.parent.getModuleName() !== 'pivotfieldlist') {
                this.parent.updateDataSource();
            }
            this.closeErrorDialog();
        };
        CalculatedField.prototype.openContextMenu = function (node) {
            var _this = this;
            var fieldName = node.getAttribute('data-field');
            var type = this.parent.engineModule.fieldList[fieldName].type !== 'number' ? 'string' : 'number';
            var validSummaryTypes = (type === 'string' ? this.getValidSummaryType().slice(0, 2) : this.getValidSummaryType());
            var eventArgs = {
                cancel: false, fieldName: fieldName,
                aggregateTypes: this.getMenuItems(type).slice()
            };
            var control = this.parent.getModuleName() === 'pivotfieldlist' && this.parent.isPopupView ?
                this.parent.pivotGridModule : this.parent;
            control.trigger(events.aggregateMenuOpen, eventArgs, function (observedArgs) {
                Eif (!observedArgs.cancel) {
                    var duplicateTypes = [];
                    var items = [];
                    for (var _i = 0, _a = observedArgs.aggregateTypes; _i < _a.length; _i++) {
                        var option = _a[_i];
                        Eif (validSummaryTypes.indexOf(option) > -1 && duplicateTypes.indexOf(option) === -1) {
                            duplicateTypes.push(option);
                            items.push({
                                id: _this.parent.element.id + 'Calc_' + option,
                                text: _this.parent.localeObj.getConstant(option)
                            });
                        }
                    }
                    _this.createMenu(items, node);
                    var pos = node.getBoundingClientRect();
                    var offset = window.scrollY || document.documentElement.scrollTop;
                    var menuObj = ej2_base_1.getInstance(ej2_base_1.select('#' + _this.parentID + 'CalcContextmenu', document), ej2_navigations_2.ContextMenu);
                    if (_this.parent.enableRtl) {
                        menuObj.open(pos.top + offset, pos.left - 100);
                    }
                    else {
                        menuObj.open(pos.top + offset, pos.left + 150);
                    }
                }
            });
        };
        CalculatedField.prototype.selectContextMenu = function (menu) {
            Eif (menu.element.textContent !== null) {
                var field = ej2_base_1.closest(this.curMenu, '.e-list-item').getAttribute('data-caption');
                ej2_base_1.closest(this.curMenu, '.e-list-item').setAttribute('data-type', menu.element.id.split('_').pop());
                this.curMenu.textContent = field + ' (' + menu.element.textContent + ')';
                ej2_base_1.addClass([this.curMenu.parentElement.parentElement], ['e-node-focus', 'e-hover']);
                this.curMenu.parentElement.parentElement.setAttribute('tabindex', '0');
                this.curMenu.parentElement.parentElement.focus();
            }
        };
        CalculatedField.prototype.createMenu = function (menuItems, node) {
            var _this = this;
            var menuOptions = {
                cssClass: this.parentID + 'calculatedmenu' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                items: menuItems,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                select: this.selectContextMenu.bind(this),
                onClose: function () {
                    _this.treeObj.element.focus();
                    ej2_base_1.addClass([node], ['e-hover', 'e-node-focus']);
                }
            };
            var contextMenu;
            Iif (ej2_base_1.select('#' + this.parentID + 'CalcContextmenu', document)) {
                contextMenu = ej2_base_1.select('#' + this.parentID + 'CalcContextmenu', document);
            }
            else {
                contextMenu = ej2_base_1.createElement('ul', {
                    id: this.parentID + 'CalcContextmenu'
                });
            }
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            dialog.element.appendChild(contextMenu);
            var menuObj = new ej2_navigations_2.ContextMenu(menuOptions);
            menuObj.isStringTemplate = true;
            menuObj.appendTo(contextMenu);
        };
        CalculatedField.prototype.applyFormula = function () {
            var _this = this;
            var currentObj = this;
            var isExist = false;
            ej2_base_2.removeClass([document.getElementById(this.parentID + 'ddlelement')], cls.EMPTY_FIELD);
            var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
            this.newFields =
                ej2_base_1.extend([], this.parent.dataSourceSettings.calculatedFieldSettings, null, true);
            var eventArgs = {
                fieldName: this.isEdit ? this.currentFieldName : inputObj.value,
                calculatedField: this.getCalculatedFieldInfo(),
                calculatedFieldSettings: util_1.PivotUtil.cloneCalculatedFieldSettings(this.parent.dataSourceSettings.calculatedFieldSettings),
                cancel: false
            };
            var control = this.parent.getModuleName() === 'pivotfieldlist' &&
                this.parent.isPopupView ? this.parent.pivotGridModule : this.parent;
            control.trigger(events.calculatedFieldCreate, eventArgs, function (observedArgs) {
                Eif (!observedArgs.cancel) {
                    var calcInfo = observedArgs.calculatedField;
                    if (!_this.isEdit) {
                        if (currentObj.parent.dataType === 'olap') {
                            var field = calcInfo.name;
                            Iif (currentObj.parent.olapEngineModule.fieldList[field] &&
                                currentObj.parent.olapEngineModule.fieldList[field].type !== 'CalculatedField') {
                                isExist = true;
                            }
                        }
                        else {
                            for (var _i = 0, _a = Object.keys(currentObj.parent.engineModule.fieldList); _i < _a.length; _i++) {
                                var key = _a[_i];
                                if (calcInfo.name && calcInfo.name === key &&
                                    currentObj.parent.engineModule.fieldList[key].aggregateType !== 'CalculatedField') {
                                    isExist = true;
                                }
                            }
                        }
                    }
                    if (isExist) {
                        currentObj.parent.pivotCommon.errorDialog.createErrorDialog(currentObj.parent.localeObj.getConstant('error'), currentObj.parent.localeObj.getConstant('fieldExist'));
                        return;
                    }
                    _this.existingReport = ej2_base_1.extend({}, _this.parent.dataSourceSettings, null, true);
                    var report = _this.parent.dataSourceSettings;
                    if (!ej2_base_2.isNullOrUndefined(calcInfo.name) && calcInfo.name !== '' &&
                        !ej2_base_2.isNullOrUndefined(calcInfo.caption) && calcInfo.caption !== '' && calcInfo.formula && calcInfo.formula !== '') {
                        var field = void 0;
                        if (_this.parent.dataType === 'olap') {
                            field = {
                                name: calcInfo.name,
                                formula: calcInfo.formula,
                                formatString: calcInfo.formatString
                            };
                            Iif (!ej2_base_2.isNullOrUndefined(calcInfo.hierarchyUniqueName)) {
                                field.hierarchyUniqueName = calcInfo.hierarchyUniqueName;
                            }
                            _this.isFieldExist = false;
                            Eif (!_this.isEdit) {
                                for (var i = 0; i < report.calculatedFieldSettings.length; i++) {
                                    Iif (report.calculatedFieldSettings[i].name === field.name) {
                                        _this.createConfirmDialog(currentObj.parent.localeObj.getConstant('alert'), currentObj.parent.localeObj.getConstant('confirmText'), calcInfo);
                                        return;
                                    }
                                }
                            }
                            else {
                                for (var i = 0; i < report.calculatedFieldSettings.length; i++) {
                                    if (report.calculatedFieldSettings[i].name === field.name && _this.isEdit) {
                                        report.calculatedFieldSettings[i].hierarchyUniqueName = calcInfo.hierarchyUniqueName;
                                        _this.parent.olapEngineModule.fieldList[field.name].caption = calcInfo.caption;
                                        report.calculatedFieldSettings[i].formatString = field.formatString;
                                        report.calculatedFieldSettings[i].formula = field.formula;
                                        field = report.calculatedFieldSettings[i];
                                        _this.updateFormatSettings(report, field.name, calcInfo.formatString);
                                        _this.parent.olapEngineModule.getFormattedFields(report.formatSettings);
                                        if (_this.parent.olapEngineModule.formatFields[field.name]) {
                                            if (_this.parent.olapEngineModule.formatFields[field.name].format) {
                                                _this.parent.olapEngineModule.formatFields[field.name].format =
                                                    _this.getFormat(field.formatString);
                                            }
                                            else {
                                                delete _this.parent.olapEngineModule.formatFields[field.name];
                                            }
                                        }
                                        _this.isFieldExist = true;
                                        break;
                                    }
                                }
                                var axisFields = [report.rows, report.columns, report.values, report.filters];
                                var isFieldExist = false;
                                for (var _b = 0, axisFields_1 = axisFields; _b < axisFields_1.length; _b++) {
                                    var fields = axisFields_1[_b];
                                    for (var _c = 0, fields_2 = fields; _c < fields_2.length; _c++) {
                                        var item = fields_2[_c];
                                        if (item.isCalculatedField && field.name !== null &&
                                            item.name === field.name && _this.isEdit) {
                                            item.caption = calcInfo.caption;
                                            _this.isFieldExist = true;
                                            isFieldExist = true;
                                            break;
                                        }
                                    }
                                    if (isFieldExist) {
                                        break;
                                    }
                                }
                            }
                            Eif (!_this.isFieldExist) {
                                report.calculatedFieldSettings.push(field);
                                _this.updateFormatSettings(report, field.name, calcInfo.formatString);
                                _this.parent.olapEngineModule.getFormattedFields(report.formatSettings);
                                Eif (_this.parent.olapEngineModule.formatFields[field.name]) {
                                    Eif (_this.parent.olapEngineModule.formatFields[field.name].format) {
                                        _this.parent.olapEngineModule.formatFields[field.name].format = _this.getFormat(field.formatString);
                                    }
                                    else {
                                        delete _this.parent.olapEngineModule.formatFields[field.name];
                                    }
                                }
                            }
                            _this.parent.lastCalcFieldInfo = field;
                        }
                        else {
                            field = {
                                name: calcInfo.name,
                                caption: calcInfo.caption,
                                type: 'CalculatedField'
                            };
                            var cField = {
                                name: calcInfo.name,
                                formula: calcInfo.formula
                            };
                            Iif (!ej2_base_2.isNullOrUndefined(calcInfo.formatString)) {
                                cField.formatString = calcInfo.formatString;
                            }
                            _this.isFieldExist = true;
                            if (!_this.isEdit) {
                                for (var i = 0; i < report.values.length; i++) {
                                    if (report.values[i].type === CALC && report.values[i].name === field.name) {
                                        for (var j = 0; j < report.calculatedFieldSettings.length; j++) {
                                            Eif (report.calculatedFieldSettings[j].name === field.name) {
                                                _this.createConfirmDialog(currentObj.parent.localeObj.getConstant('alert'), currentObj.parent.localeObj.getConstant('confirmText'), calcInfo);
                                                return;
                                            }
                                        }
                                        _this.isFieldExist = false;
                                    }
                                }
                            }
                            else {
                                for (var i = 0; i < report.values.length; i++) {
                                    if (report.values[i].type === CALC && field.name !== null &&
                                        report.values[i].name === field.name && _this.isEdit) {
                                        for (var j = 0; j < report.calculatedFieldSettings.length; j++) {
                                            if (report.calculatedFieldSettings[j].name === field.name) {
                                                report.values.splice(i, 1);
                                                report.values.splice(i, 0, field);
                                                _this.currentFormula = report.calculatedFieldSettings[j].formula;
                                                report.calculatedFieldSettings.splice(j, 1);
                                                report.calculatedFieldSettings.splice(j, 0, cField);
                                                _this.updateFormatSettings(report, field.name, calcInfo.formatString);
                                                _this.isFieldExist = false;
                                            }
                                        }
                                    }
                                }
                            }
                            if (_this.isFieldExist) {
                                report.values.push(field);
                                report.calculatedFieldSettings.push(cField);
                                _this.updateFormatSettings(report, field.name, calcInfo.formatString);
                            }
                            _this.parent.lastCalcFieldInfo = cField;
                        }
                        _this.addFormula(report, field.name);
                    }
                    else {
                        Eif (ej2_base_2.isNullOrUndefined(calcInfo.name) || calcInfo.name === '' ||
                            ej2_base_2.isNullOrUndefined(calcInfo.caption) || calcInfo.caption === '') {
                            var inputObj_1 = ej2_base_1.getInstance(ej2_base_1.select('#' + _this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
                            inputObj_1.value = '';
                            ej2_base_1.addClass([document.getElementById(_this.parentID + 'ddlelement')], cls.EMPTY_FIELD);
                            document.getElementById(_this.parentID + 'ddlelement').focus();
                        }
                        else {
                            _this.parent.pivotCommon.errorDialog.createErrorDialog(_this.parent.localeObj.getConstant('error'), _this.parent.localeObj.getConstant('invalidFormula'));
                        }
                    }
                }
                else {
                    _this.endDialog();
                    _this.parent.lastCalcFieldInfo = {};
                    _this.isFormula = false;
                }
            });
        };
        CalculatedField.prototype.getCalculatedFieldInfo = function () {
            var element = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document);
            var dialog = element ? ej2_base_1.getInstance(element, ej2_popups_1.Dialog) : undefined;
            var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
            var dropField = ej2_base_1.select('#' + this.parentID + 'droppable', document);
            var dialogElement = this.parent.isAdaptive ?
                this.parent.dialogRenderer.adaptiveElement.element : dialog.element;
            var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement), ej2_inputs_1.MaskedTextBox);
            var field = {
                name: this.isEdit ? this.currentFieldName : inputObj.value,
                caption: inputObj.value,
                formula: dropField.value
            };
            var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement), ej2_dropdowns_1.DropDownList);
            field.formatString = (ddlFormatTypes.value === 'Custom' ? customFormat.value : (ddlFormatTypes.value === 'None' ? null : ddlFormatTypes.value));
            if (this.parent.dataType === 'olap') {
                var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                Iif (memberTypeDrop.value === 'Dimension') {
                    field.hierarchyUniqueName = hierarchyDrop.value;
                }
            }
            return field;
        };
        CalculatedField.prototype.updateFormatSettings = function (report, fieldName, formatString) {
            var newFormat = { name: fieldName, format: formatString, useGrouping: true };
            var isFormatExist = false;
            for (var i = 0; i < report.formatSettings.length; i++) {
                Iif (report.formatSettings[i].name === fieldName) {
                    if (formatString === 'undefined' || formatString === undefined || formatString === '') {
                        report.formatSettings.splice(i, 1);
                        isFormatExist = true;
                        break;
                    }
                    else {
                        var formatObj = report.formatSettings[i].properties ?
                            report.formatSettings[i].properties : report.formatSettings[i];
                        formatObj.format = formatString;
                        report.formatSettings.splice(i, 1, formatObj);
                        isFormatExist = true;
                        break;
                    }
                }
            }
            if (!isFormatExist && formatString !== '' && !ej2_base_2.isNullOrUndefined(formatString)) {
                report.formatSettings.push(newFormat);
            }
        };
        CalculatedField.prototype.addFormula = function (report, field) {
            this.isFormula = true;
            this.field = field;
            this.parent.setProperties({ dataSourceSettings: report }, true);
            Iif (this.parent.getModuleName() === 'pivotfieldlist' && (this.parent.isDeferLayoutUpdate ||
                (this.parent.pivotGridModule && this.parent.pivotGridModule.pivotDeferLayoutUpdate))) {
                this.parent.isRequiredUpdate = false;
            }
            try {
                var actionInfo = {
                    calculatedFieldInfo: this.parent.lastCalcFieldInfo
                };
                this.parent.actionObj.actionInfo = actionInfo;
                var actionName = (this.parent.actionObj.actionName === events.editCalculatedField) ?
                    events.calculatedFieldEdited : events.calculatedFieldApplied;
                this.parent.actionObj.actionName = actionName;
                this.parent.updateDataSource(false);
                var pivot = (this.parent.getModuleName() === 'pivotfieldlist' && this.parent.pivotGridModule) ?
                    this.parent.pivotGridModule : this.parent;
                Eif (pivot && pivot.dataSourceSettings.mode !== 'Server') {
                    this.endDialog();
                }
                else {
                    this.isRequireUpdate = true;
                }
                Iif (this.parent.getModuleName() === 'pivotfieldlist' &&
                    this.parent.renderMode === 'Fixed' && this.parent.isDeferLayoutUpdate) {
                    this.parent.pivotChange = true;
                }
            }
            catch (exception) {
                this.showError();
            }
        };
        CalculatedField.prototype.endDialog = function () {
            this.isEdit = false;
            var element = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document);
            var dialog = element ? ej2_base_1.getInstance(element, ej2_popups_1.Dialog) : undefined;
            if (dialog) {
                dialog.close();
            }
            else {
                var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
                inputObj.value = '';
                this.currentFieldName = this.formatText = this.fieldText = this.formatType = null;
                this.formulaText = this.fieldType = this.parentHierarchy = null;
                var dialogElement = this.parent.isAdaptive ?
                    this.parent.dialogRenderer.parentElement : dialog.element;
                this.parent.dialogRenderer.parentElement.querySelector('.' + cls.CALCINPUT).value = '';
                ej2_base_1.select('#' + this.parentID + 'droppable', this.parent.dialogRenderer.parentElement).value = '';
                ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', this.parent.dialogRenderer.parentElement).value = '';
                Iif (this.parent.dataType === 'olap') {
                    var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                    var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                    memberTypeDrop.index = 0;
                    memberTypeDrop.readonly = false;
                    memberTypeDrop.dataBind();
                    hierarchyDrop.index = 0;
                    hierarchyDrop.enabled = false;
                    hierarchyDrop.dataBind();
                }
                var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement), ej2_inputs_1.MaskedTextBox);
                var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                ddlFormatTypes.index = this.parent.dataType === 'olap' ? 0 : 4;
                ddlFormatTypes.dataBind();
                customFormat.enabled = false;
                customFormat.dataBind();
            }
        };
        CalculatedField.prototype.showError = function () {
            Eif (this.parent.engineModule.fieldList[this.field]) {
                delete this.parent.engineModule.fieldList[this.field];
            }
            this.parent.pivotCommon.errorDialog.createErrorDialog(this.parent.localeObj.getConstant('error'), this.parent.localeObj.getConstant('invalidFormula'));
            this.parent.setProperties({ dataSourceSettings: this.existingReport }, true);
            Iif (this.isEdit) {
                var calcFields = this.parent.dataSourceSettings.calculatedFieldSettings;
                for (var i = 0; calcFields && i < calcFields.length; i++) {
                    if (calcFields[i].name === this.field) {
                        calcFields[i].formula = this.currentFormula;
                        break;
                    }
                }
            }
            else Eif (this.parent.engineModule.fields) {
                for (var i = 0; i < this.parent.engineModule.fields.length; i++) {
                    if (this.parent.engineModule.fields[i] === this.field) {
                        this.parent.engineModule.fields.splice(i, 1);
                        break;
                    }
                }
            }
            this.parent.lastCalcFieldInfo = {};
            this.parent.updateDataSource(false);
            this.isFormula = false;
        };
        CalculatedField.prototype.getFieldListData = function (parent) {
            var fields = [];
            if (this.parent.dataType === 'olap') {
                fields =
                    util_1.PivotUtil.getClonedData(parent.olapEngineModule.fieldListData ?
                        parent.olapEngineModule.fieldListData : []);
                for (var _i = 0, _a = fields; _i < _a.length; _i++) {
                    var item = _a[_i];
                    if (item.spriteCssClass &&
                        (item.spriteCssClass.indexOf('e-attributeCDB-icon') > -1 ||
                            item.spriteCssClass.indexOf('e-level-members') > -1)) {
                        item.hasChildren = true;
                    }
                    else if (item.spriteCssClass &&
                        (item.spriteCssClass.indexOf('e-namedSetCDB-icon') > -1)) {
                        item.hasChildren = false;
                    }
                    else if (item.spriteCssClass &&
                        (item.spriteCssClass.indexOf('e-calcMemberGroupCDB') > -1)) {
                        item.expanded = this.isEdit;
                    }
                }
            }
            else {
                for (var _b = 0, _c = (parent.engineModule.fieldList ? Object.keys(parent.engineModule.fieldList) : []); _b < _c.length; _b++) {
                    var key = _c[_b];
                    var type = null;
                    var typeVal = null;
                    var field = parent.engineModule.fieldList[key];
                    if ((field.type !== 'number' || parent.engineModule.fieldList[key].type === 'include' || parent.engineModule.fieldList[key].type === 'exclude') && field.aggregateType !== 'DistinctCount') {
                        typeVal = COUNT;
                    }
                    else {
                        typeVal = field.aggregateType !== undefined ?
                            (field.aggregateType) : SUM;
                    }
                    type = this.parent.localeObj.getConstant(typeVal);
                    fields.push({
                        index: field.index,
                        name: (this.parent.enableHtmlSanitizer ?
                            ej2_base_1.SanitizeHtmlHelper.sanitize(field.caption) : field.caption) + ' (' + type + ')',
                        type: typeVal,
                        icon: cls.FORMAT + ' ' + cls.ICON,
                        formula: (this.parent.enableHtmlSanitizer ?
                            ej2_base_1.SanitizeHtmlHelper.sanitize(field.formula) : field.formula),
                        field: (this.parent.enableHtmlSanitizer ?
                            ej2_base_1.SanitizeHtmlHelper.sanitize(key) : key),
                        caption: this.parent.enableHtmlSanitizer ?
                            ej2_base_1.SanitizeHtmlHelper.sanitize(field.caption ? field.caption : key) : field.caption ? field.caption : key
                    });
                }
            }
            return fields;
        };
        CalculatedField.prototype.fieldDropped = function (args) {
            args.cancel = true;
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            var dropField = ej2_base_1.select('#' + this.parentID + 'droppable', dialog.element);
            ej2_base_2.removeClass([dropField], 'e-copy-drop');
            ej2_base_2.removeClass([args.draggedNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.SELECTED_NODE_CLASS);
            var field = args.draggedNode.getAttribute('data-field');
            Iif (this.parent.dataType === 'olap') {
                if (this.parent.olapEngineModule.fieldList[field] &&
                    this.parent.olapEngineModule.fieldList[field].isCalculatedField) {
                    field = this.parent.olapEngineModule.fieldList[field].tag;
                }
                if (args.target.id === this.parentID + 'droppable' && dropField.value === '') {
                    dropField.value = field;
                    dropField.focus();
                }
                else if (args.target.id === (this.parentID + 'droppable') && dropField.value !== '') {
                    var currentValue = dropField.value;
                    var cursorPos = dropField.selectionStart;
                    var textAfterText = currentValue.substring(cursorPos, currentValue.length);
                    var textBeforeText = currentValue.substring(0, cursorPos);
                    var textCovered = textBeforeText + field;
                    dropField.value = textBeforeText + field + textAfterText;
                    dropField.focus();
                    dropField.setSelectionRange(textCovered.length, textCovered.length);
                }
                else {
                    args.cancel = true;
                }
            }
            else {
                var type = args.draggedNode.getAttribute('data-type');
                if (args.target.id === this.parentID + 'droppable' && dropField.value === '') {
                    if (type === CALC) {
                        dropField.value = args.draggedNodeData.id.toString();
                    }
                    else {
                        dropField.value = '"' + type + '(' + field + ')' + '"';
                    }
                    dropField.focus();
                }
                else if (args.target.id === (this.parentID + 'droppable') && dropField.value !== '') {
                    var textCovered = void 0;
                    var cursorPos = dropField.selectionStart;
                    var currentValue = dropField.value;
                    var textBeforeText = currentValue.substring(0, cursorPos);
                    var textAfterText = currentValue.substring(cursorPos, currentValue.length);
                    if (type === CALC) {
                        textCovered = textBeforeText + args.draggedNodeData.id.toString();
                        dropField.value = textBeforeText + args.draggedNodeData.id.toString() + textAfterText;
                    }
                    else {
                        textCovered = textBeforeText + '"' + type + '(' + field + ')' + '"';
                        dropField.value = textBeforeText + '"' + type + '(' + field + ')' + '"' + textAfterText;
                    }
                    dropField.focus();
                    dropField.setSelectionRange(textCovered.length, textCovered.length);
                }
                else {
                    args.cancel = true;
                }
            }
        };
        CalculatedField.prototype.createDialog = function () {
            var _this = this;
            if (ej2_base_1.select('#' + this.parentID + 'calculateddialog', document) !== null) {
                ej2_base_1.remove(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document));
                while (!ej2_base_2.isNullOrUndefined(document.querySelector('.' + this.parentID + 'calculatedmenu'))) {
                    ej2_base_1.remove(document.querySelector('.' + this.parentID + 'calculatedmenu'));
                }
            }
            var calculatedFieldElement = ej2_base_1.createElement('div', {
                id: this.parentID + 'calculateddialog',
                className: cls.CALCDIALOG + ' ' + (this.parent.dataType === 'olap' ? cls.OLAP_CALCDIALOG : '')
            });
            this.parent.element.appendChild(calculatedFieldElement);
            var calcButtons = [
                {
                    click: this.applyFormula.bind(this),
                    isFlat: false,
                    buttonModel: {
                        content: this.parent.localeObj.getConstant('ok'),
                        isPrimary: true,
                        cssClass: this.parent.cssClass
                    }
                },
                {
                    click: this.cancelClick.bind(this),
                    isFlat: false,
                    buttonModel: {
                        content: this.parent.localeObj.getConstant('cancel'),
                        cssClass: this.parent.cssClass
                    }
                }
            ];
            if (this.parent.dataType === 'olap') {
                var clearButton = {
                    click: this.clearFormula.bind(this),
                    isFlat: false,
                    buttonModel: {
                        cssClass: 'e-calc-clear-btn' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                        content: this.parent.localeObj.getConstant('clear')
                    }
                };
                calcButtons.splice(0, 0, clearButton);
            }
            var dialog = new ej2_popups_1.Dialog({
                allowDragging: true,
                position: { X: 'center', Y: 'center' },
                buttons: calcButtons,
                close: this.closeDialog.bind(this),
                beforeOpen: this.beforeOpen.bind(this),
                open: function () {
                    Eif (ej2_base_1.select('#' + _this.parentID + 'ddlelement', dialog.element)) {
                        ej2_base_1.select('#' + _this.parentID + 'ddlelement', dialog.element).focus();
                    }
                },
                animationSettings: { effect: 'Zoom' },
                width: '25%',
                isModal: true,
                closeOnEscape: true,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                showCloseIcon: true,
                header: this.parent.localeObj.getConstant('createCalculatedField'),
                target: document.body,
                cssClass: this.parent.cssClass
            });
            dialog.isStringTemplate = true;
            dialog.appendTo(calculatedFieldElement);
        };
        CalculatedField.prototype.cancelClick = function () {
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            dialog.close();
            this.isEdit = false;
        };
        CalculatedField.prototype.beforeOpen = function () {
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            dialog.element.querySelector('.e-dlg-header').setAttribute('title', this.parent.localeObj.getConstant('createCalculatedField'));
        };
        CalculatedField.prototype.closeDialog = function () {
            if (this.parent.getModuleName() === 'pivotfieldlist') {
                this.parent.axisFieldModule.render();
                if (this.parent.renderMode !== 'Fixed') {
                    ej2_base_1.addClass([this.parent.element.querySelector('.' + cls.TOGGLE_FIELD_LIST_CLASS)], cls.ICON_HIDDEN);
                    this.parent.dialogRenderer.fieldListDialog.show();
                }
            }
            this.destroy();
            Eif (!ej2_base_2.isNullOrUndefined(document.getElementById(this.parentID + 'calculateddialog'))) {
                ej2_base_1.remove(document.getElementById(this.parentID + 'calculateddialog'));
            }
            Iif (!ej2_base_2.isNullOrUndefined(document.querySelector('.' + this.parentID + 'calculatedmenu'))) {
                ej2_base_1.remove(document.querySelector('.' + this.parentID + 'calculatedmenu'));
            }
            var timeOut = ((this.parent.getModuleName() === 'pivotview') ||
                ((this.parent.getModuleName() === 'pivotfieldlist') &&
                    this.parent.renderMode === 'Fixed')) ? 0 : 500;
            if (this.buttonCall) {
                this.buttonCall = false;
                setTimeout(this.setFocus.bind(this), timeOut);
            }
        };
        CalculatedField.prototype.setFocus = function () {
            var parentElement;
            if (this.parent.getModuleName() === 'pivotview' && this.parent.element) {
                parentElement = this.parent.element;
            }
            else Iif (document.getElementById(this.parent.element.id + '_Container')) {
                parentElement = document.getElementById(this.parent.element.id + '_Container');
            }
            if (parentElement) {
                var pivotButtons = [].slice.call(parentElement.querySelectorAll('.e-pivot-button'));
                for (var _i = 0, pivotButtons_1 = pivotButtons; _i < pivotButtons_1.length; _i++) {
                    var item = pivotButtons_1[_i];
                    if (item.getAttribute('data-uid') === this.currentFieldName) {
                        item.focus();
                        break;
                    }
                }
            }
        };
        CalculatedField.prototype.renderDialogElements = function () {
            var outerDiv = ej2_base_1.createElement('div', {
                id: this.parentID + 'outerDiv',
                className: (this.parent.dataType === 'olap' ? cls.OLAP_CALCOUTERDIV + ' ' : '') + cls.CALCOUTERDIV
            });
            var olapFieldTreeDiv = ej2_base_1.createElement('div', { id: this.parentID + 'Olap_Tree_Div', className: 'e-olap-field-tree-div' });
            var pivotCalcDiv = ej2_base_1.createElement('div', { id: this.parentID + 'Pivot_Calc_Div', className: 'e-pivot-calculated-div' });
            if (this.parent.getModuleName() === 'pivotfieldlist' && this.parent.
                dialogRenderer.parentElement.querySelector('.' + cls.FORMULA) !== null && this.parent.isAdaptive) {
                var accordDiv = ej2_base_1.createElement('div', { id: this.parentID + 'accordDiv', className: cls.CALCACCORD });
                outerDiv.appendChild(accordDiv);
                var buttonDiv = ej2_base_1.createElement('div', { id: this.parentID + 'buttonDiv', className: cls.CALCBUTTONDIV });
                var addBtn = ej2_base_1.createElement('button', {
                    id: this.parentID + 'addBtn',
                    className: cls.CALCADDBTN, attrs: { 'type': 'button' }
                });
                addBtn.innerText = this.parent.localeObj.getConstant('add');
                var cancelBtn = ej2_base_1.createElement('button', {
                    id: this.parentID + 'cancelBtn',
                    className: cls.CALCCANCELBTN, attrs: { 'type': 'button' }
                });
                cancelBtn.innerText = this.parent.localeObj.getConstant('cancel');
                buttonDiv.appendChild(cancelBtn);
                buttonDiv.appendChild(addBtn);
                outerDiv.appendChild(buttonDiv);
            }
            else {
                if (!this.parent.isAdaptive && this.parent.dataType === 'olap') {
                    var formulaTitle = ej2_base_1.createElement('div', {
                        className: cls.PIVOT_FIELD_TITLE_CLASS, id: this.parentID + '_' + 'FieldNameTitle'
                    });
                    formulaTitle.innerText = this.parent.localeObj.getConstant('fieldTitle');
                    pivotCalcDiv.appendChild(formulaTitle);
                }
                var inputDiv = ej2_base_1.createElement('div', { id: this.parentID + 'innerDiv', className: cls.CALCINPUTDIV });
                var inputObj = ej2_base_1.createElement('input', {
                    id: this.parentID + 'ddlelement',
                    attrs: { 'type': 'text' },
                    className: cls.CALCINPUT
                });
                inputDiv.appendChild(inputObj);
                if (this.parent.dataType === 'olap' && !this.parent.isAdaptive) {
                    pivotCalcDiv.appendChild(inputDiv);
                }
                else {
                    outerDiv.appendChild(inputDiv);
                }
                var wrapDiv = ej2_base_1.createElement('div', { id: this.parentID + 'control_container', className: cls.TREEVIEWOUTER });
                if (!this.parent.isAdaptive) {
                    var fieldTitle = ej2_base_1.createElement('div', {
                        className: cls.PIVOT_ALL_FIELD_TITLE_CLASS
                    });
                    fieldTitle.innerText = (this.parent.dataType === 'olap' ? this.parent.localeObj.getConstant('allFields') :
                        this.parent.localeObj.getConstant('formulaField'));
                    if (this.parent.dataType === 'olap') {
                        var headerWrapperDiv = ej2_base_1.createElement('div', { className: cls.PIVOT_ALL_FIELD_TITLE_CLASS + '-container' });
                        headerWrapperDiv.appendChild(fieldTitle);
                        var spanElement = ej2_base_1.createElement('span', {
                            attrs: {
                                'tabindex': '0',
                                'aria-disabled': 'false',
                                'aria-label': this.parent.localeObj.getConstant('fieldTooltip'),
                                'role': 'button'
                            },
                            className: cls.ICON + ' ' + cls.CALC_INFO
                        });
                        headerWrapperDiv.appendChild(spanElement);
                        var tooltip = new ej2_popups_1.Tooltip({
                            content: this.parent.localeObj.getConstant('fieldTooltip'),
                            position: (this.parent.enableRtl ? 'RightCenter' : 'LeftCenter'),
                            target: '.' + cls.CALC_INFO,
                            offsetY: (this.parent.enableRtl ? -10 : -10),
                            locale: this.parent.locale,
                            enableRtl: this.parent.enableRtl,
                            enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                            width: 220,
                            cssClass: this.parent.cssClass
                        });
                        tooltip.appendTo(headerWrapperDiv);
                        wrapDiv.appendChild(headerWrapperDiv);
                    }
                    else {
                        outerDiv.appendChild(fieldTitle);
                    }
                }
                var treeOuterDiv = ej2_base_1.createElement('div', { className: cls.TREEVIEW + '-outer-div' });
                wrapDiv.appendChild(treeOuterDiv);
                var treeElement = ej2_base_1.createElement('div', { id: this.parentID + 'tree', className: cls.TREEVIEW });
                treeOuterDiv.appendChild(treeElement);
                if (this.parent.dataType === 'olap' && !this.parent.isAdaptive) {
                    olapFieldTreeDiv.appendChild(wrapDiv);
                }
                else {
                    outerDiv.appendChild(wrapDiv);
                }
                if (!this.parent.isAdaptive) {
                    var formulaTitle = ej2_base_1.createElement('div', {
                        className: cls.PIVOT_FORMULA_TITLE_CLASS
                    });
                    formulaTitle.innerText = (this.parent.dataType === 'olap' ? this.parent.localeObj.getConstant('expressionField') :
                        this.parent.localeObj.getConstant('formula'));
                    if (this.parent.dataType === 'olap') {
                        pivotCalcDiv.appendChild(formulaTitle);
                    }
                    else {
                        outerDiv.appendChild(formulaTitle);
                    }
                }
                var dropDiv = ej2_base_1.createElement('textarea', {
                    id: this.parentID + 'droppable',
                    className: cls.FORMULA + ' e-control e-textbox e-input',
                    attrs: {
                        'placeholder': this.parent.isAdaptive ? this.parent.localeObj.getConstant('dropTextMobile') :
                            (this.parent.dataType === 'olap' ? this.parent.localeObj.getConstant('olapDropText') :
                                this.parent.localeObj.getConstant('dropText'))
                    }
                });
                if (this.parent.dataType === 'olap' && !this.parent.isAdaptive) {
                    pivotCalcDiv.appendChild(dropDiv);
                }
                else {
                    outerDiv.appendChild(dropDiv);
                }
                if (this.parent.isAdaptive) {
                    var buttonDiv = ej2_base_1.createElement('div', { id: this.parentID + 'buttonDiv', className: cls.CALCBUTTONDIV });
                    var okBtn = ej2_base_1.createElement('button', {
                        id: this.parentID + 'okBtn',
                        className: cls.CALCOKBTN, attrs: { 'type': 'button' }
                    });
                    okBtn.innerText = this.parent.localeObj.getConstant('apply');
                    buttonDiv.appendChild(okBtn);
                    outerDiv.appendChild(buttonDiv);
                }
                if (this.parent.dataType === 'olap') {
                    Eif (!this.parent.isAdaptive) {
                        var memberTypeTitle = ej2_base_1.createElement('div', {
                            className: cls.OLAP_MEMBER_TITLE_CLASS
                        });
                        memberTypeTitle.innerText = this.parent.localeObj.getConstant('memberType');
                        pivotCalcDiv.appendChild(memberTypeTitle);
                    }
                    var memberTypeDrop = ej2_base_1.createElement('div', { id: this.parentID + 'Member_Type_Div', className: cls.CALC_MEMBER_TYPE_DIV });
                    Iif (this.parent.isAdaptive) {
                        outerDiv.appendChild(memberTypeDrop);
                    }
                    else {
                        pivotCalcDiv.appendChild(memberTypeDrop);
                        var hierarchyTitle = ej2_base_1.createElement('div', {
                            className: cls.OLAP_HIERARCHY_TITLE_CLASS
                        });
                        hierarchyTitle.innerText = this.parent.localeObj.getConstant('selectedHierarchy');
                        pivotCalcDiv.appendChild(hierarchyTitle);
                    }
                    var hierarchyDrop = ej2_base_1.createElement('div', {
                        id: this.parentID + 'Hierarchy_List_Div', className: cls.CALC_HIERARCHY_LIST_DIV
                    });
                    Iif (this.parent.isAdaptive) {
                        outerDiv.appendChild(hierarchyDrop);
                    }
                    else {
                        pivotCalcDiv.appendChild(hierarchyDrop);
                    }
                }
                if (!this.parent.isAdaptive) {
                    var formatTitle = ej2_base_1.createElement('div', {
                        className: cls.PIVOT_FORMAT_TITLE_CLASS
                    });
                    formatTitle.innerText = this.parent.localeObj.getConstant('formatString');
                    pivotCalcDiv.appendChild(formatTitle);
                }
                var ddlFormatTypes = ej2_base_1.createElement('div', {
                    id: this.parentID + 'Format_Div', className: cls.CALC_FORMAT_TYPE_DIV
                });
                if (this.parent.isAdaptive) {
                    outerDiv.appendChild(ddlFormatTypes);
                }
                else {
                    pivotCalcDiv.appendChild(ddlFormatTypes);
                }
                var customFormatDiv = ej2_base_1.createElement('div', {
                    id: this.parentID + 'custom_Format_Div',
                    className: cls.PIVOT_CALC_CUSTOM_FORMAT_INPUTDIV
                });
                var customFormatObj = ej2_base_1.createElement('input', {
                    id: this.parentID + 'Custom_Format_Element',
                    attrs: { 'type': 'text' },
                    className: cls.CALC_FORMAT_INPUT
                });
                customFormatDiv.appendChild(customFormatObj);
                pivotCalcDiv.appendChild(customFormatDiv);
                if (this.parent.isAdaptive) {
                    outerDiv.appendChild(customFormatDiv);
                }
                else {
                    pivotCalcDiv.appendChild(customFormatDiv);
                }
                if (this.parent.getModuleName() === 'pivotfieldlist' && this.parent.
                    dialogRenderer.parentElement.querySelector('.' + cls.FORMULA) === null && this.parent.isAdaptive) {
                    var okBtn = outerDiv.querySelector('.' + cls.CALCOKBTN);
                    outerDiv.appendChild(okBtn);
                }
                else {
                    if (this.parent.dataType === 'olap') {
                        outerDiv.appendChild(olapFieldTreeDiv);
                    }
                    outerDiv.appendChild(pivotCalcDiv);
                }
            }
            return outerDiv;
        };
        CalculatedField.prototype.renderAdaptiveLayout = function (isEdit) {
            var dialogElement = this.parent.dialogRenderer.adaptiveElement;
            Eif (isEdit) {
                if (ej2_base_1.select('#' + this.parentID + 'droppable', dialogElement.element)) {
                    var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
                    this.formulaText = ej2_base_1.select('#' + this.parentID + 'droppable', document).value;
                    this.fieldText = inputObj.value;
                }
                Iif (dialogElement.element.querySelector('.' + cls.CALC_MEMBER_TYPE_DIV)) {
                    var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement.element), ej2_dropdowns_1.DropDownList);
                    this.fieldType = memberTypeDrop.value;
                }
                Iif (dialogElement.element.querySelector('.' + cls.CALC_HIERARCHY_LIST_DIV)) {
                    var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement.element), ej2_dropdowns_1.DropDownList);
                    this.parentHierarchy = this.fieldType === 'Dimension' ? hierarchyDrop.value : null;
                }
                if (dialogElement.element.querySelector('.' + cls.CALC_FORMAT_TYPE_DIV)) {
                    var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement.element), ej2_dropdowns_1.DropDownList);
                    this.formatType = ddlFormatTypes.value;
                }
                if (dialogElement.element.querySelector('.' + cls.CALC_FORMAT_INPUT)) {
                    var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement.element), ej2_inputs_1.MaskedTextBox);
                    this.formatText = (this.parent.dataType === 'olap' ? this.formatType : this.getFormat(this.formatType)) === 'Custom' ? customFormat.value : null;
                }
            }
            else {
                this.currentFieldName = this.formulaText = this.fieldText = this.formatText = null;
                this.fieldType = this.formatType = this.parentHierarchy = null;
            }
            this.renderMobileLayout(dialogElement);
        };
        CalculatedField.prototype.updateAdaptiveCalculatedField = function (isEdit, fieldName) {
            var dialogElement = this.parent.dialogRenderer.adaptiveElement.element;
            this.isEdit = isEdit;
            var calcInfo = (isEdit ? (this.parent.dataType === 'pivot' ?
                this.parent.engineModule.fieldList[fieldName] : this.parent.olapEngineModule.fieldList[fieldName]) :
                {
                    id: null, caption: null, formula: null, fieldType: 'Measure',
                    formatString: (this.parent.dataType === 'pivot' ? null : 'Standard'), parentHierarchy: null
                });
            this.currentFieldName = calcInfo.id;
            var inputObj = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'ddlelement', document), ej2_inputs_1.MaskedTextBox);
            Eif (ej2_base_1.select('#' + this.parentID + 'droppable', document)) {
                this.formulaText = ej2_base_1.select('#' + this.parentID + 'droppable', document).value = calcInfo.formula;
                this.fieldText = inputObj.value = calcInfo.caption;
                inputObj.dataBind();
            }
            Iif (dialogElement.querySelector('.' + cls.CALC_MEMBER_TYPE_DIV)) {
                var memberTypeDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                this.fieldType = memberTypeDrop.value = calcInfo.fieldType;
                memberTypeDrop.readonly = isEdit ? true : false;
                memberTypeDrop.dataBind();
            }
            Iif (dialogElement.querySelector('.' + cls.CALC_HIERARCHY_LIST_DIV)) {
                var hierarchyDrop = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                if (this.fieldType === 'Dimension') {
                    this.parentHierarchy = hierarchyDrop.value = calcInfo.parentHierarchy;
                }
                else {
                    this.parentHierarchy = null;
                    hierarchyDrop.index = 0;
                }
                hierarchyDrop.dataBind();
            }
            Eif (dialogElement.querySelector('.' + cls.CALC_FORMAT_TYPE_DIV)) {
                var ddlFormatTypes = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement), ej2_dropdowns_1.DropDownList);
                this.formatType = ddlFormatTypes.value = (this.formatTypes.indexOf(calcInfo.formatString) > -1 ? calcInfo.formatString : 'Custom');
            }
            Eif (dialogElement.querySelector('.' + cls.CALC_FORMAT_INPUT)) {
                var customFormat = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement), ej2_inputs_1.MaskedTextBox);
                var formatObj = util_1.PivotUtil.getFieldByName(fieldName, this.parent.dataSourceSettings.formatSettings);
                Eif (this.parent.dataType === 'pivot') {
                    this.formatText = customFormat.value = formatObj ? formatObj.format : null;
                }
                else {
                    this.formatText = customFormat.value = (this.formatType === 'Custom' ? calcInfo.formatString : null);
                }
                customFormat.dataBind();
            }
        };
        CalculatedField.prototype.createDropElements = function () {
            var _this = this;
            var dialog = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document) ? ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog) : null;
            var dialogElement = (this.parent.isAdaptive ?
                this.parent.dialogRenderer.parentElement : dialog.element);
            var fData = [];
            var fieldData = [];
            for (var _i = 0, _a = this.formatTypes; _i < _a.length; _i++) {
                var format = _a[_i];
                fData.push({ value: (this.parent.dataType === 'pivot' ? this.getFormat(format) : format), text: this.parent.localeObj.getConstant(format) });
            }
            if (this.parent.dataType === 'olap') {
                var mData = [];
                var memberTypeData = ['Measure', 'Dimension'];
                for (var _b = 0, memberTypeData_1 = memberTypeData; _b < memberTypeData_1.length; _b++) {
                    var type = memberTypeData_1[_b];
                    mData.push({ value: type, text: this.parent.localeObj.getConstant(type) });
                }
                var fields = util_1.PivotUtil.getClonedData(this.parent.olapEngineModule.fieldListData);
                for (var _c = 0, _d = fields; _c < _d.length; _c++) {
                    var item = _d[_c];
                    if (item.spriteCssClass &&
                        (item.spriteCssClass.indexOf('e-attributeCDB-icon') > -1 ||
                            item.spriteCssClass.indexOf('e-hierarchyCDB-icon') > -1)) {
                        fieldData.push({ value: item.id, text: item.caption });
                    }
                }
                var memberTypeObj = new ej2_dropdowns_1.DropDownList({
                    dataSource: mData, enableRtl: this.parent.enableRtl, locale: this.parent.locale,
                    fields: { value: 'value', text: 'text' },
                    value: this.fieldType !== null ? this.fieldType : mData[0].value,
                    readonly: this.isEdit,
                    cssClass: cls.MEMBER_OPTIONS_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), width: '100%',
                    change: function (args) {
                        hierarchyListObj_1.enabled = args.value === 'Dimension' ? true : false;
                        _this.fieldType = args.value;
                        _this.formulaText = ej2_base_1.select('#' + _this.parentID + 'droppable', document).value;
                        hierarchyListObj_1.dataBind();
                    }
                });
                memberTypeObj.isStringTemplate = true;
                memberTypeObj.appendTo(ej2_base_1.select('#' + this.parentID + 'Member_Type_Div', dialogElement));
                var hierarchyListObj_1 = new ej2_dropdowns_1.DropDownList({
                    dataSource: fieldData, enableRtl: this.parent.enableRtl, locale: this.parent.locale,
                    allowFiltering: true,
                    enabled: memberTypeObj.value === 'Dimension' ? true : false,
                    filterBarPlaceholder: this.parent.localeObj.getConstant('example') + ' ' + fieldData[0].text.toString(),
                    fields: { value: 'value', text: 'text' },
                    value: this.parentHierarchy !== null && memberTypeObj.value === 'Dimension' ?
                        this.parentHierarchy : fieldData[0].value,
                    cssClass: cls.MEMBER_OPTIONS_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), width: '100%',
                    change: function (args) {
                        _this.parentHierarchy = args.value;
                        _this.formulaText = ej2_base_1.select('#' + _this.parentID + 'droppable', document).value;
                    }
                });
                hierarchyListObj_1.isStringTemplate = true;
                hierarchyListObj_1.appendTo(ej2_base_1.select('#' + this.parentID + 'Hierarchy_List_Div', dialogElement));
            }
            var formatStringObj = new ej2_dropdowns_1.DropDownList({
                dataSource: fData, enableRtl: this.parent.enableRtl, locale: this.parent.locale,
                fields: { value: 'value', text: 'text' },
                value: this.parent.isAdaptive && this.formatType !== null ? this.formatType
                    : this.parent.dataType === 'olap' ? fData[0].value : fData[4].value,
                cssClass: cls.MEMBER_OPTIONS_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), width: '100%',
                change: function (args) {
                    customerFormatObj.enabled = args.value === 'Custom' ? true : false;
                    _this.formatType = args.value;
                    _this.formulaText = ej2_base_1.select('#' + _this.parentID + 'droppable', document).value;
                    customerFormatObj.dataBind();
                }
            });
            formatStringObj.isStringTemplate = true;
            formatStringObj.appendTo(ej2_base_1.select('#' + this.parentID + 'Format_Div', dialogElement));
            var customerFormatObj = new ej2_inputs_1.MaskedTextBox({
                placeholder: this.parent.localeObj.getConstant('customFormat'),
                locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                value: this.formatText !== null && formatStringObj.value === 'Custom' ? this.formatText : null,
                enabled: formatStringObj.value === 'Custom' ? true : false,
                change: function (args) {
                    _this.formatText = args.value;
                    _this.formulaText = ej2_base_1.select('#' + _this.parentID + 'droppable', document).value;
                },
                cssClass: this.parent.cssClass
            });
            customerFormatObj.isStringTemplate = true;
            customerFormatObj.appendTo(ej2_base_1.select('#' + this.parentID + 'Custom_Format_Element', dialogElement));
        };
        CalculatedField.prototype.getFormat = function (pivotFormat) {
            var format = pivotFormat;
            if (this.parent.dataType !== 'olap') {
                switch (format) {
                    case 'Standard':
                        format = 'N';
                        break;
                    case 'Currency':
                        format = 'C';
                        break;
                    case 'Percent':
                        format = 'P';
                        break;
                    case 'N':
                        format = 'Standard';
                        break;
                    case 'C':
                        format = 'Currency';
                        break;
                    case 'P':
                        format = 'Percent';
                        break;
                }
            }
            else {
                switch (format) {
                    case 'Standard':
                        format = 'N';
                        break;
                    case 'Currency':
                        format = 'C';
                        break;
                    case 'Percent':
                        format = 'P';
                        break;
                }
            }
            return format;
        };
        CalculatedField.prototype.createTreeView = function () {
            var _this = this;
            var dialog = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document) ? ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog) : null;
            var dialogElement = (this.parent.isAdaptive ?
                this.parent.dialogRenderer.parentElement : dialog.element);
            if (this.parent.dataType === 'olap') {
                this.treeObj = new ej2_navigations_1.TreeView({
                    fields: { dataSource: this.getFieldListData(this.parent), id: 'id', text: 'caption', parentID: 'pid', iconCss: 'spriteCssClass' },
                    allowDragAndDrop: true,
                    enableRtl: this.parent.enableRtl,
                    enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                    locale: this.parent.locale,
                    nodeDragStart: this.dragStart.bind(this),
                    nodeDragging: function (e) {
                        if (e.event.target && e.event.target.classList.contains(cls.FORMULA)) {
                            ej2_base_2.removeClass([e.clonedNode], cls.NO_DRAG_CLASS);
                            ej2_base_1.addClass([e.event.target], 'e-copy-drop');
                        }
                        else {
                            ej2_base_1.addClass([e.clonedNode], cls.NO_DRAG_CLASS);
                            ej2_base_2.removeClass([e.event.target], 'e-copy-drop');
                            e.dropIndicator = 'e-no-drop';
                            ej2_base_1.addClass([e.clonedNode.querySelector('.' + cls.ICON)], 'e-icon-expandable');
                            ej2_base_2.removeClass([e.clonedNode.querySelector('.' + cls.ICON)], 'e-list-icon');
                        }
                    },
                    nodeClicked: this.fieldClickHandler.bind(this),
                    nodeSelected: function (args) {
                        Eif (args.node.getAttribute('data-type') === CALC) {
                            _this.displayMenu(args.node);
                        }
                        else {
                            ej2_base_2.removeClass([args.node], 'e-active');
                            args.cancel = true;
                        }
                    },
                    nodeDragStop: this.fieldDropped.bind(this),
                    drawNode: this.drawTreeNode.bind(this),
                    nodeExpanding: this.updateNodeIcon.bind(this),
                    nodeCollapsed: this.updateNodeIcon.bind(this),
                    sortOrder: 'None',
                    cssClass: this.parent.cssClass
                });
            }
            else {
                this.treeObj = new ej2_navigations_1.TreeView({
                    fields: { dataSource: this.getFieldListData(this.parent), id: 'formula', text: 'name', iconCss: 'icon' },
                    allowDragAndDrop: true,
                    enableRtl: this.parent.enableRtl,
                    enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                    locale: this.parent.locale,
                    cssClass: this.parent.cssClass,
                    nodeCollapsing: this.nodeCollapsing.bind(this),
                    nodeDragStart: this.dragStart.bind(this),
                    nodeClicked: this.fieldClickHandler.bind(this),
                    nodeDragStop: this.fieldDropped.bind(this),
                    drawNode: this.drawTreeNode.bind(this),
                    keyPress: function (args) {
                        if (args.event.keyCode === 39) {
                            args.cancel = true;
                        }
                    },
                    sortOrder: 'Ascending'
                });
            }
            this.treeObj.isStringTemplate = true;
            this.treeObj.appendTo(ej2_base_1.select('#' + this.parentID + 'tree', dialogElement));
        };
        CalculatedField.prototype.updateNodeIcon = function (args) {
            Iif (args.node && args.node.querySelector('.e-list-icon') &&
                args.node.querySelector('.e-icon-expandable.e-process') &&
                (args.node.querySelector('.e-list-icon').className.indexOf('e-folderCDB-icon') > -1)) {
                var node = args.node.querySelector('.e-list-icon');
                ej2_base_2.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-icon-expandable') &&
                (args.node.querySelector('.e-list-icon').className.indexOf('e-folderCDB-open-icon') > -1)) {
                var node = args.node.querySelector('.e-list-icon');
                ej2_base_2.removeClass([node], 'e-folderCDB-open-icon');
                ej2_base_1.addClass([node], 'e-folderCDB-icon');
            }
            else {
                var curTreeData = this.treeObj.fields.dataSource;
                var fieldListData = curTreeData;
                var childNodes = [];
                for (var _i = 0, fieldListData_1 = fieldListData; _i < fieldListData_1.length; _i++) {
                    var item = fieldListData_1[_i];
                    if (item.pid === args.nodeData.id.toString()) {
                        childNodes.push(item);
                    }
                }
                Iif (childNodes.length === 0) {
                    this.parent.olapEngineModule.calcChildMembers = [];
                    this.parent.olapEngineModule.getCalcChildMembers(this.parent.dataSourceSettings, args.nodeData.id.toString());
                    childNodes = this.parent.olapEngineModule.calcChildMembers;
                    this.parent.olapEngineModule.calcChildMembers = [];
                    for (var _a = 0, childNodes_1 = childNodes; _a < childNodes_1.length; _a++) {
                        var node = childNodes_1[_a];
                        node.pid = args.nodeData.id.toString();
                        node.hasChildren = false;
                        node.spriteCssClass = 'e-level-members';
                        node.caption = (node.caption === '' ? this.parent.localeObj.getConstant('blank') : node.caption);
                        curTreeData.push(node);
                    }
                    this.treeObj.addNodes(childNodes, args.node);
                }
                else {
                    return;
                }
            }
        };
        CalculatedField.prototype.nodeCollapsing = function (args) {
            args.cancel = true;
        };
        CalculatedField.prototype.dragStart = function (args) {
            var isDrag = false;
            var dragItem = args.clonedNode;
            Eif (dragItem && ((this.parent.dataType === 'olap' &&
                (dragItem.querySelector('.e-calc-dimension-icon,.e-calc-measure-icon,.e-measure-icon') ||
                    dragItem.querySelector('.e-attributeCDB-icon,.e-hierarchyCDB-icon') ||
                    dragItem.querySelector('.e-level-members,.e-namedSetCDB-icon'))) || (this.parent.dataType === 'pivot' &&
                args.event.target.classList.contains(cls.DRAG_CLASS)))) {
                isDrag = true;
            }
            Eif (isDrag) {
                ej2_base_1.addClass([args.draggedNode.querySelector('.' + cls.LIST_TEXT_CLASS)], cls.SELECTED_NODE_CLASS);
                ej2_base_1.addClass([dragItem], cls.PIVOTCALC);
                var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
                dragItem.style.zIndex = (dialog.zIndex + 1).toString();
                dragItem.style.display = 'inline';
            }
            else {
                args.cancel = true;
            }
        };
        CalculatedField.prototype.drawTreeNode = function (args) {
            if (this.parent.dataType === 'olap') {
                Iif (args.node.querySelector('.e-measure-icon')) {
                    args.node.querySelector('.e-list-icon').style.display = 'none';
                }
                var field = args.nodeData;
                args.node.setAttribute('data-field', field.id);
                args.node.setAttribute('data-caption', field.caption);
                var liTextElement = args.node.querySelector('.' + cls.TEXT_CONTENT_CLASS);
                if (args.nodeData && args.nodeData.type === CALC &&
                    liTextElement && args.node.querySelector('.e-list-icon.e-calc-member')) {
                    args.node.setAttribute('data-type', field.type);
                    args.node.setAttribute('data-membertype', field.fieldType);
                    args.node.setAttribute('data-hierarchy', field.parentHierarchy ? field.parentHierarchy : '');
                    args.node.setAttribute('data-formula', field.formula);
                    var formatString = (field.formatString ? this.formatTypes.indexOf(field.formatString) > -1 ?
                        field.formatString : 'Custom' : 'None');
                    args.node.setAttribute('data-formatString', formatString);
                    args.node.setAttribute('data-customformatstring', (formatString === 'Custom' ? field.formatString : ''));
                    var removeElement = ej2_base_1.createElement('span', {
                        className: cls.GRID_REMOVE + ' e-icons e-list-icon'
                    });
                    liTextElement.classList.add('e-calcfieldmember');
                    Iif (this.parent.isAdaptive) {
                        var editElement = ej2_base_1.createElement('span', {
                            className: 'e-list-edit-icon' + (this.isEdit && this.currentFieldName === field.id ?
                                ' e-edited ' : ' e-edit ') + cls.ICON
                        });
                        var editWrapper = ej2_base_1.createElement('div', { className: 'e-list-header-icon' });
                        editWrapper.appendChild(editElement);
                        editWrapper.appendChild(removeElement);
                        liTextElement.appendChild(editWrapper);
                    }
                    else {
                        liTextElement.appendChild(removeElement);
                    }
                }
                Iif (this.parent.isAdaptive) {
                    var liTextElement_1 = args.node.querySelector('.' + cls.TEXT_CONTENT_CLASS);
                    if (args.node && args.node.querySelector('.e-list-icon') && liTextElement_1) {
                        var liIconElement = args.node.querySelector('.e-list-icon');
                        liTextElement_1.insertBefore(liIconElement, args.node.querySelector('.e-list-text'));
                    }
                    if (args.node && args.node.querySelector('.e-calcMemberGroupCDB,.e-measureGroupCDB-icon,.e-folderCDB-icon')) {
                        args.node.querySelector('.' + cls.CHECKBOX_CONTAINER).style.display = 'none';
                    }
                    if (args.node && args.node.querySelector('.e-level-members')) {
                        args.node.querySelector('.e-list-icon').style.display = 'none';
                    }
                }
                if (args.node.querySelector('.e-calc-dimension-icon,.e-calc-measure-icon,.e-measure-icon') ||
                    args.node.querySelector('.e-attributeCDB-icon,.e-hierarchyCDB-icon') ||
                    args.node.querySelector('.e-level-members,.e-namedSetCDB-icon')) {
                    ej2_base_1.addClass([args.node], cls.BUTTON_DRAGGABLE);
                }
            }
            else {
                var field = args.nodeData.field;
                args.node.setAttribute('data-field', field);
                args.node.setAttribute('data-caption', args.nodeData.caption);
                args.node.setAttribute('data-type', args.nodeData.type);
                var formatObj = util_1.PivotUtil.getFieldByName(field, this.parent.dataSourceSettings.formatSettings);
                args.node.setAttribute('data-formatString', formatObj ? formatObj.format : '');
                if (formatObj) {
                    var pivotFormat = this.getFormat(formatObj.format);
                    var formatString = (pivotFormat ? this.formatTypes.indexOf(pivotFormat) > -1 ?
                        formatObj.format : 'Custom' : 'None');
                    args.node.setAttribute('data-customformatstring', (formatString === 'Custom' ? pivotFormat : ''));
                    args.node.setAttribute('data-formatString', formatObj ? formatString : '');
                }
                var dragElement = ej2_base_1.createElement('span', {
                    attrs: { 'tabindex': '-1', 'aria-disabled': 'false', 'title': this.parent.localeObj.getConstant('dragField') },
                    className: cls.ICON + ' e-drag'
                });
                var spaceElement = ej2_base_1.createElement('div', {
                    className: ' e-iconspace'
                });
                ej2_base_2.prepend([dragElement], args.node.querySelector('.' + cls.TEXT_CONTENT_CLASS));
                ej2_base_2.append([spaceElement, args.node.querySelector('.' + cls.FORMAT)], args.node.querySelector('.' + cls.TEXT_CONTENT_CLASS));
                Iif (this.getMenuItems(this.parent.engineModule.fieldList[field].type).length <= 0) {
                    ej2_base_2.removeClass([args.node.querySelector('.' + cls.FORMAT)], cls.ICON);
                }
                else {
                    args.node.querySelector('.' + cls.FORMAT).setAttribute('title', this.parent.localeObj.getConstant('format'));
                }
                if (this.parent.engineModule.fieldList[field].aggregateType === CALC) {
                    args.node.querySelector('.' + cls.FORMAT).setAttribute('title', this.parent.localeObj.getConstant('remove'));
                    ej2_base_1.addClass([args.node.querySelector('.' + cls.FORMAT)], cls.GRID_REMOVE);
                    ej2_base_1.addClass([args.node.querySelector('.' + 'e-iconspace')], [cls.CALC_EDIT, cls.ICON, 'e-list-icon']);
                    args.node.querySelector('.' + cls.CALC_EDIT).setAttribute('title', this.parent.localeObj.getConstant('edit'));
                    args.node.querySelector('.' + cls.CALC_EDIT).setAttribute('aria-disabled', 'false');
                    args.node.querySelector('.' + cls.CALC_EDIT).setAttribute('tabindex', '-1');
                    ej2_base_2.removeClass([args.node.querySelector('.' + cls.FORMAT)], cls.FORMAT);
                    ej2_base_2.removeClass([args.node.querySelector('.e-iconspace')], 'e-iconspace');
                }
            }
        };
        CalculatedField.prototype.createTypeContainer = function (key) {
            var wrapDiv = ej2_base_1.createElement('div', { id: this.parentID + 'control_container', className: cls.TREEVIEWOUTER });
            var type = this.getMenuItems(this.parent.engineModule.fieldList[key].type);
            for (var i = 0; i < type.length; i++) {
                var input = ej2_base_1.createElement('input', {
                    id: this.parentID + 'radio' + key + type[i],
                    attrs: { 'type': 'radio', 'data-ftxt': key, 'data-value': type[i] },
                    className: cls.CALCRADIO
                });
                wrapDiv.appendChild(input);
            }
            return wrapDiv;
        };
        CalculatedField.prototype.getMenuItems = function (fieldType, summaryType) {
            var menuItems = !ej2_base_2.isNullOrUndefined(summaryType) ? summaryType : this.parent.aggregateTypes;
            var type = [];
            var menuTypes = this.getValidSummaryType();
            for (var i = 0; i < menuItems.length; i++) {
                if ((menuTypes.indexOf(menuItems[i]) > -1) && (type.indexOf(menuItems[i]) < 0)) {
                    if (((menuItems[i] === COUNT || menuItems[i] === DISTINCTCOUNT) && fieldType !== 'number')
                        || (fieldType === 'number')) {
                        type.push(menuItems[i]);
                    }
                }
            }
            return type;
        };
        CalculatedField.prototype.getValidSummaryType = function () {
            return [COUNT, DISTINCTCOUNT,
                SUM, AVG, MEDIAN,
                MIN, MAX, PRODUCT,
                STDEV, STDEVP,
                VAR, VARP];
        };
        CalculatedField.prototype.getAccordionData = function (parent) {
            var data = [];
            var keys = Object.keys(parent.engineModule.fieldList);
            for (var index = 0, i = keys.length; index < i; index++) {
                var key = keys[index];
                data.push({
                    header: '<input id=' + this.parentID + '_' + index + ' class=' + cls.CALCCHECK + ' type="checkbox" data-field=' +
                        key + ' data-caption="' + this.parent.engineModule.fieldList[key].caption + '" data-type=' +
                        this.parent.engineModule.fieldList[key].type + '/>',
                    content: (this.parent.engineModule.fieldList[key].aggregateType === CALC ||
                        (this.getMenuItems(this.parent.engineModule.fieldList[key].type).length < 1)) ? '' :
                        this.createTypeContainer(key).outerHTML,
                    iconCss: this.parent.engineModule.fieldList[key].aggregateType === CALC ? 'e-list-icon' + ' ' +
                        (this.isEdit && this.currentFieldName === key ? 'e-edited' : 'e-edit') : ''
                });
            }
            return data;
        };
        CalculatedField.prototype.renderMobileLayout = function (tabObj) {
            var _this = this;
            tabObj.items[4].content = this.renderDialogElements().outerHTML;
            tabObj.dataBind();
            var dialog = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document) ? ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog) : null;
            var dialogElement = (this.parent.isAdaptive ?
                this.parent.dialogRenderer.parentElement : dialog.element);
            if (this.parent.isAdaptive && this.parent.
                dialogRenderer.parentElement.querySelector('.' + cls.FORMULA) !== null) {
                this.createDropElements();
            }
            var cancelBtn = new ej2_buttons_1.Button({
                cssClass: this.parent.cssClass, locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer
            });
            cancelBtn.isStringTemplate = true;
            cancelBtn.appendTo(ej2_base_1.select('#' + this.parentID + 'cancelBtn', dialogElement));
            if (cancelBtn.element) {
                cancelBtn.element.onclick = this.cancelBtnClick.bind(this);
            }
            if (this.parent.
                dialogRenderer.parentElement.querySelector('.' + cls.FORMULA) !== null && this.parent.isAdaptive) {
                var okBtn = new ej2_buttons_1.Button({
                    cssClass: this.parent.cssClass, isPrimary: true, locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                    enableHtmlSanitizer: this.parent.enableHtmlSanitizer
                });
                okBtn.isStringTemplate = true;
                okBtn.appendTo(ej2_base_1.select('#' + this.parentID + 'okBtn', dialogElement));
                var inputObj = new ej2_inputs_1.MaskedTextBox({
                    placeholder: this.parent.localeObj.getConstant('fieldName'),
                    locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                    change: function (args) {
                        _this.fieldText = args.value;
                        _this.formulaText = ej2_base_1.select('#' + _this.parentID + 'droppable', document).value;
                    },
                    cssClass: this.parent.cssClass
                });
                inputObj.isStringTemplate = true;
                inputObj.appendTo(ej2_base_1.select('#' + this.parentID + 'ddlelement', dialogElement));
                if (this.formulaText !== null && ej2_base_1.select('#' + this.parentID + 'droppable', this.parent.dialogRenderer.parentElement) !== null) {
                    var drop = ej2_base_1.select('#' + this.parentID + 'droppable', this.parent.dialogRenderer.parentElement);
                    drop.value = this.formulaText;
                }
                if (this.fieldText !== null && this.parent.
                    dialogRenderer.parentElement.querySelector('.' + cls.CALCINPUT) !== null) {
                    this.parent.
                        dialogRenderer.parentElement.querySelector('.' + cls.CALCINPUT).value = this.fieldText;
                    inputObj.value = this.fieldText;
                }
                Eif (okBtn.element) {
                    okBtn.element.onclick = this.applyFormula.bind(this);
                }
            }
            else Eif (this.parent.isAdaptive) {
                var addBtn = new ej2_buttons_1.Button({
                    cssClass: this.parent.cssClass, isPrimary: true, locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                    enableHtmlSanitizer: this.parent.enableHtmlSanitizer
                });
                addBtn.isStringTemplate = true;
                addBtn.appendTo(ej2_base_1.select('#' + this.parentID + 'addBtn', dialogElement));
                Iif (this.parent.dataType === 'olap') {
                    this.treeObj = new ej2_navigations_1.TreeView({
                        fields: { dataSource: this.getFieldListData(this.parent), id: 'id', text: 'caption', parentID: 'pid', iconCss: 'spriteCssClass' },
                        showCheckBox: true,
                        autoCheck: false,
                        sortOrder: 'None',
                        enableRtl: this.parent.enableRtl,
                        locale: this.parent.locale,
                        enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                        nodeClicked: this.fieldClickHandler.bind(this),
                        drawNode: this.drawTreeNode.bind(this),
                        nodeExpanding: this.updateNodeIcon.bind(this),
                        nodeCollapsed: this.updateNodeIcon.bind(this),
                        nodeSelected: function (args) {
                            ej2_base_2.removeClass([args.node], 'e-active');
                            args.cancel = true;
                        },
                        cssClass: this.parent.cssClass
                    });
                    this.treeObj.isStringTemplate = true;
                    this.treeObj.appendTo(ej2_base_1.select('#' + this.parentID + 'accordDiv', dialogElement));
                }
                else {
                    var accordion = new ej2_navigations_3.Accordion({
                        items: this.getAccordionData(this.parent),
                        enableRtl: this.parent.enableRtl,
                        locale: this.parent.locale,
                        enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                        expanding: this.accordionExpand.bind(this),
                        clicked: this.accordionClickHandler.bind(this),
                        created: this.accordionCreated.bind(this)
                    });
                    accordion.isStringTemplate = true;
                    accordion.appendTo(ej2_base_1.select('#' + this.parentID + 'accordDiv', dialogElement));
                    this.updateType();
                }
                Eif (addBtn.element) {
                    addBtn.element.onclick = this.addBtnClick.bind(this);
                }
            }
        };
        CalculatedField.prototype.accordionExpand = function (args) {
            Eif (args.element.querySelectorAll('.e-radio-wrapper').length === 0) {
                var keys = Object.keys(this.parent.engineModule.fieldList);
                for (var index = 0, i = keys.length; index < i; index++) {
                    var key = keys[index];
                    var type = this.parent.engineModule.fieldList[key].type !== 'number' ? [COUNT, DISTINCTCOUNT] :
                        [SUM, COUNT, AVG, MEDIAN, MIN, MAX, DISTINCTCOUNT, PRODUCT, STDEV, STDEVP, VAR, VARP];
                    var radiobutton = void 0;
                    if (key === args.element.querySelector('[data-field').getAttribute('data-field')) {
                        for (var i_1 = 0; i_1 < type.length; i_1++) {
                            radiobutton = new ej2_buttons_1.RadioButton({
                                label: this.parent.localeObj.getConstant(type[i_1]),
                                name: AGRTYPE + key,
                                checked: args.element.querySelector('[data-type').getAttribute('data-type') === type[i_1],
                                change: this.onChange.bind(this),
                                locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                                cssClass: this.parent.cssClass
                            });
                            radiobutton.isStringTemplate = true;
                            radiobutton.appendTo(ej2_base_1.select('#' + this.parentID + 'radio' + key + type[i_1], args.element));
                        }
                    }
                }
            }
        };
        CalculatedField.prototype.onChange = function (args) {
            var type = args.event.target.parentElement.querySelector('.e-label')
                .innerText;
            var field = args.event.target.closest('.e-acrdn-item').
                querySelector('[data-field').getAttribute('data-caption');
            args.event.target.
                closest('.e-acrdn-item').querySelector('.e-label').
                innerText = field + ' (' + type + ')';
            args.event.target.closest('.e-acrdn-item').
                querySelector('[data-type').setAttribute('data-type', args.event.target.getAttribute('data-value'));
        };
        CalculatedField.prototype.updateType = function () {
            var keys = Object.keys(this.parent.engineModule.fieldList);
            var dialog = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document) ? ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog) : null;
            var dialogElement = (this.parent.isAdaptive ?
                this.parent.dialogRenderer.parentElement : dialog.element);
            for (var index = 0, i = keys.length; index < i; index++) {
                var key = keys[index];
                var type = null;
                if ((this.parent.engineModule.fieldList[key].type !== 'number' ||
                    this.parent.engineModule.fieldList[key].type === 'include' ||
                    this.parent.engineModule.fieldList[key].type === 'exclude') &&
                    (this.parent.engineModule.fieldList[key].aggregateType !== 'DistinctCount')) {
                    type = COUNT;
                }
                else {
                    type = this.parent.engineModule.fieldList[key].aggregateType !== undefined ?
                        this.parent.engineModule.fieldList[key].aggregateType : SUM;
                }
                var checkbox = new ej2_buttons_1.CheckBox({
                    label: this.parent.engineModule.fieldList[key].caption + ' (' + this.parent.localeObj.getConstant(type) + ')',
                    locale: this.parent.locale, enableRtl: this.parent.enableRtl, enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                    cssClass: this.parent.cssClass
                });
                checkbox.isStringTemplate = true;
                checkbox.appendTo(ej2_base_1.select('#' + this.parentID + '_' + index, dialogElement));
                ej2_base_1.select('#' + this.parentID + '_' + index, dialogElement).setAttribute('data-field', key);
                ej2_base_1.select('#' + this.parentID + '_' + index, dialogElement).setAttribute('data-type', type);
            }
        };
        CalculatedField.prototype.cancelBtnClick = function () {
            this.renderMobileLayout(this.parent.dialogRenderer.adaptiveElement);
        };
        CalculatedField.prototype.addBtnClick = function () {
            var fieldText = '';
            var field = null;
            var type = null;
            Eif (this.parent.dataType === 'pivot') {
                var node = document.querySelectorAll('.e-accordion .e-check');
                for (var i = 0; i < node.length; i++) {
                    field = node[i].parentElement.querySelector('[data-field]').getAttribute('data-field');
                    type = node[i].parentElement.querySelector('[data-field]').getAttribute('data-type');
                    Eif (type.indexOf(CALC) === -1) {
                        fieldText = fieldText + ('"' + type + '(' + field + ')' + '"');
                    }
                    else {
                        for (var j = 0; j < this.parent.dataSourceSettings.calculatedFieldSettings.length; j++) {
                            if (this.parent.dataSourceSettings.calculatedFieldSettings[j].name === field) {
                                fieldText = fieldText + this.parent.dataSourceSettings.calculatedFieldSettings[j].formula;
                                break;
                            }
                        }
                    }
                }
            }
            else {
                var nodes = this.treeObj.getAllCheckedNodes();
                var olapEngine = this.parent.olapEngineModule;
                for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
                    var item = nodes_1[_i];
                    fieldText = fieldText + (olapEngine.fieldList[item] &&
                        olapEngine.fieldList[item].type === CALC ? olapEngine.fieldList[item].tag : item);
                }
            }
            this.formulaText = this.formulaText !== null ? (this.formulaText + fieldText) : fieldText;
            this.renderMobileLayout(this.parent.dialogRenderer.adaptiveElement);
        };
        CalculatedField.prototype.createCalculatedFieldDialog = function (args) {
            if (this.parent.isAdaptive && this.parent.getModuleName() === 'pivotfieldlist') {
                this.renderAdaptiveLayout(args && args.edit !== undefined ? args.edit : true);
                this.isEdit = (args && args.edit !== undefined ? args.edit : this.isEdit);
            }
            else Eif (!this.parent.isAdaptive) {
                this.isEdit = (args && args.edit !== undefined ? args.edit : false);
                this.renderDialogLayout();
                if (args && args.edit) {
                    var target = this.treeObj.element.querySelector('li[data-field="' + args.fieldName + '"]');
                    Eif (target) {
                        ej2_base_1.addClass([target], ['e-active', 'e-node-focus']);
                        target.setAttribute('aria-selected', 'true');
                        target.id = this.treeObj.element.id + '_active';
                        Eif (this.parent.dataType === 'pivot') {
                            var e = { event: { target: target.querySelector('.e-list-icon.e-edit.e-icons') } };
                            this.fieldClickHandler(e);
                        }
                        else {
                            this.displayMenu(target);
                        }
                    }
                }
                var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
                dialog.element.style.top = parseInt(dialog.element.style.top, 10) < 0 ? '0px' : dialog.element.style.top;
            }
        };
        CalculatedField.prototype.renderDialogLayout = function () {
            this.newFields =
                ej2_base_1.extend([], this.parent.dataSourceSettings.calculatedFieldSettings, null, true);
            this.createDialog();
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'calculateddialog', document), ej2_popups_1.Dialog);
            dialog.content = this.renderDialogElements();
            dialog.refresh();
            var inputObj = new ej2_inputs_1.MaskedTextBox({
                placeholder: this.parent.localeObj.getConstant('fieldName'),
                locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                cssClass: this.parent.cssClass
            });
            inputObj.isStringTemplate = true;
            inputObj.appendTo(ej2_base_1.select('#' + this.parentID + 'ddlelement', dialog.element));
            this.createDropElements();
            this.createTreeView();
            this.droppable = new ej2_base_1.Droppable(ej2_base_1.select('#' + this.parentID + 'droppable', dialog.element));
            this.keyboardEvents = new ej2_base_2.KeyboardEvents(dialog.element, {
                keyAction: this.keyActionHandler.bind(this),
                keyConfigs: { moveRight: 'rightarrow', enter: 'enter', shiftE: 'shift+E', delete: 'delete' },
                eventName: 'keydown'
            });
        };
        CalculatedField.prototype.createConfirmDialog = function (title, description, calcInfo, isRemove, node) {
            var errorDialog = ej2_base_1.createElement('div', {
                id: this.parentID + '_CalculatedFieldErrorDialog',
                className: cls.ERROR_DIALOG_CLASS
            });
            this.parent.element.appendChild(errorDialog);
            var confirmPopUp = new ej2_popups_1.Dialog({
                animationSettings: { effect: 'Fade' },
                allowDragging: false,
                showCloseIcon: true,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                width: 'auto',
                height: 'auto',
                position: { X: 'center', Y: 'center' },
                buttons: [
                    {
                        click: isRemove ? this.removeCalcField.bind(this, node) : this.replaceFormula.bind(this, calcInfo),
                        isFlat: false,
                        buttonModel: {
                            cssClass: cls.OK_BUTTON_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                            content: isRemove ? this.parent.localeObj.getConstant('yes') : this.parent.localeObj.getConstant('ok'), isPrimary: true
                        }
                    },
                    {
                        click: this.closeErrorDialog.bind(this),
                        isFlat: false,
                        buttonModel: {
                            cssClass: cls.CANCEL_BUTTON_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                            content: isRemove ? this.parent.localeObj.getConstant('no') : this.parent.localeObj.getConstant('cancel')
                        }
                    }
                ],
                header: title,
                content: description,
                isModal: true,
                visible: true,
                closeOnEscape: true,
                target: document.body,
                cssClass: this.parent.cssClass,
                close: this.removeErrorDialog.bind(this)
            });
            confirmPopUp.isStringTemplate = true;
            confirmPopUp.appendTo(errorDialog);
        };
        CalculatedField.prototype.replaceFormula = function (calcInfo) {
            var report = this.parent.dataSourceSettings;
            Iif (this.parent.dataType === 'olap') {
                for (var j = 0; j < report.calculatedFieldSettings.length; j++) {
                    if (report.calculatedFieldSettings[j].name === calcInfo.name) {
                        if (!ej2_base_2.isNullOrUndefined(calcInfo.hierarchyUniqueName)) {
                            report.calculatedFieldSettings[j].hierarchyUniqueName = calcInfo.hierarchyUniqueName;
                        }
                        report.calculatedFieldSettings[j].formatString = calcInfo.formatString;
                        report.calculatedFieldSettings[j].formula = calcInfo.formula;
                        this.parent.lastCalcFieldInfo = report.calculatedFieldSettings[j];
                        break;
                    }
                }
            }
            else {
                for (var i = 0; i < report.values.length; i++) {
                    if (report.values[i].type === CALC && report.values[i].name === calcInfo.name) {
                        for (var j = 0; j < report.calculatedFieldSettings.length; j++) {
                            if (report.calculatedFieldSettings[j].name === calcInfo.name) {
                                report.calculatedFieldSettings[j].formula = calcInfo.formula;
                                this.parent.lastCalcFieldInfo =
                                    report.calculatedFieldSettings[j].properties ?
                                        report.calculatedFieldSettings[j].properties :
                                        report.calculatedFieldSettings[j];
                                this.updateFormatSettings(report, calcInfo.name, calcInfo.formatString);
                            }
                        }
                    }
                }
            }
            this.addFormula(report, calcInfo.name);
            this.removeErrorDialog();
        };
        CalculatedField.prototype.removeErrorDialog = function () {
            var element = ej2_base_1.select('#' + this.parentID + '_CalculatedFieldErrorDialog', document);
            var confirmPopUp = element ? ej2_base_1.getInstance(element, ej2_popups_1.Dialog) : null;
            if (confirmPopUp && !confirmPopUp.isDestroyed) {
                confirmPopUp.destroy();
            }
            if (ej2_base_1.select('#' + this.parentID + '_CalculatedFieldErrorDialog', document) !== null) {
                ej2_base_1.remove(ej2_base_1.select('#' + this.parentID + '_CalculatedFieldErrorDialog', document));
            }
        };
        CalculatedField.prototype.closeErrorDialog = function () {
            var confirmPopUp = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + '_CalculatedFieldErrorDialog', document), ej2_popups_1.Dialog);
            confirmPopUp.close();
        };
        CalculatedField.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.initCalculatedField, this.createCalculatedFieldDialog, this);
        };
        CalculatedField.prototype.removeEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.initCalculatedField, this.createCalculatedFieldDialog);
        };
        CalculatedField.prototype.destroy = function () {
            if (this.treeObj && !this.treeObj.isDestroyed) {
                this.treeObj.destroy();
            }
            if (this.treeObj) {
                this.treeObj = null;
            }
            if (this.newFields) {
                this.newFields = null;
            }
            if (this.curMenu) {
                this.curMenu = null;
            }
            if (this.droppable) {
                this.droppable = null;
            }
            if (this.keyboardEvents) {
                this.keyboardEvents = null;
            }
            var element = ej2_base_1.select('#' + this.parentID + 'ddlelement', document);
            if (element) {
                ej2_base_1.getInstance(element, ej2_inputs_1.MaskedTextBox).destroy();
            }
            element = ej2_base_1.select('#' + this.parentID + 'calculateddialog', document);
            if (element) {
                ej2_base_1.getInstance(element, ej2_popups_1.Dialog).destroy();
            }
            element = ej2_base_1.select('#' + this.parentID + 'CalcContextmenu', document);
            if (element) {
                ej2_base_1.getInstance(element, ej2_navigations_2.ContextMenu).destroy();
            }
            element = ej2_base_1.select('#' + this.parentID + 'accordDiv', document);
            Iif (element) {
                ej2_base_1.getInstance(element, ej2_navigations_3.Accordion).destroy();
            }
            element = ej2_base_1.select('#' + this.parentID + '_CalculatedFieldErrorDialog', document);
            if (element) {
                ej2_base_1.getInstance(element, ej2_popups_1.Dialog).destroy();
            }
        };
        return CalculatedField;
    }());
    exports.CalculatedField = CalculatedField;
});