all files / grid/actions/ edit.js

94.8% Statements 620/654
85.78% Branches 579/675
98.51% Functions 66/67
94.76% Lines 615/649
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   282× 282× 282× 282× 282× 282× 282× 282× 282× 282× 282× 282×   296× 296× 1726× 28× 28×     1698×         296×   20935×   365× 337×   28× 28× 29× 29×                 286×   286× 286×   288×   118× 118×     10×   108× 108× 22×     86× 78×   104× 19× 19×   104× 104× 104×   103× 102×   104×   103× 103× 103× 103× 103×     254× 254×     252× 11×     43×   10× 10×   33× 33× 33× 33× 33×     796×   144×   143× 143× 118×   143× 137× 137× 136× 136×     70× 70×   69× 48×     65×   59×       141×   18× 18× 18× 14× 14×     127×   50×         74×   129×   1112×     91×   137× 128×   137× 137× 137×   63× 63× 63× 63×     1021× 1021×   411× 411×   40×   40×     61×     58×   61×       1021×   2616× 2616× 54× 54×   2616× 2616× 263× 262×   263×     282×                           282×                   564× 564× 564×                   564× 564× 564× 564× 564× 564×   46× 30×   46× 46× 46× 46×   32×         10× 10×   12× 12×   12× 12×   12× 12×   32×   277× 79× 79×   277×   283×   282×               282× 282× 282× 282× 282×   576× 298×   278× 278× 278×   387× 387× 92×   387× 11×   387×   310× 310× 48×     48×   48× 48× 48×   42× 42× 42×                       48×     48× 48×   48× 48×           48× 26×   48×         2266× 304×               304× 304× 982× 982× 967× 967× 323×   967×     304×   973×   973× 973× 973× 34×   973×         973×   973× 182×   973×   486×       483× 483× 483×       483× 483× 483×   483×   483×   30× 30×       353× 353× 353×     353× 1199×     353× 1223× 1223× 1223× 1223×         1223×       353× 353× 1139× 971×   971×     22×         946× 946× 5659× 946× 1891×   384× 383× 383×         945×   577× 577×     577×   577× 575×   576× 576× 576× 278× 277×   575× 575× 277× 277×   575×   574× 574×     124× 124×     124×           19× 19×   19×           11× 11× 11×   11×   19×                   60× 60×     65× 10× 10× 10×               67×                                             25× 25×   12×   377× 377× 377×         377× 377× 377× 377× 377× 377× 1335×   58×   1277× 215×     377× 377×   415× 415×       380×     93× 93×           93×               71×   93× 93×       72× 71× 71× 71× 65×           449× 449× 449× 449× 424×   424×       25×   449×   109× 109× 108× 108× 108×       381× 378× 378× 46× 46× 22×     378× 150× 108× 108×     42×         65× 65× 65×   65× 65× 65× 65× 65× 65× 65× 65× 65× 65×   65× 65× 65× 27× 27×       65× 61×         61×           65×     65× 65×   65× 65× 65×               65×     65×   65× 65× 65× 65×     60× 60× 60×   65× 65× 65×                                   64×     60×                   58×       65× 65×     65×     65×           65× 65×       65×     64×   65× 33× 33×   65×                                 1327×                    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../renderer/edit-renderer", "../renderer/boolean-edit-cell", "../renderer/dropdown-edit-cell", "../renderer/numeric-edit-cell", "../renderer/default-edit-cell", "./inline-edit", "./batch-edit", "./dialog-edit", "@syncfusion/ej2-popups", "../base/util", "@syncfusion/ej2-inputs", "../renderer/datepicker-edit-cell", "@syncfusion/ej2-popups", "../renderer/template-edit-cell", "@syncfusion/ej2-data", "../base/util", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, ej2_base_3, ej2_base_4, events, edit_renderer_1, boolean_edit_cell_1, dropdown_edit_cell_1, numeric_edit_cell_1, default_edit_cell_1, inline_edit_1, batch_edit_1, dialog_edit_1, ej2_popups_1, util_1, ej2_inputs_1, datepicker_edit_cell_1, ej2_popups_2, template_edit_cell_1, ej2_data_1, util_2, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Edit = (function () {
        function Edit(parent, serviceLocator) {
            this.isShowAddedRowValidate = false;
            this.editType = { 'Inline': inline_edit_1.InlineEdit, 'Normal': inline_edit_1.InlineEdit, 'Batch': batch_edit_1.BatchEdit, 'Dialog': dialog_edit_1.DialogEdit };
            this.fieldname = '';
            this.data = {};
            this.editCellDialogClose = false;
            this.parent = parent;
            this.serviceLocator = serviceLocator;
            this.l10n = this.serviceLocator.getService('localization');
            this.addEventListener();
            this.updateEditObj();
            this.createAlertDlg();
            this.createConfirmDlg();
        }
        Edit.prototype.updateColTypeObj = function () {
            var cols = this.parent.columnModel;
            for (var i = 0; i < cols.length; i++) {
                if (this.parent.editSettings.template || cols[parseInt(i.toString(), 10)].editTemplate) {
                    var templteCell = 'templateedit';
                    cols[parseInt(i.toString(), 10)].edit = ej2_base_2.extend(new Edit.editCellType["" + templteCell](this.parent), cols[parseInt(i.toString(), 10)].edit || {});
                }
                else {
                    cols[parseInt(i.toString(), 10)].edit = ej2_base_2.extend(new Edit.editCellType[cols[parseInt(i.toString(), 10)].editType
                        && Edit.editCellType[cols[parseInt(i.toString(), 10)].editType] ?
                        cols[parseInt(i.toString(), 10)].editType : 'defaultedit'](this.parent, this.serviceLocator), cols[parseInt(i.toString(), 10)].edit || {});
                }
            }
            this.parent.log('primary_column_missing');
        };
        Edit.prototype.getModuleName = function () {
            return 'edit';
        };
        Edit.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            var gObj = this.parent;
            for (var _i = 0, _a = Object.keys(e.properties); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'allowAdding':
                    case 'allowDeleting':
                    case 'allowEditing':
                        if (gObj.editSettings.allowAdding || gObj.editSettings.allowEditing || gObj.editSettings.allowDeleting) {
                            this.initialEnd();
                        }
                        break;
                    case 'mode':
                        this.updateEditObj();
                        gObj.isEdit = gObj.editSettings.showAddNewRow ? true : false;
                        gObj.refresh();
                        break;
                }
            }
        };
        Edit.prototype.updateEditObj = function () {
            if (this.editModule) {
                this.editModule.destroy();
            }
            this.renderer = new edit_renderer_1.EditRender(this.parent, this.serviceLocator);
            this.editModule = new this.editType[this.parent.editSettings.mode](this.parent, this.serviceLocator, this.renderer);
        };
        Edit.prototype.initialEnd = function () {
            this.updateColTypeObj();
        };
        Edit.prototype.startEdit = function (tr) {
            var gObj = this.parent;
            if (!gObj.editSettings.allowEditing || (gObj.isEdit && (!gObj.editSettings.showAddNewRow ||
                (gObj.editSettings.showAddNewRow && !ej2_base_4.isNullOrUndefined(gObj.element.querySelector('.' + literals.editedRow)))))
                || gObj.editSettings.mode === 'Batch') {
                return;
            }
            this.parent.element.classList.add('e-editing');
            if (!gObj.getSelectedRows().length || ej2_base_4.isNullOrUndefined(this.parent.getRowByIndex(parseInt(this.parent.getSelectedRows()[0].getAttribute('data-rowindex'), 10)))) {
                if (!tr) {
                    this.showDialog('EditOperationAlert', this.alertDObj);
                    return;
                }
            }
            else if (!tr) {
                tr = gObj.getSelectedRows()[0];
            }
            if (this.parent.enableVirtualization && this.parent.editSettings.mode === 'Normal') {
                var idx = parseInt(tr.getAttribute('data-rowindex'), 10);
                tr = this.parent.getRowByIndex(idx);
            }
            var lastTr = gObj.getContent().querySelector('tr:last-child');
            var hdrTbody = gObj.getHeaderContent().querySelector('tbody');
            if (gObj.frozenRows && ej2_base_4.isNullOrUndefined(lastTr) && hdrTbody && hdrTbody.querySelector('tr:last-child')) {
                this.isLastRow = tr.rowIndex === parseInt(gObj.getHeaderContent().querySelector('tbody').querySelector('tr:last-child').getAttribute('data-rowindex'), 10);
            }
            else if (lastTr) {
                this.isLastRow = tr.rowIndex === lastTr.rowIndex;
            }
            if (tr.style.display === 'none') {
                return;
            }
            this.editModule.startEdit(tr);
            this.refreshToolbar();
            gObj.element.querySelector('.e-gridpopup').style.display = 'none';
            this.parent.notify('start-edit', {});
            if (gObj.editSettings.showAddNewRow) {
                this.destroyToolTip();
            }
        };
        Edit.prototype.checkLastRow = function (tr, args) {
            var checkLastRow = this.isLastRow;
            if (this.parent.height !== 'auto' && this.parent.editSettings.newRowPosition === 'Bottom' && args && args.requestType === 'add' &&
                this.parent.getContent().firstElementChild.offsetHeight > this.parent.getContentTable().scrollHeight) {
                ej2_base_1.addClass([].slice.call(tr.getElementsByClassName(literals.rowCell)), 'e-lastrowadded');
            }
            else if (checkLastRow && tr && tr.classList) {
                ej2_base_1.addClass([].slice.call(tr.getElementsByClassName(literals.rowCell)), 'e-lastrowcell');
            }
        };
        Edit.prototype.closeEdit = function () {
            if (this.parent.editSettings.mode === 'Batch' && this.parent.editSettings.showConfirmDialog
                && this.parent.element.getElementsByClassName('e-updatedtd').length) {
                this.showDialog('CancelEdit', this.dialogObj);
                return;
            }
            this.parent.element.classList.remove('e-editing');
            this.editModule.closeEdit();
            this.refreshToolbar();
            this.parent.notify(events.closeEdit, {});
            if (this.parent.editSettings.showAddNewRow) {
                this.destroyToolTip();
            }
        };
        Edit.prototype.refreshToolbar = function () {
            this.parent.notify(events.toolbarRefresh, {});
        };
        Edit.prototype.addRecord = function (data, index) {
            if (!this.parent.editSettings.allowAdding) {
                return;
            }
            var args = { startEdit: true };
            if (!data) {
                this.parent.notify(events.virtualScrollAddActionBegin, args);
            }
            if (args.startEdit) {
                this.parent.element.classList.add('e-editing');
                this.editModule.addRecord(data, index);
                this.refreshToolbar();
                this.parent.notify('start-add', {});
            }
        };
        Edit.prototype.deleteRecord = function (fieldname, data) {
            var gObj = this.parent;
            if (!gObj.editSettings.allowDeleting) {
                return;
            }
            if (!data) {
                if (!gObj.getSelectedRecords().length && ej2_base_4.isNullOrUndefined(gObj.commandDelIndex)) {
                    this.showDialog('DeleteOperationAlert', this.alertDObj);
                    return;
                }
            }
            if (gObj.editSettings.showDeleteConfirmDialog) {
                this.fieldname = fieldname;
                this.data = data;
                this.showDialog('ConfirmDelete', this.dialogObj);
                return;
            }
            this.editModule.deleteRecord(fieldname, data);
        };
        Edit.prototype.deleteRow = function (tr) {
            this.deleteRowUid = tr.getAttribute('data-uid');
            var rowObj = this.parent.getRowObjectFromUID(this.deleteRowUid);
            if (!ej2_base_4.isNullOrUndefined(rowObj)) {
                this.deleteRecord(null, rowObj.data);
            }
        };
        Edit.prototype.endEdit = function () {
            if (this.parent.editSettings.mode === 'Batch' && this.parent.editSettings.showConfirmDialog &&
                (ej2_base_4.isNullOrUndefined(this.formObj) || this.formObj.validate())) {
                this.parent.editModule.saveCell();
                this.parent.notify(events.editNextValCell, {});
                if (ej2_base_4.isNullOrUndefined(this.formObj) || this.formObj.validate()) {
                    this.showDialog('BatchSaveConfirm', this.dialogObj);
                    return;
                }
            }
            this.endEditing();
        };
        Edit.prototype.updateCell = function (rowIndex, field, value) {
            this.editModule.updateCell(rowIndex, field, value);
        };
        Edit.prototype.updateRow = function (index, data) {
            this.editModule.updateRow(index, data);
        };
        Edit.prototype.batchCancel = function () {
            this.closeEdit();
        };
        Edit.prototype.batchSave = function () {
            this.endEdit();
        };
        Edit.prototype.editCell = function (index, field) {
            this.editModule.editCell(index, field);
        };
        Edit.prototype.editFormValidate = function () {
            return this.formObj ? this.formObj.validate() : true;
        };
        Edit.prototype.getBatchChanges = function () {
            return this.editModule.getBatchChanges ? this.editModule.getBatchChanges() : {};
        };
        Edit.prototype.getCurrentEditCellData = function () {
            var obj = this.getCurrentEditedData(this.formObj.element, {});
            return obj[Object.keys(obj)[0]];
        };
        Edit.prototype.saveCell = function () {
            this.editModule.saveCell();
        };
        Edit.prototype.endEditing = function () {
            if (!this.parent.editSettings.showAddNewRow) {
                this.parent.element.classList.remove('e-editing');
            }
            this.editModule.endEdit();
            this.isShowAddedRowValidate = false;
            this.refreshToolbar();
        };
        Edit.prototype.showDialog = function (content, obj) {
            obj.content = '<div>' + this.l10n.getConstant(content) + '</div>';
            obj.dataBind();
            obj.show();
            if (this.parent.enableRtl) {
                obj.refresh();
            }
        };
        Edit.prototype.getValueFromType = function (col, value) {
            var val = value;
            switch (col.type) {
                case 'number':
                    val = !isNaN(parseFloat(value)) ? parseFloat(value) : null;
                    break;
                case 'boolean':
                    if (col.editType !== 'booleanedit') {
                        val = value === this.l10n.getConstant('True') || value === true ? true : false;
                    }
                    break;
                case 'date':
                case 'datetime':
                    if (col.editType !== 'datepickeredit' && col.editType !== 'datetimepickeredit'
                        && value && value.length) {
                        val = new Date(value);
                    }
                    else if (value === '') {
                        val = null;
                    }
                    break;
                case 'dateonly':
                    val = value && (value = new Date(value)) ?
                        value.getFullYear() + '-' + util_2.padZero(value.getMonth() + 1) + '-' + util_2.padZero(value.getDate()) : null;
                    break;
            }
            return val;
        };
        Edit.prototype.destroyToolTip = function () {
            var elements = [].slice.call(this.parent.element.getElementsByClassName('e-griderror'));
            for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
                var elem = elements_1[_i];
                ej2_base_3.remove(elem);
            }
            this.parent.getContent().firstElementChild.style.position = 'relative';
            if (this.parent.isFrozenGrid()) {
                if (this.parent.element.querySelector('.e-gridheader')) {
                    this.parent.element.querySelector('.e-gridheader').style.position = '';
                }
                this.parent.element.querySelector('.e-gridcontent').style.position = '';
            }
        };
        Edit.prototype.createConfirmDlg = function () {
            this.dialogObj = this.dlgWidget([
                {
                    click: this.dlgOk.bind(this),
                    buttonModel: { content: this.l10n.getConstant('OKButton'),
                        cssClass: this.parent.cssClass ? 'e-primary' + ' ' + this.parent.cssClass : 'e-primary',
                        isPrimary: true }
                },
                {
                    click: this.dlgCancel.bind(this),
                    buttonModel: { cssClass: this.parent.cssClass ? 'e-flat' + ' ' + this.parent.cssClass : 'e-flat',
                        content: this.l10n.getConstant('CancelButton') }
                }
            ], 'EditConfirm');
        };
        Edit.prototype.createAlertDlg = function () {
            this.alertDObj = this.dlgWidget([
                {
                    click: this.alertClick.bind(this),
                    buttonModel: { content: this.l10n.getConstant('OKButton'),
                        cssClass: this.parent.cssClass ? 'e-flat' + ' ' + this.parent.cssClass : 'e-flat',
                        isPrimary: true }
                }
            ], 'EditAlert');
        };
        Edit.prototype.alertClick = function () {
            this.alertDObj.hide();
        };
        Edit.prototype.dlgWidget = function (btnOptions, name) {
            var div = this.parent.createElement('div', { id: this.parent.element.id + name });
            this.parent.element.appendChild(div);
            var options = {
                showCloseIcon: false,
                isModal: true,
                visible: false,
                closeOnEscape: true,
                target: this.parent.element,
                width: '320px',
                animationSettings: { effect: 'None' },
                cssClass: this.parent.cssClass ? this.parent.cssClass : ''
            };
            options.buttons = btnOptions;
            var obj = new ej2_popups_1.Dialog(options);
            var isStringTemplate = 'isStringTemplate';
            obj["" + isStringTemplate] = true;
            obj.appendTo(div);
            return obj;
        };
        Edit.prototype.dlgCancel = function () {
            if (this.parent.pagerModule) {
                this.parent.pagerModule.isForceCancel = false;
            }
            this.parent.focusModule.clearIndicator();
            this.parent.focusModule.restoreFocus();
            this.dialogObj.hide();
            this.parent.notify('cancelcnfrmDlg', {});
        };
        Edit.prototype.dlgOk = function () {
            switch (this.dialogObj.element.querySelector('.e-dlg-content').firstElementChild.innerText) {
                case this.l10n.getConstant('ConfirmDelete'):
                    this.editModule.deleteRecord(this.fieldname, this.data);
                    if (this.parent.editSettings.showDeleteConfirmDialog && !this.parent.allowSelection) {
                        this.parent.commandDelIndex = undefined;
                    }
                    break;
                case this.l10n.getConstant('CancelEdit'):
                    this.editModule.closeEdit();
                    break;
                case this.l10n.getConstant('BatchSaveConfirm'):
                    this.endEditing();
                    break;
                case this.l10n.getConstant('BatchSaveLostChanges'):
                    Eif (this.parent.editSettings.mode === 'Batch') {
                        this.editModule.addCancelWhilePaging();
                    }
                    Eif (this.parent.pagerModule) {
                        this.parent.pagerModule.isForceCancel = false;
                    }
                    this.executeAction();
                    break;
            }
            this.dlgCancel();
        };
        Edit.prototype.destroyEditComponents = function () {
            if (this.parent.isEdit) {
                this.destroyWidgets();
                this.destroyForm();
            }
            this.destroy();
        };
        Edit.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.eventDetails = [{ event: events.inBoundModelChanged, handler: this.onPropertyChanged },
                { event: events.initialEnd, handler: this.initialEnd },
                { event: events.keyPressed, handler: this.keyPressHandler },
                { event: events.autoCol, handler: this.updateColTypeObj },
                { event: events.tooltipDestroy, handler: this.destroyToolTip },
                { event: events.preventBatch, handler: this.preventBatch },
                { event: events.destroyForm, handler: this.destroyForm },
                { event: events.destroy, handler: this.destroyEditComponents }];
            util_2.addRemoveEventListener(this.parent, this.eventDetails, true, this);
            this.actionBeginFunction = this.onActionBegin.bind(this);
            this.actionCompleteFunction = this.actionComplete.bind(this);
            this.parent.addEventListener(events.actionBegin, this.actionBeginFunction);
            this.parent.addEventListener(events.actionComplete, this.actionCompleteFunction);
        };
        Edit.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            util_2.addRemoveEventListener(this.parent, this.eventDetails, false);
            this.parent.removeEventListener(events.actionComplete, this.actionCompleteFunction);
            this.parent.removeEventListener(events.actionBegin, this.actionBeginFunction);
        };
        Edit.prototype.actionComplete = function (e) {
            var actions = ['add', 'beginEdit', 'save', 'delete', 'cancel', 'filterAfterOpen', 'filterchoicerequest'];
            if (actions.indexOf(e.requestType) < 0) {
                this.parent.isEdit = this.parent.editSettings.showAddNewRow ? true : false;
            }
            if (e.requestType === 'batchsave') {
                this.parent.focusModule.restoreFocus();
            }
            this.refreshToolbar();
        };
        Edit.prototype.getCurrentEditedData = function (form, editedData) {
            var gObj = this.parent;
            if (gObj.editSettings.template) {
                var elements = [].slice.call(form.elements);
                for (var k = 0; k < elements.length; k++) {
                    Eif (((elements[parseInt(k.toString(), 10)].hasAttribute('name') && (elements[parseInt(k.toString(), 10)].className !== 'e-multi-hidden')) ||
                        elements[parseInt(k.toString(), 10)].classList.contains('e-multiselect')) && !(elements[parseInt(k.toString(), 10)].type === 'hidden' &&
                        (util_1.parentsUntil(elements[parseInt(k.toString(), 10)], 'e-switch-wrapper') || util_1.parentsUntil(elements[parseInt(k.toString(), 10)], 'e-checkbox-wrapper')))) {
                        var field = (elements[parseInt(k.toString(), 10)].hasAttribute('name')) ? util_1.setComplexFieldID(elements[parseInt(k.toString(), 10)].getAttribute('name')) :
                            util_1.setComplexFieldID(elements[parseInt(k.toString(), 10)].getAttribute('id'));
                        var column = gObj.getColumnByField(field) || { field: field, type: elements[parseInt(k.toString(), 10)].getAttribute('type') };
                        var value = void 0;
                        if (column.type === 'checkbox' || column.type === 'boolean') {
                            value = elements[parseInt(k.toString(), 10)].checked;
                        }
                        else Eif (elements[parseInt(k.toString(), 10)].value) {
                            value = elements[parseInt(k.toString(), 10)].value;
                            Iif (elements[parseInt(k.toString(), 10)].ej2_instances &&
                                elements[parseInt(k.toString(), 10)].ej2_instances.length &&
                                !ej2_base_4.isNullOrUndefined(elements[parseInt(k.toString(), 10)].ej2_instances[0].value)) {
                                elements[parseInt(k.toString(), 10)].blur();
                                value = elements[parseInt(k.toString(), 10)]
                                    .ej2_instances[0].value;
                            }
                        }
                        else if (elements[parseInt(k.toString(), 10)].ej2_instances) {
                            value = elements[parseInt(k.toString(), 10)]
                                .ej2_instances[0].value;
                        }
                        Iif (column.edit && typeof column.edit.read === 'string') {
                            value = ej2_base_2.getValue(column.edit.read, window)(elements[parseInt(k.toString(), 10)], value);
                        }
                        else Eif (column.edit && column.edit.read) {
                            value = column.edit.read(elements[parseInt(k.toString(), 10)], value);
                        }
                        value = gObj.editModule.getValueFromType(column, value);
                        Iif (elements[parseInt(k.toString(), 10)].type === 'radio') {
                            if (elements[parseInt(k.toString(), 10)].checked) {
                                ej2_data_1.DataUtil.setValue(column.field, value, editedData);
                            }
                        }
                        else {
                            if (typeof value === 'string') {
                                this.parent.sanitize(value);
                            }
                            ej2_data_1.DataUtil.setValue(column.field, value, editedData);
                        }
                    }
                }
                return editedData;
            }
            var col = gObj.columnModel.filter(function (col) { return col.editTemplate; });
            for (var j = 0; j < col.length; j++) {
                Eif (form[util_1.getComplexFieldID(col[parseInt(j.toString(), 10)].field)]) {
                    var inputElements = [].slice.call(form[util_1.getComplexFieldID(col[parseInt(j.toString(), 10)].field)])
                        .filter(function (element) { return element.tagName.toLowerCase() === 'input'; });
                    inputElements = inputElements.length ? inputElements : [form[util_1.getComplexFieldID(col[parseInt(j.toString(), 10)].field)]];
                    var temp = inputElements.filter(function (e) {
                        return !ej2_base_4.isNullOrUndefined((e.ej2_instances));
                    });
                    Eif (temp.length === 0) {
                        temp = inputElements.filter(function (e) { return e.hasAttribute('name'); });
                    }
                    for (var k = 0; k < temp.length; k++) {
                        var value = this.getValue(col[parseInt(j.toString(), 10)], temp[parseInt(k.toString(), 10)], editedData);
                        Eif (col[parseInt(j.toString(), 10)].type === 'string') {
                            value = this.parent.sanitize(value);
                        }
                        ej2_data_1.DataUtil.setValue(col[parseInt(j.toString(), 10)].field, value, editedData);
                    }
                }
            }
            var inputs = [].slice.call(form.getElementsByClassName('e-field'));
            for (var i = 0, len = inputs.length; i < len; i++) {
                var col_1 = gObj.getColumnByUid(inputs[parseInt(i.toString(), 10)].getAttribute('e-mappinguid'));
                if (col_1 && col_1.field) {
                    var value = this.getValue(col_1, inputs[parseInt(i.toString(), 10)], editedData);
                    if (col_1.type === 'string' && !(col_1.isForeignColumn() && typeof value !== 'string')) {
                        value = this.parent.sanitize(value);
                    }
                    ej2_data_1.DataUtil.setValue(col_1.field, value, editedData);
                }
            }
            return editedData;
        };
        Edit.prototype.getValue = function (col, input, editedData) {
            var value = input.ej2_instances ?
                input.ej2_instances[0].value : input.value;
            var gObj = this.parent;
            var temp = col.edit.read;
            if (col.type === 'checkbox' || col.type === 'boolean') {
                value = input.checked;
            }
            Iif (typeof temp === 'string') {
                temp = ej2_base_2.getValue(temp, window);
                value = gObj.editModule.getValueFromType(col, (temp)(input, value));
            }
            else {
                value = gObj.editModule.getValueFromType(col, col.edit.read(input, value));
            }
            if (ej2_base_4.isNullOrUndefined(editedData[col.field]) && value === '') {
                value = editedData[col.field];
            }
            return value;
        };
        Edit.prototype.onActionBegin = function (e) {
            if ((e.requestType === 'columnstate' || (this.parent.enableInfiniteScrolling && this.parent.infiniteScrollSettings.enableCache
                && e.requestType === 'sorting')) && this.parent.isEdit && this.parent.editSettings.mode !== 'Batch') {
                this.closeEdit();
            }
            else {
                var editRow = this.parent.element.querySelector('.' + literals.editedRow);
                var addRow = this.parent.element.querySelector('.' + literals.addedRow);
                Iif (editRow && this.parent.frozenRows && e.requestType === 'virtualscroll'
                    && parseInt(util_1.parentsUntil(editRow, literals.row).getAttribute(literals.dataRowIndex), 10) < this.parent.frozenRows) {
                    return;
                }
                var restrictedRequestTypes = ['filterAfterOpen', 'filterBeforeOpen', 'filterchoicerequest', 'filterSearchBegin', 'save', 'infiniteScroll', 'virtualscroll'];
                var isRestrict = restrictedRequestTypes.indexOf(e.requestType) === -1;
                var isAddRows = !this.parent.editSettings.showAddNewRow || (this.parent.editSettings.showAddNewRow &&
                    !ej2_base_4.isNullOrUndefined(this.parent.element.querySelector('.e-editedrow')));
                var isDestroyVirtualForm = (this.parent.enableVirtualization || this.parent.enableInfiniteScrolling) && this.formObj
                    && isAddRows && !this.formObj.isDestroyed && (editRow || addRow || e.requestType === 'cancel') && isRestrict;
                if ((!this.parent.enableVirtualization && isAddRows && this.parent.editSettings.mode !== 'Batch' && this.formObj && !this.formObj.isDestroyed
                    && isRestrict && !e.cancel) || isDestroyVirtualForm) {
                    this.destroyWidgets();
                    this.destroyForm();
                }
            }
        };
        Edit.prototype.destroyWidgets = function (cols) {
            var gObj = this.parent;
            gObj.isWidgetsDestroyed = true;
            if (gObj.editSettings.template) {
                var parentIns = util_2.getParentIns(this.parent);
                parentIns = parentIns.isReact ? parentIns : this.parent;
                parentIns.destroyTemplate(['editSettingsTemplate']);
                if (this.parent.isReact) {
                    this.parent.renderTemplates();
                }
            }
            cols = cols ? cols : this.parent.getCurrentVisibleColumns(this.parent.enableColumnVirtualization);
            if (cols.some(function (column) { return !ej2_base_4.isNullOrUndefined(column.editTemplate); })) {
                this.parent.destroyTemplate(['editTemplate']);
                if (this.parent.isReact) {
                    this.parent.renderTemplates();
                }
            }
            for (var _i = 0, cols_1 = cols; _i < cols_1.length; _i++) {
                var col = cols_1[_i];
                var temp = col.edit.destroy;
                Eif (col.edit.destroy) {
                    Iif (typeof temp === 'string') {
                        temp = ej2_base_2.getValue(temp, window);
                        temp();
                    }
                    else {
                        col.edit.destroy();
                    }
                }
            }
            var elements = [].slice.call(this.formObj.element.elements);
            for (var i = 0; i < elements.length; i++) {
                if (elements[parseInt(i.toString(), 10)].hasAttribute('name')) {
                    var instanceElement = elements[parseInt(i.toString(), 10)].parentElement.classList.contains('e-ddl') ?
                        elements[parseInt(i.toString(), 10)].parentElement.querySelector('input') : elements[parseInt(i.toString(), 10)];
                    if (instanceElement.ej2_instances &&
                        instanceElement.ej2_instances.length &&
                        !instanceElement.ej2_instances[0].isDestroyed) {
                        instanceElement.ej2_instances[0].destroy();
                    }
                }
            }
        };
        Edit.prototype.destroyForm = function () {
            this.destroyToolTip();
            var formObjects = [this.formObj, this.virtualFormObj];
            var col = this.parent.columnModel.filter(function (col) { return col.editTemplate; });
            for (var i = 0; i < formObjects.length; i++) {
                if (formObjects[parseInt(i.toString(), 10)] && formObjects[parseInt(i.toString(), 10)].element
                    && !formObjects[parseInt(i.toString(), 10)].isDestroyed) {
                    formObjects[parseInt(i.toString(), 10)].destroy();
                    var parentIns = util_2.getParentIns(this.parent);
                    if (parentIns.isReact && this.parent.editSettings.mode === 'Dialog'
                        && (!ej2_base_4.isNullOrUndefined(this.parent.editSettings.template) || col.length)) {
                        formObjects[parseInt(i.toString(), 10)].element.remove();
                    }
                }
            }
            this.destroyToolTip();
        };
        Edit.prototype.destroy = function () {
            var gridElement = this.parent.element;
            Iif (!gridElement) {
                return;
            }
            var hasGridChild = gridElement.querySelector('.' + literals.gridHeader) &&
                gridElement.querySelector('.' + literals.gridContent) ? true : false;
            if (hasGridChild) {
                this.destroyForm();
            }
            this.removeEventListener();
            var elem = this.dialogObj.element;
            if (elem.childElementCount > 0) {
                this.dialogObj.destroy();
                ej2_base_3.remove(elem);
            }
            elem = this.alertDObj.element;
            if (elem.childElementCount > 0) {
                this.alertDObj.destroy();
                ej2_base_3.remove(elem);
            }
            if (!hasGridChild) {
                return;
            }
            Eif (this.editModule) {
                this.editModule.destroy();
            }
        };
        Edit.prototype.keyPressHandler = function (e) {
            var isMacLike = /(Mac)/i.test(navigator.platform);
            Iif (isMacLike && e.metaKey && e.action === 'ctrlEnter') {
                e.action = 'insert';
            }
            switch (e.action) {
                case 'insert':
                    this.addRecord();
                    break;
                case 'delete':
                    Eif ((e.target.tagName !== 'INPUT' || e.target.classList.contains('e-checkselect'))
                        && !document.querySelector('.e-popup-open.e-edit-dialog')) {
                        this.deleteRecord();
                    }
                    break;
                case 'f2':
                    this.startEdit();
                    break;
                case 'enter':
                    if (!util_1.parentsUntil(e.target, 'e-unboundcelldiv') && this.parent.editSettings.mode !== 'Batch' &&
                        (util_1.parentsUntil(e.target, literals.gridContent) || ((this.parent.frozenRows ||
                            (this.parent.editSettings.showAddNewRow && (this.parent.enableVirtualization || this.parent.enableInfiniteScrolling)))
                            && util_1.parentsUntil(e.target, literals.headerContent)))
                        && (!document.getElementsByClassName('e-popup-open').length || (document.querySelectorAll('.e-popup-open .e-editcell').length &&
                            !document.querySelectorAll('.e-popup-open:not(.e-dialog)').length))) {
                        e.preventDefault();
                        Eif (this.parent.isEdit) {
                            this.parent.isFocusFirstCell = true;
                        }
                        this.endEdit();
                    }
                    break;
                case 'escape':
                    Eif (this.parent.isEdit && !this.editCellDialogClose) {
                        if (this.parent.editSettings.mode === 'Batch') {
                            this.editModule.escapeCellEdit();
                        }
                        else {
                            this.curretRowFocus(e);
                        }
                    }
                    Iif (this.editCellDialogClose) {
                        this.editCellDialogClose = false;
                    }
                    break;
                case 'tab':
                case 'shiftTab':
                    this.curretRowFocus(e);
                    break;
            }
        };
        Edit.prototype.curretRowFocus = function (e) {
            if (this.parent.isEdit && this.parent.editSettings.mode !== 'Batch') {
                this.parent.isWidgetsDestroyed = false;
                var editedRow = util_1.parentsUntil(e.target, 'e-editedrow') || util_1.parentsUntil(e.target, 'e-addedrow');
                if (editedRow) {
                    var focusableEditCells = [].slice.call(editedRow.querySelectorAll('.e-input:not(.e-disabled)'));
                    var commandColCell = [].slice.call(editedRow.querySelectorAll('.e-unboundcell'));
                    if (commandColCell && commandColCell.length) {
                        for (var i = 0; i < commandColCell.length; i++) {
                            focusableEditCells = focusableEditCells.concat([].slice
                                .call(commandColCell[parseInt(i.toString(), 10)].querySelectorAll('.e-btn:not(.e-hide)')));
                        }
                    }
                    var rowCell = util_1.parentsUntil(e.target, 'e-rowcell');
                    rowCell = rowCell && rowCell.classList.contains('e-unboundcell') ? e.target : rowCell;
                    var lastCell = util_1.parentsUntil(focusableEditCells[focusableEditCells.length - 1], 'e-rowcell');
                    lastCell = lastCell && lastCell.classList.contains('e-unboundcell') ?
                        focusableEditCells[focusableEditCells.length - 1] : lastCell;
                    if ((rowCell === lastCell && e.action === 'tab') || e.action === 'escape' ||
                        (rowCell === util_1.parentsUntil(focusableEditCells[0], 'e-rowcell') && e.action === 'shiftTab' &&
                            !this.parent.editSettings.showAddNewRow)) {
                        var uid = editedRow.getAttribute('data-uid');
                        var rows = this.parent.allowGrouping ? (!ej2_base_4.isNullOrUndefined(this.parent.getContent()) ?
                            [].slice.call(this.parent.getContent().querySelectorAll('tr')) : []) : this.parent.getRows();
                        var rowIndex = rows.map(function (m) { return m.getAttribute('data-uid'); }).indexOf(uid);
                        Iif (this.parent.frozenRows) {
                            if (util_1.parentsUntil(editedRow, 'e-gridheader')) {
                                rowIndex = editedRow.rowIndex;
                            }
                            else if (util_1.parentsUntil(editedRow, 'e-gridcontent')) {
                                rowIndex = rowIndex - this.parent.frozenRows;
                            }
                        }
                        if (editedRow.classList.contains('e-addedrow')) {
                            rowIndex = 0;
                        }
                        if (e.action === 'escape') {
                            this.parent.isFocusFirstCell = true;
                            this.closeEdit();
                        }
                        else {
                            this.isShowAddedRowValidate = true;
                            this.parent.selectionModule.preventFocus = false;
                            this.parent.isFocusFirstCell = true;
                            this.endEdit();
                            this.isShowAddedRowValidate = false;
                        }
                        if (this.parent.focusModule.active && (!this.parent.editSettings.showAddNewRow ||
                            editedRow.classList.contains('e-editedrow') || (this.parent.editSettings.showAddNewRow &&
                            (editedRow.classList.contains('e-addedrow') && ej2_base_4.isNullOrUndefined(this.parent.element.querySelector('.e-griderror:not([style*="display: none"])')))))) {
                            var firstCellIndex = 0;
                            var matrix = this.parent.focusModule.active.matrix;
                            Eif (matrix && matrix.matrix.length && matrix.matrix[parseInt(rowIndex.toString(), 10)]) {
                                var rowMatrix = matrix.matrix[parseInt(rowIndex.toString(), 10)];
                                for (var i = 0; i < rowMatrix.length; i++) {
                                    if (rowMatrix[parseInt(i.toString(), 10)] > 0) {
                                        firstCellIndex = i;
                                        break;
                                    }
                                }
                            }
                            this.parent.focusModule.active.matrix.current = [rowIndex, firstCellIndex];
                        }
                    }
                    if (this.parent.editSettings.showAddNewRow && e.action === 'tab' && util_1.parentsUntil(e.target, 'e-addedrow')) {
                        this.isShowAddedRowValidate = true;
                    }
                }
            }
        };
        Edit.prototype.preventBatch = function (args) {
            this.preventObj = args;
            this.showDialog('BatchSaveLostChanges', this.dialogObj);
        };
        Edit.prototype.executeAction = function () {
            this.preventObj.handler.call(this.preventObj.instance, this.preventObj.arg1, this.preventObj.arg2, this.preventObj.arg3, this.preventObj.arg4, this.preventObj.arg5, this.preventObj.arg6, this.preventObj.arg7, this.preventObj.arg8);
        };
        Edit.prototype.applyFormValidation = function (cols, newRule) {
            var gObj = this.parent;
            var idx = 0;
            var form = this.parent.editSettings.mode !== 'Dialog' ?
                gObj.editSettings.showAddNewRow && gObj.element.querySelector('.' + literals.editedRow) ?
                    gObj.element.querySelector('.' + literals.editedRow).getElementsByClassName('e-gridform')[parseInt(idx.toString(), 10)] :
                    gObj.element.getElementsByClassName('e-gridform')[parseInt(idx.toString(), 10)] :
                ej2_base_1.select('#' + gObj.element.id + '_dialogEdit_wrapper .e-gridform', document);
            var index = 1;
            var rules = {};
            var mRules = {};
            var frRules = {};
            cols = cols ? cols : gObj.getColumns();
            for (var i = 0; i < cols.length; i++) {
                if (!cols[parseInt(i.toString(), 10)].visible && (gObj.editSettings.mode !== 'Dialog' || (gObj.groupSettings.columns.indexOf(cols[parseInt(i.toString(), 10)].field) === -1
                    && gObj.editSettings.mode === 'Dialog'))) {
                    continue;
                }
                if (cols[parseInt(i.toString(), 10)].validationRules && ej2_base_4.isNullOrUndefined(newRule)) {
                    util_1.setValidationRuels(cols[parseInt(i.toString(), 10)], index, rules, mRules, frRules, cols.length);
                }
            }
            rules = ej2_base_2.extend(rules, mRules, frRules);
            this.parent.editModule.formObj = this.createFormObj(form, newRule ? newRule : rules);
        };
        Edit.prototype.createFormObj = function (form, rules) {
            var _this = this;
            return new ej2_inputs_1.FormValidator(form, {
                rules: rules,
                locale: this.parent.locale,
                validationComplete: function (args) {
                    _this.validationComplete(args);
                },
                customPlacement: function (inputElement, error) {
                    var uid = inputElement.getAttribute('e-mappinguid');
                    var args = {
                        column: _this.parent.getColumnByUid(uid),
                        error: error,
                        inputElement: inputElement,
                        value: inputElement.value
                    };
                    if ((!(event && event['relatedTarget'] && event['relatedTarget'].classList.contains('e-cancelbutton')) &&
                        !_this.parent.editSettings.showAddNewRow) || (_this.parent.editSettings.showAddNewRow && event && event.target &&
                        (util_1.parentsUntil(event.target, _this.parent.element.id + '_update', true) ||
                            (util_1.parentsUntil(event.target, 'e-grid-menu') && (event.target.classList.contains('e-save') ||
                                event.target.querySelector('.e-save'))) || _this.isShowAddedRowValidate ||
                            (util_1.parentsUntil(event.target, 'e-unboundcell') && util_1.parentsUntil(event.target, 'e-update')) ||
                            (event['action'] === 'enter' && (util_1.parentsUntil(event.target, 'e-content') || util_1.parentsUntil(event.target, 'e-addedrow'))))) ||
                        (_this.parent.editSettings.showAddNewRow && !ej2_base_4.isNullOrUndefined(_this.parent.element.querySelector('.' + literals.editedRow)))) {
                        _this.valErrorPlacement(inputElement, error);
                    }
                    _this.isShowAddedRowValidate = false;
                    _this.parent.notify(events.valCustomPlacement, args);
                }
            });
        };
        Edit.prototype.valErrorPlacement = function (inputElement, error) {
            if (this.parent.isEdit) {
                var id = error.getAttribute('for');
                var elem = this.getElemTable(inputElement).querySelector('#' + util_1.getParsedFieldID(id) + '_Error');
                if (!elem) {
                    this.createTooltip(inputElement, error, id, '');
                }
                else {
                    elem.querySelector('.e-tip-content').innerHTML = error.outerHTML;
                }
            }
        };
        Edit.prototype.getElemTable = function (inputElement) {
            var isFrozenHdr;
            var gObj = this.parent;
            var table;
            if (gObj.editSettings.mode !== 'Dialog') {
                isFrozenHdr = (gObj.frozenRows && ej2_base_1.closest(inputElement, '.' + literals.row) && gObj.frozenRows
                    > (parseInt(ej2_base_1.closest(inputElement, '.' + literals.row).getAttribute(literals.dataRowIndex), 10) || 0));
                table = this.parent.isFrozenGrid() ? gObj.element : isFrozenHdr || (gObj.editSettings.showAddNewRow &&
                    (gObj.enableVirtualization || gObj.enableInfiniteScrolling)) ? gObj.getHeaderTable() : gObj.getContentTable();
            }
            else {
                table = ej2_base_1.select('#' + gObj.element.id + '_dialogEdit_wrapper', document);
            }
            return table;
        };
        Edit.prototype.resetElemPosition = function (elem, args) {
            var td = util_1.parentsUntil(args.element, literals.rowCell);
            if (td) {
                var tdRight = td.getBoundingClientRect().right;
                var elemRight = elem.getBoundingClientRect().right;
                if (elemRight > tdRight) {
                    var offSet = elemRight - tdRight;
                    elem.style.left = (elem.offsetLeft - offSet) + 'px';
                }
            }
        };
        Edit.prototype.validationComplete = function (args) {
            if (this.parent.isEdit) {
                var elem = this.getElemTable(args.element).querySelector('#' + util_1.getParsedFieldID(args.inputName) + '_Error');
                if (this.parent.editSettings.showAddNewRow && !elem && args.element) {
                    var error = util_1.parentsUntil(args.element, 'e-rowcell').querySelector('.e-error');
                    if (error) {
                        error.classList.remove('e-error');
                    }
                }
                if (elem) {
                    if (args.status === 'failure') {
                        elem.style.display = '';
                        this.resetElemPosition(elem, args);
                    }
                    else {
                        elem.style.display = 'none';
                    }
                }
            }
        };
        Edit.prototype.createTooltip = function (element, error, name, display) {
            var formObj = this.formObj.element;
            var customForm = util_1.parentsUntil(element, 'e-virtual-validation');
            if (customForm) {
                formObj = this.virtualFormObj.element;
            }
            var gcontent = this.parent.getContent().firstElementChild;
            var isScroll = gcontent.scrollHeight > gcontent.clientHeight || gcontent.scrollWidth > gcontent.clientWidth;
            var isInline = this.parent.editSettings.mode !== 'Dialog';
            var td = ej2_base_1.closest(element, '.' + literals.rowCell);
            var row = ej2_base_1.closest(element, '.' + literals.row);
            var isFHdr;
            var isFHdrLastRow = false;
            var validationForBottomRowPos;
            var isBatchModeLastRow = false;
            var isAddNewRow = this.parent.editSettings.showAddNewRow && !ej2_base_4.isNullOrUndefined(util_1.parentsUntil(element, literals.addedRow))
                && (this.parent.enableVirtualization || this.parent.enableInfiniteScrolling);
            var viewPortRowCount = Math.round(this.parent.getContent().clientHeight / this.parent.getRowHeight()) - 1;
            var rows = [].slice.call(this.parent.getContent().getElementsByClassName(literals.row));
            if (this.parent.editSettings.mode === 'Batch') {
                rows = [].slice.call(this.parent.getContent().querySelectorAll('.e-row:not(.e-hiddenrow)'));
                if (viewPortRowCount >= 1 && rows.length >= viewPortRowCount
                    && rows[rows.length - 1].getAttribute(literals.dataRowIndex) === row.getAttribute(literals.dataRowIndex)) {
                    isBatchModeLastRow = true;
                }
            }
            if (isInline) {
                if (this.parent.frozenRows || isAddNewRow) {
                    var headerRows = this.parent.editSettings.showAddNewRow ? '.e-row:not(.e-hiddenrow.e-addedrow)' :
                        '.e-row:not(.e-hiddenrow)';
                    var fHearderRows = [].slice.call(this.parent.getHeaderTable().querySelector(literals.tbody).querySelectorAll(headerRows));
                    isFHdr = fHearderRows.length > (parseInt(row.getAttribute(literals.dataRowIndex), 10) || 0);
                    isFHdrLastRow = isFHdr && parseInt(row.getAttribute(literals.dataRowIndex), 10) === fHearderRows.length - 1;
                    var insertRow = [].slice.call(this.parent.getHeaderTable().querySelector(literals.tbody).querySelectorAll('.e-row:not(.e-hiddenrow)'));
                    Iif (insertRow.length === 1 && (insertRow[0].classList.contains('e-addedrow') || insertRow[0].classList.contains('e-insertedrow'))) {
                        isFHdrLastRow = true;
                    }
                }
                if (isFHdrLastRow || (viewPortRowCount >= 1 && rows.length >= viewPortRowCount
                    && ((this.parent.editSettings.newRowPosition === 'Bottom' && (this.editModule.args
                        && this.editModule.args.requestType === 'add')) || (td.classList.contains('e-lastrowcell')
                        && !row.classList.contains(literals.addedRow)))) || isBatchModeLastRow) {
                    validationForBottomRowPos = true;
                }
            }
            var table = isInline ?
                (isFHdr ? this.parent.getHeaderTable() : this.parent.getContentTable()) :
                ej2_base_1.select('#' + this.parent.element.id + '_dialogEdit_wrapper .e-dlg-content', document);
            var client = table.getBoundingClientRect();
            var left = isInline ?
                this.parent.element.getBoundingClientRect().left : client.left;
            var input = ej2_base_1.closest(element, 'td');
            var inputClient = input ? input.getBoundingClientRect() : element.parentElement.getBoundingClientRect();
            var div = this.parent.createElement('div', {
                className: 'e-tooltip-wrap e-lib e-control e-popup e-griderror',
                id: name + '_Error',
                styles: 'display:' + display + ';top:' +
                    ((isFHdr ? inputClient.top + inputClient.height : inputClient.bottom - client.top) + table.scrollTop + 9) + 'px;left:' +
                    (inputClient.left - left + table.scrollLeft + inputClient.width / 2) + 'px;' +
                    'max-width:' + inputClient.width + 'px;text-align:center;'
            });
            Iif (this.parent.cssClass) {
                div.classList.add(this.parent.cssClass);
            }
            if (isInline && client.left < left) {
                div.style.left = parseInt(div.style.left, 10) - client.left + left + 'px';
            }
            var content = this.parent.createElement('div', { className: 'e-tip-content' });
            content.appendChild(error);
            var arrow;
            if (validationForBottomRowPos) {
                arrow = this.parent.createElement('div', { className: 'e-arrow-tip e-tip-bottom' });
                arrow.appendChild(this.parent.createElement('div', { className: 'e-arrow-tip-outer e-tip-bottom' }));
                arrow.appendChild(this.parent.createElement('div', { className: 'e-arrow-tip-inner e-tip-bottom' }));
            }
            else {
                arrow = this.parent.createElement('div', { className: 'e-arrow-tip e-tip-top' });
                arrow.appendChild(this.parent.createElement('div', { className: 'e-arrow-tip-outer e-tip-top' }));
                arrow.appendChild(this.parent.createElement('div', { className: 'e-arrow-tip-inner e-tip-top' }));
            }
            div.appendChild(content);
            div.appendChild(arrow);
            if (!customForm && (this.parent.frozenRows || isAddNewRow) && this.parent.editSettings.mode !== 'Dialog') {
                var getEditCell = this.parent.editSettings.mode === 'Normal' ?
                    ej2_base_1.closest(element, '.e-editcell') : ej2_base_1.closest(element, '.' + literals.table);
                getEditCell.style.position = 'relative';
                div.style.position = 'absolute';
                Eif (this.parent.editSettings.mode === 'Batch' ||
                    (ej2_base_1.closest(element, '.' + literals.frozenContent) || ej2_base_1.closest(element, '.' + literals.frozenHeader))
                    || (this.parent.frozenRows || isAddNewRow)) {
                    Eif (this.parent.isFrozenGrid()) {
                        Iif (td.classList.contains('e-unfreeze')) {
                            ej2_base_1.addClass([div], 'e-unfreeze');
                            formObj.appendChild(div);
                        }
                        else {
                            var elem = ej2_base_1.closest(td, '.e-gridheader') ? this.parent.element.querySelector('.e-gridheader') :
                                rows.length === 1 ? this.parent.element.querySelector('.e-gridcontent').querySelector('.e-content') :
                                    this.parent.element.querySelector('.e-gridcontent');
                            elem.appendChild(div);
                            elem.style.position = 'relative';
                        }
                    }
                    else {
                        formObj.appendChild(div);
                    }
                }
            }
            else {
                if (customForm) {
                    this.virtualFormObj.element.appendChild(div);
                }
                else {
                    if (this.parent.editSettings.mode !== 'Dialog' && this.parent.isFrozenGrid()) {
                        Iif (td.classList.contains('e-unfreeze')) {
                            ej2_base_1.addClass([div], 'e-unfreeze');
                            this.formObj.element.appendChild(div);
                        }
                        else {
                            var elem = ej2_base_1.closest(td, '.e-gridheader') ? this.parent.element.querySelector('.e-gridheader') :
                                rows.length === 1 ? this.parent.element.querySelector('.e-gridcontent').querySelector('.e-content') :
                                    this.parent.element.querySelector('.e-gridcontent');
                            elem.appendChild(div);
                            elem.style.position = 'relative';
                        }
                    }
                    else {
                        this.formObj.element.appendChild(div);
                    }
                }
            }
            Eif (!ej2_base_4.isNullOrUndefined(td)) {
                Iif (td.classList.contains('e-fixedfreeze')) {
                    div.classList.add('e-fixederror');
                }
                else if (td.classList.contains('e-leftfreeze') || td.classList.contains('e-rightfreeze')) {
                    div.classList.add('e-freezeerror');
                }
            }
            if (!validationForBottomRowPos && isInline && gcontent.getBoundingClientRect().bottom < inputClient.bottom + inputClient.height) {
                var contentDiv = this.parent.getContent().querySelector('.e-content');
                Eif (this.parent.currentViewData.length === 0 && contentDiv.scrollTop === 0) {
                    contentDiv.scrollTop = div.offsetHeight + arrow.scrollHeight;
                }
                else {
                    gcontent.scrollTop = gcontent.scrollTop + div.offsetHeight + arrow.scrollHeight;
                }
            }
            var lineHeight = parseInt(document.defaultView.getComputedStyle(div, null).getPropertyValue('font-size'), 10);
            Iif (div.getBoundingClientRect().width < inputClient.width &&
                div.querySelector('label').getBoundingClientRect().height / (lineHeight * 1.2) >= 2) {
                div.style.width = div.style.maxWidth;
            }
            if ((this.parent.frozenRows || isAddNewRow) && this.parent.editSettings.mode !== 'Dialog') {
                div.style.left = input.offsetLeft + (input.offsetWidth / 2 - div.offsetWidth / 2) + 'px';
            }
            else {
                div.style.left = (parseInt(div.style.left, 10) - div.offsetWidth / 2) + 'px';
            }
            if (isInline && !isScroll && !this.parent.allowPaging || (this.parent.frozenRows || isAddNewRow)) {
                var pos = ej2_popups_2.calculateRelativeBasedPosition(input, div);
                div.style.top = pos.top + inputClient.height + 9 + 'px';
            }
            if (validationForBottomRowPos) {
                if (isScroll && this.parent.height !== 'auto' && (!this.parent.frozenRows || !isAddNewRow)
                    && !this.parent.enableVirtualization && !this.parent.enableInfiniteScrolling && !(div.classList.contains('e-freezeerror')
                    && div.classList.contains('e-fixederror'))) {
                    var scrollWidth = gcontent.scrollWidth > gcontent.offsetWidth ? util_1.getScrollBarWidth() : 0;
                    var gHeight = this.parent.height.toString().indexOf('%') === -1 ?
                        parseInt(this.parent.height, 10) : gcontent.offsetHeight;
                    div.style.bottom = (gHeight - gcontent.querySelector('table').offsetHeight
                        - scrollWidth) + inputClient.height + 9 + 'px';
                }
                else {
                    div.style.bottom = inputClient.height + 9 + 'px';
                }
                Iif (rows.length < viewPortRowCount && this.parent.editSettings.newRowPosition === 'Bottom' && (this.editModule.args
                    && this.editModule.args.requestType === 'add')) {
                    var rowsCount = this.parent.frozenRows ? (isAddNewRow ? this.parent.frozenRows + 1 : this.parent.frozenRows) +
                        (rows.length - 1) : rows.length - 1;
                    var rowsHeight = rowsCount * this.parent.getRowHeight();
                    var position = this.parent.getContent().clientHeight - rowsHeight;
                    div.style.bottom = position + 9 + 'px';
                }
                div.style.top = null;
            }
        };
        Edit.prototype.checkColumnIsGrouped = function (col) {
            return !col.visible && !(this.parent.groupSettings.columns.indexOf(col.field) > -1);
        };
        Edit.AddEditors = function (editors) {
            Edit.editCellType = ej2_base_2.extend(Edit.editCellType, editors);
        };
        Edit.editCellType = {
            'dropdownedit': dropdown_edit_cell_1.DropDownEditCell, 'numericedit': numeric_edit_cell_1.NumericEditCell,
            'datepickeredit': datepicker_edit_cell_1.DatePickerEditCell, 'datetimepickeredit': datepicker_edit_cell_1.DatePickerEditCell,
            'booleanedit': boolean_edit_cell_1.BooleanEditCell, 'defaultedit': default_edit_cell_1.DefaultEditCell,
            'templateedit': template_edit_cell_1.TemplateEditCell
        };
        return Edit;
    }());
    exports.Edit = Edit;
});