all files / grid/actions/ normal-edit.js

91.89% Statements 419/456
86.96% Branches 320/368
86.96% Functions 40/46
92.7% Lines 419/452
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   182× 182× 182× 182× 182× 182×   54× 54× 54× 12×   42×       16×   16×       17×     14×     61× 61× 61×   35×     35×   35×       35×   26×       26× 21×   26×     146× 146× 146× 136×   146×         146×   108× 108× 108× 108× 26× 26× 26×       108× 108× 108×   107×   25×   82× 82×       108× 108× 108× 108× 108× 108× 107× 107× 107× 107× 107× 106×               13× 13× 13× 12×           13× 13× 48× 48× 48× 48× 48×   48× 48× 31×     30× 30×     48×   47× 45×                                           107× 107× 107× 107× 87×   107× 19× 19×   107× 107× 107× 107×   107× 107× 107×   107× 107×                               107× 107× 107×     107× 107×   127× 127× 127× 36×   91× 91×       91× 91× 91×   91×     91× 91×   21× 21×       70×   91× 91×   91× 62× 62× 62×   61× 60×   61×   61×   61×       29× 29× 29× 29× 29× 29× 29×   28×           89× 89× 87× 87×   89×   64× 64×     63×   64×             63× 49×     102× 88× 88× 88×         63× 63× 63×   63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63×   11× 11×                         61×   63× 63×   60× 54×     63×       62× 62×         90× 90×   90× 555× 555×   555×                   73× 73× 73×     73×   81× 81× 81× 73× 73× 73× 73× 71×   73× 73× 72× 72×                                             32× 32×       27× 27×     27× 27× 27× 27×   26×   26× 26× 26×   26× 18×   26× 26× 26×         26×   26×     26× 18×   26×     86× 86× 86× 86× 11×     11×   75×   74× 74× 74× 74× 74× 59×   74× 454× 11×   443× 436× 149×     436×     74×         74×     74× 72× 72× 15×     57× 57×   56×             73× 73× 73× 67×   72× 72× 72× 72× 72× 58×   72×   72×   30× 30× 14× 14× 14× 38× 38×   14×     14×     30×       30×     30×   115× 115×   115× 115× 30×   115× 54×     183×   182×                 182×   368× 192×   176×   368× 368×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/util", "../base/constant", "../renderer/row-renderer", "@syncfusion/ej2-data", "../base/util", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, util_1, events, row_renderer_1, ej2_data_1, util_2, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var NormalEdit = (function () {
        function NormalEdit(parent, serviceLocator, renderer) {
            this.args = {};
            this.currentVirtualData = {};
            this.parent = parent;
            this.renderer = renderer;
            this.serviceLocator = serviceLocator;
            this.addEventListener();
        }
        NormalEdit.prototype.clickHandler = function (e) {
            var target = e.target;
            var gObj = this.parent;
            if (gObj.editSettings.showAddNewRow && ej2_base_2.isNullOrUndefined(gObj.element.querySelector('.' + literals.editedRow))) {
                return;
            }
            if ((((util_1.parentsUntil(target, literals.gridContent) &&
                util_1.parentsUntil(util_1.parentsUntil(target, literals.gridContent), 'e-grid').id === gObj.element.id)) || (gObj.frozenRows
                && util_1.parentsUntil(target, literals.headerContent) && !util_1.parentsUntil(target, 'e-columnheader')))
                && !util_1.parentsUntil(target, 'e-unboundcelldiv')) {
                this.rowIndex = util_1.parentsUntil(target, literals.rowCell)
                    ? parseInt(target.parentElement.getAttribute(literals.dataRowIndex), 10) : -1;
                if (gObj.isEdit) {
                    gObj.editModule.endEdit();
                }
            }
        };
        NormalEdit.prototype.dblClickHandler = function (e) {
            if (util_1.parentsUntil(e.target, literals.rowCell) && this.parent.editSettings.allowEditOnDblClick &&
                (!this.parent.editSettings.showAddNewRow || (this.parent.editSettings.showAddNewRow &&
                    !util_1.parentsUntil(e.target, 'e-addedrow')))) {
                this.parent.editModule.startEdit(util_1.parentsUntil(e.target, literals.row));
            }
        };
        NormalEdit.prototype.editComplete = function (e) {
            this.parent.isEdit = this.parent.editSettings.showAddNewRow ? true : false;
            var action = 'action';
            switch (e.requestType) {
                case 'save':
                    Eif ((!(this.parent.isCheckBoxSelection || this.parent.selectionSettings.type === 'Multiple')
                        || (!this.parent.isPersistSelection)) && (e["" + action] !== 'edit' && (!this.parent.editSettings.showAddNewRow ||
                        (this.parent.editSettings.showAddNewRow && e["" + action] !== 'add')))) {
                        this.parent.selectRow(e['index']);
                    }
                    this.parent.trigger(events.actionComplete, ej2_base_1.extend(e, {
                        requestType: 'save',
                        type: events.actionComplete
                    }));
                    break;
                case 'delete':
                    this.parent.trigger(events.actionComplete, ej2_base_1.extend(e, {
                        requestType: 'delete',
                        type: events.actionComplete
                    }));
                    if (!this.parent.isCheckBoxSelection) {
                        this.parent.selectRow(this.editRowIndex);
                    }
                    break;
            }
        };
        NormalEdit.prototype.getEditArgs = function (editedData, rowObj, isScroll) {
            var primaryKeys = this.parent.getPrimaryKeyFieldNames();
            var primaryKeyValues = [];
            for (var i = 0; i < primaryKeys.length; i++) {
                primaryKeyValues.push(util_1.getObject(primaryKeys[parseInt(i.toString(), 10)], editedData));
            }
            var args = {
                primaryKey: primaryKeys, primaryKeyValue: primaryKeyValues, requestType: 'beginEdit',
                rowData: editedData, rowIndex: this.rowIndex, type: 'edit', cancel: false,
                foreignKeyData: rowObj && rowObj.foreignKeyData, target: undefined, isScroll: isScroll
            };
            return args;
        };
        NormalEdit.prototype.startEdit = function (tr) {
            var _this = this;
            var gObj = this.parent;
            this.rowIndex = this.editRowIndex = parseInt(tr.getAttribute(literals.dataRowIndex), 10);
            if (gObj.enableVirtualization || gObj.enableColumnVirtualization || gObj.enableInfiniteScrolling) {
                var selector = '.e-row[data-rowindex="' + this.rowIndex + '"]';
                var virtualRow = this.parent.element.querySelector(selector);
                Iif (!virtualRow) {
                    return;
                }
            }
            var e = { data: undefined, index: this.rowIndex, isScroll: false };
            this.parent.notify(events.virtualScrollEditActionBegin, e);
            if (util_1.isGroupAdaptive(gObj)) {
                var rObj = gObj.getRowObjectFromUID(tr.getAttribute('data-uid'));
                this.previousData = rObj.data;
            }
            else if (this.parent.enableVirtualization || this.parent.enableColumnVirtualization ||
                (this.parent.enableInfiniteScrolling && !this.previousData)) {
                this.previousData = e.data;
            }
            else Eif (!this.parent.enableVirtualization) {
                this.previousData = ej2_base_1.extend({}, {}, this.parent.getForeignKeyColumns().length ?
                    this.parent.getRowObjectFromUID(tr.getAttribute('data-uid')).data :
                    gObj.getCurrentViewRecords()[this.rowIndex], true);
            }
            var editedData = ej2_base_1.extend({}, {}, e.data || this.previousData, true);
            this.uid = tr.getAttribute('data-uid');
            var rowObj = gObj.getRowObjectFromUID(this.uid);
            var args = this.getEditArgs(editedData, rowObj, e.isScroll);
            args.row = tr;
            if (!args.isScroll) {
                this.parent.notify(events.createVirtualValidationForm, { uid: this.uid, prevData: this.previousData, argsCreator: this.getEditArgs.bind(this), renderer: this.renderer });
                gObj.trigger(events.beginEdit, args, function (begineditargs) {
                    begineditargs.type = 'actionBegin';
                    gObj.trigger(events.actionBegin, begineditargs, function (editargs) {
                        if (!editargs.cancel) {
                            _this.inlineEditHandler(editargs, tr);
                        }
                    });
                });
            }
            else {
                this.inlineEditHandler(args, tr);
            }
        };
        NormalEdit.prototype.disabledShowAddRow = function (disable, prevent) {
            var addRow = this.parent.element.querySelector('.e-addedrow');
            var inputs = [].slice.call(addRow ? addRow.querySelectorAll('.e-input') : []);
            if (addRow && addRow.querySelector('.e-unboundcell')) {
                var buttons = [].slice.call(addRow.querySelector('.e-unboundcell').querySelectorAll('.e-btn'));
                for (var i = 0; i < buttons.length; i++) {
                    if (!disable) {
                        buttons[parseInt(i.toString(), 10)].classList.add('e-disabled');
                        buttons[parseInt(i.toString(), 10)].setAttribute('disabled', 'disabled');
                    }
                    else {
                        buttons[parseInt(i.toString(), 10)].classList.remove('e-disabled');
                        buttons[parseInt(i.toString(), 10)].removeAttribute('disabled');
                    }
                }
            }
            Eif (inputs.length) {
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[parseInt(i.toString(), 10)];
                    var uid = input.getAttribute('e-mappinguid');
                    var column = this.parent.getColumnByUid(uid);
                    var error = util_1.parentsUntil(input, 'e-rowcell').querySelector('.e-error');
                    if (error) {
                        error.classList.remove('e-error');
                    }
                    Eif (input.ej2_instances) {
                        if (prevent && ej2_base_2.isNullOrUndefined(column.defaultValue)) {
                            if (input.type === 'checkbox') {
                                input.ej2_instances[0].checked = false;
                                input.checked = false;
                            }
                            else {
                                input.ej2_instances[0].value = null;
                                input.value = null;
                            }
                        }
                        if (input.type === 'checkbox' && !ej2_base_2.isNullOrUndefined(disable)) {
                            input.ej2_instances[0].disabled = disable && column.allowEditing ? false : true;
                        }
                        else if (!ej2_base_2.isNullOrUndefined(disable)) {
                            input.ej2_instances[0].enabled = disable && column.allowEditing ? true : false;
                        }
                    }
                    else {
                        if (prevent && input.value && input.value.length &&
                            ej2_base_2.isNullOrUndefined(column.defaultValue)) {
                            input.value = null;
                        }
                        if (!ej2_base_2.isNullOrUndefined(disable)) {
                            if (!disable) {
                                input.classList.add('e-disabled');
                                input.setAttribute('disabled', 'disabled');
                            }
                            else if (column.allowEditing) {
                                input.classList.remove('e-disabled');
                                input.removeAttribute('disabled');
                            }
                        }
                    }
                }
            }
        };
        NormalEdit.prototype.inlineEditHandler = function (editargs, tr) {
            var gObj = this.parent;
            gObj.isEdit = true;
            editargs.row = editargs.row ? editargs.row : tr;
            if (gObj.editSettings.mode !== 'Dialog') {
                gObj.clearSelection();
            }
            if (gObj.editSettings.mode === 'Dialog' && gObj.selectionModule) {
                gObj.selectionModule.preventFocus = true;
                editargs.row.classList.add('e-dlgeditrow');
            }
            this.renderer.update(editargs);
            this.uid = tr.getAttribute('data-uid');
            gObj.editModule.applyFormValidation();
            if (gObj.editSettings.showAddNewRow && !tr.classList.contains('e-addedrow')) {
                this.disabledShowAddRow(false, true);
            }
            editargs.type = 'actionComplete';
            gObj.trigger(events.actionComplete, editargs);
            if (gObj.editSettings.template) {
                gObj.editModule.applyFormValidation(undefined, editargs.form.ej2_instances[0].rules);
            }
            this.args = editargs;
            Iif (this.parent.allowTextWrap) {
                this.parent.notify(events.freezeRender, { case: 'textwrap' });
            }
        };
        NormalEdit.prototype.updateRow = function (index, data) {
            var _this = this;
            var gObj = this.parent;
            this.editRowIndex = index;
            var row = gObj.getRowByIndex(index);
            if (!row) {
                return;
            }
            var args = {
                requestType: 'save', action: 'edit', type: events.actionBegin, data: data, cancel: false,
                previousData: gObj.getCurrentViewRecords()[parseInt(index.toString(), 10)],
                row: row
            };
            gObj.showSpinner();
            if (gObj.enableInfiniteScrolling) {
                this.uid = args.row.getAttribute('data-uid');
                var index_1 = parseInt(args.row.getAttribute('data-rowindex'), 10);
                this.parent.notify(events.refreshInfiniteEditrowindex, { index: index_1 });
            }
            gObj.notify(events.updateData, args);
            Iif (args.promise) {
                args.promise.then(function () { return gObj.refresh(); }).catch(function (e) { return _this.edFail(e); });
            }
            else {
                if (!gObj.enableInfiniteScrolling) {
                    gObj.refresh();
                }
            }
        };
        NormalEdit.prototype.editFormValidate = function () {
            var gObj = this.parent;
            var isValid = gObj.editModule.editFormValidate();
            var validationArgs = {
                prevData: this.previousData, isValid: true, editIdx: this.editRowIndex, addIdx: this.addedRowIndex
            };
            gObj.notify(events.validateVirtualForm, validationArgs);
            return (isValid && validationArgs.isValid);
        };
        NormalEdit.prototype.endEdit = function () {
            var _this = this;
            var gObj = this.parent;
            if (!this.parent.isEdit || !this.editFormValidate()) {
                return;
            }
            var editedData = ej2_base_1.extend({}, {}, this.previousData, true);
            var args = ej2_base_1.extend(this.args, {
                requestType: 'save', type: events.actionBegin, data: editedData, cancel: false,
                previousData: this.previousData, selectedRow: gObj.selectedRowIndex, foreignKeyData: {}
            });
            var isDlg = gObj.editSettings.mode === 'Dialog';
            var dlgWrapper = ej2_base_1.select('#' + gObj.element.id + '_dialogEdit_wrapper', document);
            var dlgForm = isDlg ? dlgWrapper.querySelector('.e-gridform') : gObj.editSettings.showAddNewRow &&
                gObj.element.querySelector('.' + literals.editedRow) ? gObj.element.querySelector('.' + literals.editedRow).getElementsByClassName('e-gridform')[0] : gObj.element.getElementsByClassName('e-gridform')[0];
            var data = {
                virtualData: ej2_base_1.extend({}, {}, this.previousData, true), isAdd: false, isScroll: false, endEdit: true
            };
            this.parent.notify(events.getVirtualData, data);
            if ((this.parent.enableVirtualization || this.parent.enableColumnVirtualization || this.parent.enableInfiniteScrolling)
                && this.parent.editSettings.mode === 'Normal' && Object.keys(data.virtualData).length) {
                Eif (this.parent.isEdit) {
                    this.currentVirtualData = editedData = args.data = data.virtualData;
                }
            }
            else {
                editedData = gObj.editModule.getCurrentEditedData(dlgForm, editedData);
            }
            var eleLength = [].slice.call(gObj.element.getElementsByClassName(literals.editedRow)).length;
            if (!data.isAdd && Object.keys(this.currentVirtualData).length && !eleLength) {
                eleLength = 1;
            }
            if (isDlg ? dlgWrapper.getElementsByClassName(literals.editedRow).length : eleLength) {
                args.action = 'edit';
                gObj.trigger(events.actionBegin, args, function (endEditArgs) {
                    if (endEditArgs.cancel) {
                        return;
                    }
                    if (_this.parent.loadingIndicator.indicatorType === 'Spinner') {
                        gObj.showSpinner();
                    }
                    if (_this.parent.loadingIndicator.indicatorType === 'Shimmer') {
                        _this.parent.showMaskRow();
                    }
                    if (gObj.editSettings.showAddNewRow) {
                        _this.disabledShowAddRow(true);
                    }
                    gObj.notify(events.updateData, endEditArgs);
                });
            }
            else {
                args.action = 'add';
                args.selectedRow = 0;
                args.index = this.addedRowIndex;
                gObj.notify(events.virtualScrollEditSuccess, {});
                gObj.notify(events.modelChanged, args);
                this.addedRowIndex = null;
                if (args.cancel) {
                    return;
                }
                if (this.parent.editSettings.showAddNewRow) {
                    this.parent.notify(events.showAddNewRowFocus, {});
                    Iif (this.parent.enableVirtualization || this.parent.enableInfiniteScrolling) {
                        this.disabledShowAddRow(true, true);
                    }
                }
            }
        };
        NormalEdit.prototype.destroyElements = function () {
            var gObj = this.parent;
            if (!gObj.editSettings.showAddNewRow || (gObj.editSettings.showAddNewRow && gObj.element.querySelector('.e-editedrow'))) {
                gObj.editModule.destroyWidgets();
                gObj.editModule.destroyForm();
            }
            this.parent.notify(events.dialogDestroy, {});
        };
        NormalEdit.prototype.editHandler = function (args) {
            var _this = this;
            if (args.promise) {
                args.promise.then(function (e) { return _this.edSucc(e, args); }).catch(function (e) { return _this.edFail(e); });
            }
            else {
                this.editSuccess(args.data, args);
            }
            if (this.parent.editSettings.showAddNewRow) {
                this.parent.editModule.applyFormValidation();
            }
        };
        NormalEdit.prototype.edSucc = function (e, args) {
            this.editSuccess(e, args);
        };
        NormalEdit.prototype.edFail = function (e) {
            this.editFailure(e);
        };
        NormalEdit.prototype.updateCurrentViewData = function (data) {
            if (!this.parent.enableVirtualization && !this.parent.enableInfiniteScrolling) {
                this.parent.getCurrentViewRecords()[this.editRowIndex] = data;
            }
        };
        NormalEdit.prototype.requestSuccess = function (args) {
            if (this.parent.editModule.formObj && !this.parent.editModule.formObj.isDestroyed) {
                this.destroyElements();
                this.stopEditStatus();
                if (this.parent.editSettings.mode === 'Dialog' && args.action !== 'add' &&
                    this.parent.selectionModule) {
                    this.parent.element.querySelector('.e-dlgeditrow').classList.remove('e-dlgeditrow');
                }
            }
        };
        NormalEdit.prototype.editSuccess = function (e, args) {
            Eif (!ej2_base_2.isNullOrUndefined(e) && !(e instanceof Array)) {
                var rowData = 'rowData';
                args.data = ej2_base_1.extend({}, ej2_base_1.extend({}, args["" + rowData], args.data), e);
            }
            this.requestSuccess(args);
            this.parent.trigger(events.beforeDataBound, args);
            args.type = events.actionComplete;
            this.parent.isEdit = this.parent.editSettings.showAddNewRow ? true : false;
            this.refreshRow(args.data);
            this.parent.notify(events.virtualScrollEditSuccess, args);
            this.parent.editModule.checkLastRow(args.row);
            this.parent.editModule.isLastRow = false;
            this.updateCurrentViewData(args.data);
            this.blazorTemplate();
            this.editRowIndex = null;
            if (this.parent.allowGrouping && this.parent.groupSettings.columns.length
                && this.parent.groupSettings.showGroupedColumn) {
                var dragRow = args.row;
                var rows = this.parent.getRowsObject();
                var dragRowUid = dragRow.getAttribute('data-uid');
                var dragRowObject_1 = this.parent.getRowObjectFromUID(dragRowUid);
                var _loop_1 = function (i) {
                    var thisRef = this_1;
                    rows = rows.filter(function (data) {
                        var flag = data.isDataRow && data !== dragRowObject_1;
                        if (flag) {
                            var groupedColumn = thisRef.parent.groupSettings.columns[parseInt(i.toString(), 10)].split('.');
                            var comparer1 = data.data[groupedColumn[0]];
                            var comparer2 = args.data[groupedColumn[0]];
                            for (var j = 1; j < groupedColumn.length; j++) {
                                comparer1 = comparer1[groupedColumn[j]];
                                comparer2 = comparer2[groupedColumn[j]];
                            }
                            return flag && comparer1 === comparer2;
                        }
                        else {
                            return flag;
                        }
                    });
                };
                var this_1 = this;
                for (var i = 0; i < this.parent.groupSettings.columns.length; i++) {
                    _loop_1(i);
                }
                var dropRowObject = rows[0];
                if (!ej2_base_2.isNullOrUndefined(dragRowObject_1) && !ej2_base_2.isNullOrUndefined(dropRowObject) &&
                    dragRowObject_1.parentUid !== dropRowObject.parentUid) {
                    this.parent['groupModule'].groupedRowReorder(dragRowObject_1, dropRowObject);
                }
                else Iif (this.parent.aggregates.length) {
                    this.parent.aggregateModule.refresh(args.data, this.parent.groupSettings.enableLazyLoading ? args.row : undefined);
                }
            }
            else if (this.parent.aggregates.length) {
                this.parent.aggregateModule.refresh(args.data, this.parent.groupSettings.enableLazyLoading ? args.row : undefined);
            }
            this.parent.trigger(events.actionComplete, args);
            if (!(this.parent.isCheckBoxSelection || this.parent.selectionSettings.type === 'Multiple')
                || (!this.parent.isPersistSelection) && !this.parent.selectionSettings.checkboxOnly) {
                if (this.parent.editSettings.mode !== 'Dialog') {
                    this.parent.selectRow(this.rowIndex > -1 ? this.rowIndex : this.editRowIndex);
                }
            }
            if (this.parent.aggregates.length && this.parent.groupSettings.enableLazyLoading && this.parent.groupSettings.columns.length
                && (this.parent.groupModule.getGroupAggregateTemplates(true).length
                    || this.parent.groupModule.getGroupAggregateTemplates(false).length)) {
                return;
            }
            this.parent.removeMaskRow();
            this.parent.hideSpinner();
        };
        NormalEdit.prototype.closeForm = function () {
            if (!this.cloneRow && this.parent.isEdit) {
                this.stopEditStatus();
            }
            if (this.cloneRow) {
                this.cloneRow.remove();
                this.cloneRow = null;
                this.originalRow.classList.remove('e-hiddenrow');
            }
        };
        NormalEdit.prototype.blazorTemplate = function () {
            var cols = this.parent.getColumns();
            if (this.parent.editSettings.template && this.parent.editSettings.mode === 'Normal') {
                ej2_base_2.updateBlazorTemplate(this.parent.element.id + 'editSettingsTemplate', 'Template', this.parent.editSettings);
            }
            for (var i = 0; i < cols.length; i++) {
                var col = cols[parseInt(i.toString(), 10)];
                if (col.template) {
                    ej2_base_2.updateBlazorTemplate(this.parent.element.id + col.uid, 'Template', col, false);
                }
                if (col.editTemplate) {
                    ej2_base_2.updateBlazorTemplate(this.parent.element.id + col.uid + 'editTemplate', 'EditTemplate', col);
                }
            }
        };
        NormalEdit.prototype.editFailure = function (e) {
            Eif (e.cancel) {
                return;
            }
            this.parent.removeMaskRow();
            this.parent.trigger(events.actionFailure, ({ error: e }));
            this.parent.hideSpinner();
            this.parent.log('actionfailure', { error: e });
        };
        NormalEdit.prototype.needRefresh = function () {
            var refresh = true;
            var editedRow = this.parent.element.querySelector('.e-gridform');
            if ((this.parent.enableVirtualization || this.parent.infiniteScrollSettings.enableCache)
                && this.parent.editSettings.mode === 'Normal' && !editedRow) {
                refresh = false;
            }
            return refresh;
        };
        NormalEdit.prototype.refreshRow = function (data) {
            var row = new row_renderer_1.RowRenderer(this.serviceLocator, null, this.parent);
            var rowObj = this.parent.getRowObjectFromUID(this.uid);
            if (rowObj) {
                rowObj.changes = data;
                this.parent.notify(events.refreshVirtualCache, { data: data });
                util_1.refreshForeignData(rowObj, this.parent.getForeignKeyColumns(), rowObj.changes);
                if (this.needRefresh()) {
                    row.refresh(rowObj, this.parent.getColumns(), true);
                }
                var tr = [].slice.call(this.parent.element.querySelectorAll('[data-rowindex="' + rowObj.index + '"]'));
                for (var i = 0; i < tr.length; i++) {
                    util_2.addFixedColumnBorder(tr[parseInt(i.toString(), 10)]);
                    Iif (this.parent.enableColumnVirtualization &&
                        tr[parseInt(i.toString(), 10)].querySelectorAll('.e-leftfreeze,.e-rightfreeze,.e-fixedfreeze').length) {
                        var cols = this.parent.getColumns();
                        var leftrightCells = [].slice.call(tr[parseInt(i.toString(), 10)].querySelectorAll('.e-leftfreeze,.e-rightfreeze.e-fixedfreeze'));
                        for (var j = 0; j < leftrightCells.length; j++) {
                            if (leftrightCells[parseInt(j.toString(), 10)].classList.contains('e-leftfreeze')) {
                                leftrightCells[parseInt(j.toString(), 10)].style.left = (cols[parseInt(j.toString(), 10)].valueX - this.parent.translateX) + 'px';
                            }
                            else if (leftrightCells[parseInt(j.toString(), 10)].classList.contains('e-rightfreeze')) {
                                var idx = parseInt(leftrightCells[parseInt(j.toString(), 10)].getAttribute('data-colindex'), 10);
                                leftrightCells[parseInt(j.toString(), 10)].style.right = ((cols[parseInt(idx.toString(), 10)].valueX + this.parent.translateX)) + 'px';
                            }
                            else {
                                leftrightCells[parseInt(j.toString(), 10)].style.left = (this.parent.leftrightColumnWidth('left') -
                                    this.parent.translateX) + 'px';
                                leftrightCells[parseInt(j.toString(), 10)].style.right = (this.parent.leftrightColumnWidth('right') +
                                    this.parent.translateX) + 'px';
                            }
                        }
                    }
                }
            }
        };
        NormalEdit.prototype.closeEdit = function () {
            var _this = this;
            if (!this.parent.isEdit || (this.parent.editSettings.showAddNewRow && this.parent.element.querySelector('.e-addedrow') &&
                ej2_base_2.isNullOrUndefined(this.parent.element.querySelector('.' + literals.editedRow)))) {
                if (this.parent.editSettings.showAddNewRow) {
                    this.disabledShowAddRow(true, true);
                    this.parent.notify(events.showAddNewRowFocus, {});
                }
                return;
            }
            var gObj = this.parent;
            var args = ej2_base_1.extend(this.args, {
                requestType: 'cancel', type: events.actionBegin, cancel: false, data: this.previousData, selectedRow: gObj.selectedRowIndex
            });
            gObj.notify(events.virtualScrollEditCancel, args);
            this.blazorTemplate();
            gObj.trigger(events.actionBegin, args, function (closeEditArgs) {
                if (closeEditArgs.cancel) {
                    return;
                }
                if (_this.parent.editSettings.mode === 'Dialog') {
                    _this.parent.notify(events.dialogDestroy, {});
                }
                closeEditArgs.type = events.actionComplete;
                Eif (!_this.parent.editSettings.showAddNewRow) {
                    gObj.isEdit = false;
                }
                if (gObj.editSettings.mode !== 'Dialog') {
                    _this.refreshRow(closeEditArgs.data);
                }
                _this.stopEditStatus();
                gObj.isEdit = false;
                Iif (gObj.editSettings.showAddNewRow) {
                    _this.disabledShowAddRow(true);
                    gObj.editModule.applyFormValidation();
                    gObj.isEdit = true;
                }
                var isLazyLoad = gObj.groupSettings.enableLazyLoading && gObj.groupSettings.columns.length
                    && !gObj.getContentTable().querySelector('tr.e-emptyrow');
                if (!gObj.getContentTable().querySelector('tr.e-emptyrow') &&
                    !gObj.getContentTable().querySelector('tr.e-row') && !isLazyLoad) {
                    gObj.renderModule.emptyRow();
                }
                if (gObj.editSettings.mode !== 'Dialog') {
                    gObj.selectRow(_this.rowIndex);
                }
                gObj.trigger(events.actionComplete, closeEditArgs);
            });
        };
        NormalEdit.prototype.addRecord = function (data, index) {
            var _this = this;
            var gObj = this.parent;
            this.addedRowIndex = index = !ej2_base_2.isNullOrUndefined(index) ? index : 0;
            if (data) {
                gObj.notify(events.modelChanged, {
                    requestType: 'save', type: events.actionBegin, data: data, selectedRow: 0, action: 'add', index: index
                });
                return;
            }
            if (gObj.isEdit) {
                return;
            }
            this.previousData = {};
            this.uid = '';
            var cols = gObj.getColumns();
            var rowData = { virtualData: {}, isScroll: false };
            if (!gObj.editSettings.showAddNewRow) {
                this.parent.notify(events.getVirtualData, rowData);
            }
            for (var i = 0; i < cols.length; i++) {
                if (rowData.isScroll) {
                    continue;
                }
                if (cols[parseInt(i.toString(), 10)].field) {
                    if (cols[parseInt(i.toString(), 10)].type === 'string') {
                        cols[parseInt(i.toString(), 10)].defaultValue = this.parent
                            .sanitize(cols[parseInt(i.toString(), 10)].defaultValue);
                    }
                    ej2_data_1.DataUtil.setValue(cols[parseInt(i.toString(), 10)].field, cols[parseInt(i.toString(), 10)].defaultValue, this.previousData);
                }
            }
            var args = {
                cancel: false, foreignKeyData: {},
                requestType: 'add', data: this.previousData, type: events.actionBegin, index: index,
                rowData: this.previousData, target: undefined, isScroll: rowData.isScroll
            };
            if ((this.parent.enableVirtualization || this.parent.enableColumnVirtualization || this.parent.infiniteScrollSettings.enableCache)
                && Object.keys(rowData.virtualData).length) {
                args.data = args.rowData = rowData.virtualData;
            }
            if (!args.isScroll) {
                this.parent.notify(events.createVirtualValidationForm, { uid: this.uid, prevData: this.previousData, argsCreator: this.getEditArgs.bind(this), renderer: this.renderer });
                if (gObj.editSettings.showAddNewRow) {
                    this.inlineAddHandler(args);
                }
                else {
                    gObj.trigger(events.actionBegin, args, function (addArgs) {
                        if (addArgs.cancel) {
                            return;
                        }
                        _this.inlineAddHandler(addArgs);
                    });
                }
            }
            else {
                this.inlineAddHandler(args);
            }
        };
        NormalEdit.prototype.inlineAddHandler = function (addArgs) {
            var gObj = this.parent;
            gObj.isEdit = true;
            if (gObj.editSettings.mode !== 'Dialog') {
                gObj.clearSelection();
            }
            this.renderer.addNew(addArgs);
            gObj.editModule.applyFormValidation();
            addArgs.type = events.actionComplete;
            addArgs.row = gObj.element.querySelector('.' + literals.addedRow);
            if (!gObj.editSettings.showAddNewRow) {
                gObj.trigger(events.actionComplete, addArgs);
            }
            if (gObj.editSettings.template) {
                gObj.editModule.applyFormValidation(undefined, addArgs.form.ej2_instances[0].rules);
            }
            this.args = addArgs;
        };
        NormalEdit.prototype.deleteRecord = function (fieldname, data) {
            this.editRowIndex = this.parent.selectedRowIndex;
            if (data) {
                data = (data instanceof Array) ? data : [data];
                var gObj = this.parent;
                var dataLen = Object.keys(data).length;
                fieldname = fieldname || this.parent.getPrimaryKeyFieldNames()[0];
                var _loop_2 = function (i) {
                    var _a;
                    var tmpRecord;
                    var contained = gObj.currentViewData.some(function (record) {
                        tmpRecord = record;
                        return data[parseInt(i.toString(), 10)] === util_1.getObject(fieldname, record) || data[parseInt(i.toString(), 10)] === record;
                    });
                    data[parseInt(i.toString(), 10)] = contained ? tmpRecord : data[parseInt(i.toString(), 10)]["" + fieldname] ?
                        data[parseInt(i.toString(), 10)] : (_a = {}, _a[fieldname] = data[parseInt(i.toString(), 10)], _a);
                };
                for (var i = 0; i < dataLen; i++) {
                    _loop_2(i);
                }
            }
            var args = {
                requestType: 'delete', type: events.actionBegin, foreignKeyData: {},
                data: data ? data : this.parent.getSelectedRecords(), tr: this.parent.getSelectedRows(), cancel: false
            };
            if (!ej2_base_2.isNullOrUndefined(this.parent.commandDelIndex)) {
                args.data[0] =
                    this.parent.getRowObjectFromUID(this.parent.getRowByIndex(this.parent.commandDelIndex).getAttribute('data-uid')).data;
            }
            this.parent.notify(events.modelChanged, args);
        };
        NormalEdit.prototype.stopEditStatus = function () {
            var gObj = this.parent;
            var addElements = [].slice.call(gObj.editSettings.showAddNewRow ? [] :
                gObj.element.getElementsByClassName(literals.addedRow));
            var editElements = [].slice.call(gObj.element.getElementsByClassName(literals.editedRow));
            for (var i = 0; i < addElements.length; i++) {
                ej2_base_2.remove(addElements[parseInt(i.toString(), 10)]);
            }
            for (var i = 0; i < editElements.length; i++) {
                editElements[parseInt(i.toString(), 10)].classList.remove(literals.editedRow);
            }
        };
        NormalEdit.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.evtHandlers = [{ event: events.crudAction, handler: this.editHandler },
                { event: events.doubleTap, handler: this.dblClickHandler },
                { event: events.click, handler: this.clickHandler },
                { event: events.recordAdded, handler: this.requestSuccess },
                { event: events.dblclick, handler: this.dblClickHandler },
                { event: events.deleteComplete, handler: this.editComplete },
                { event: events.saveComplete, handler: this.editComplete },
                { event: events.rowModeChange, handler: this.closeEdit },
                { event: events.closeInline, handler: this.closeForm }];
            util_2.addRemoveEventListener(this.parent, this.evtHandlers, true, this);
        };
        NormalEdit.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            util_2.addRemoveEventListener(this.parent, this.evtHandlers, false);
        };
        NormalEdit.prototype.destroy = function () {
            this.removeEventListener();
            this.renderer.destroy();
        };
        return NormalEdit;
    }());
    exports.NormalEdit = NormalEdit;
});