all files / treegrid/actions/ batch-edit.js

96.09% Statements 418/435
87.36% Branches 235/269
97.06% Functions 33/34
96.24% Lines 409/425
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   229× 229× 229× 229× 229× 229× 229× 229× 229× 229× 229× 229×   229× 229× 229× 229× 229× 229× 229× 229× 229× 229×         16×   50×   50×   12×                 81× 81× 32×       81× 48×   48× 48× 48× 48× 48× 48× 48× 48× 48× 48× 48× 48×     48× 48× 45× 45× 45× 45× 23×     45× 45× 45× 45× 45× 45× 45× 45× 45× 11× 11× 11× 11× 11× 11× 11× 11× 11× 11× 11× 334× 11×   11×     34×   25× 25× 14× 14× 14× 14×   25× 25× 18× 18× 18× 589×   25×   25×     45× 45× 45× 45× 45× 45× 31×     14×   45× 41×   45× 45×   45× 45×       53× 53×         53×         46× 46× 46× 46×     53× 53× 53× 53× 53× 34× 34× 34×   53×   53× 43× 43×   16×   43× 43× 43×   53× 53× 53× 53×         53×   53× 53×       18× 15× 15×   18× 18× 18× 18× 18× 18× 18× 18× 18× 18×     17× 17× 17×   18× 18× 80× 80× 38×       18×     18× 18× 18× 1697× 98× 98×     18× 118× 80×       53× 53× 884×     72× 72× 72× 72× 87× 11×         59× 59× 59× 59× 14× 14× 14×     59× 12× 12× 12× 123× 123× 123× 225×   123×     59×   348× 348× 348× 348×     150×   48×                   48×               76× 75× 75× 75× 75× 75× 75× 75×   75× 75× 75× 75× 75× 75× 75× 75× 75× 75× 75×   75× 63× 63×     63×       60× 60× 1461×   60× 60×       75× 34×   75×     75× 53× 53× 53× 53× 53× 53× 53× 53× 53×   53×         53× 53× 53×     53× 12× 10×     53× 53×   53× 19×   53× 39×     53× 53× 53×   24×           75× 91×     75× 75× 1918× 1918× 1918× 224×       76× 76×       48× 48×   29×               29×   29× 29×   29×   48×   17× 17× 17× 17× 17×   17×                    
define(["require", "exports", "@syncfusion/ej2-base", "../base/constant", "@syncfusion/ej2-data", "../utils", "@syncfusion/ej2-grids", "./crud-actions", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, events, ej2_data_1, utils_1, ej2_grids_1, crud_actions_1, ej2_base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BatchEdit = (function () {
        function BatchEdit(parent) {
            this.batchChildCount = 0;
            this.addedRecords = 'addedRecords';
            this.deletedRecords = 'deletedRecords';
            this.batchAddedRecords = [];
            this.batchDeletedRecords = [];
            this.batchAddRowRecord = [];
            this.parent = parent;
            this.isSelfReference = !ej2_base_1.isNullOrUndefined(parent.parentIdMapping);
            this.batchRecords = [];
            this.currentViewRecords = [];
            this.isAdd = false;
            this.addEventListener();
        }
        BatchEdit.prototype.addEventListener = function () {
            this.parent.on(events.cellSaved, this.cellSaved, this);
            this.parent.on(events.batchAdd, this.batchAdd, this);
            this.parent.on(events.beforeBatchAdd, this.beforeBatchAdd, this);
            this.parent.on(events.batchSave, this.batchSave, this);
            this.parent.on(events.beforeBatchDelete, this.beforeBatchDelete, this);
            this.parent.on(events.beforeBatchSave, this.beforeBatchSave, this);
            this.parent.on('batchPageAction', this.batchPageAction, this);
            this.parent.on('batchCancelAction', this.batchCancelAction, this);
            this.parent.grid.on('immutable-batch-cancel', this.immutableBatchAction, this);
            this.parent.grid.on('next-cell-index', this.nextCellIndex, this);
        };
        BatchEdit.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.cellSaved, this.cellSaved);
            this.parent.off(events.batchAdd, this.batchAdd);
            this.parent.off(events.batchSave, this.batchSave);
            this.parent.off(events.beforeBatchAdd, this.beforeBatchAdd);
            this.parent.off(events.beforeBatchDelete, this.beforeBatchDelete);
            this.parent.off(events.beforeBatchSave, this.beforeBatchSave);
            this.parent.off('batchPageAction', this.batchPageAction);
            this.parent.off('batchCancelAction', this.batchCancelAction);
            this.parent.grid.off('immutable-batch-cancel', this.immutableBatchAction);
            this.parent.grid.off('next-cell-index', this.nextCellIndex);
        };
        BatchEdit.prototype.destroy = function () {
            this.removeEventListener();
        };
        BatchEdit.prototype.getBatchRecords = function () {
            return this.batchRecords;
        };
        BatchEdit.prototype.getAddRowIndex = function () {
            return this.addRowIndex;
        };
        BatchEdit.prototype.getSelectedIndex = function () {
            return this.selectedIndex;
        };
        BatchEdit.prototype.getBatchChildCount = function () {
            return this.batchChildCount;
        };
        BatchEdit.prototype.batchPageAction = function () {
            var data = (this.parent.grid.dataSource instanceof ej2_data_1.DataManager ?
                this.parent.grid.dataSource.dataSource.json : this.parent.grid.dataSource);
            var primaryKey = this.parent.grid.getPrimaryKeyFieldNames()[0];
            var index;
            Iif (!ej2_base_1.isNullOrUndefined(this.batchAddedRecords) && this.batchAddedRecords.length) {
                for (var i = 0; i < this.batchAddedRecords.length; i++) {
                    index = data.map(function (e) { return e["" + primaryKey]; }).indexOf(this.batchAddedRecords[parseInt(i.toString(), 10)]["" + primaryKey]);
                    data.splice(index, 1);
                }
            }
            this.batchAddedRecords = this.batchRecords = this.batchAddRowRecord = this.batchDeletedRecords = this.currentViewRecords = [];
        };
        BatchEdit.prototype.cellSaved = function (args) {
            var actualCellIndex = args.column.index;
            if (actualCellIndex === this.parent.treeColumnIndex) {
                this.parent.renderModule.cellRender({ data: args.rowData, cell: args.cell,
                    column: this.parent.grid.getColumnByIndex(args.column.index)
                });
            }
            if (this.isAdd && this.parent.editSettings.mode === 'Batch' && this.parent.editSettings.newRowPosition !== 'Bottom') {
                var data = (this.parent.grid.dataSource instanceof ej2_data_1.DataManager ?
                    this.parent.grid.dataSource.dataSource.json : this.parent.grid.dataSource);
                var added = void 0;
                var level = 'level';
                var primaryKey_1 = this.parent.grid.getPrimaryKeyFieldNames()[0];
                var currentDataIndex = void 0;
                var indexvalue = void 0;
                var parentItem = 'parentItem';
                var uniqueID = 'uniqueID';
                var parentRecord = this.selectedIndex > -1 ? this.batchRecords[parseInt(this.addRowIndex.toString(), 10)]["" + parentItem] : null;
                var idMapping = void 0;
                var parentUniqueID = void 0;
                var parentIdMapping = void 0;
                var rowObjectIndex = this.parent.editSettings.newRowPosition === 'Top' || this.selectedIndex === -1 ? 0 :
                    this.parent.editSettings.newRowPosition === 'Above' ? this.addRowIndex
                        : this.addRowIndex + 1;
                rowObjectIndex = this.getActualRowObjectIndex(rowObjectIndex);
                if (this.newBatchRowAdded) {
                    Eif (this.batchRecords.length) {
                        idMapping = this.batchRecords[this.addRowIndex][this.parent.idMapping];
                        parentIdMapping = this.batchRecords[this.addRowIndex][this.parent.parentIdMapping];
                        if (this.batchRecords[parseInt(this.addRowIndex.toString(), 10)]["" + parentItem]) {
                            parentUniqueID = this.batchRecords[parseInt(this.addRowIndex.toString(), 10)]["" + parentItem]["" + uniqueID];
                        }
                    }
                    this.batchAddedRecords = utils_1.extendArray(this.batchAddedRecords);
                    this.batchAddRowRecord = utils_1.extendArray(this.batchAddRowRecord);
                    this.batchAddRowRecord.push(this.batchRecords[this.addRowIndex]);
                    added = this.parent.grid.getRowsObject()[parseInt(rowObjectIndex.toString(), 10)].changes;
                    added.uniqueID = ej2_grids_1.getUid(this.parent.element.id + '_data_');
                    ej2_base_1.setValue('uniqueIDCollection.' + added.uniqueID, added, this.parent);
                    Eif (!Object.prototype.hasOwnProperty.call(added, 'level')) {
                        this.batchIndex = this.selectedIndex === -1 ? 0 : this.batchIndex;
                        if (this.parent.editSettings.newRowPosition === 'Child') {
                            added.primaryParent = parentRecord;
                            Eif (this.selectedIndex > -1) {
                                added.parentItem = ej2_base_1.extend({}, this.batchRecords[this.addRowIndex]);
                                added.parentUniqueID = added.parentItem.uniqueID;
                                delete added.parentItem.childRecords;
                                delete added.parentItem[this.parent.childMapping];
                                added.level = added.parentItem.level + 1;
                                added.index = this.batchIndex;
                                var childRecordCount = utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex]).length;
                                var record = utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex])[childRecordCount - 1];
                                record = ej2_base_1.isNullOrUndefined(record) ? this.batchRecords[this.addRowIndex] : record;
                                currentDataIndex = data.map(function (e) { return e["" + primaryKey_1]; }).indexOf(record["" + primaryKey_1]);
                                if (this.isSelfReference) {
                                    added[this.parent.parentIdMapping] = idMapping;
                                }
                                crud_actions_1.updateParentRow(primaryKey_1, added.parentItem, 'add', this.parent, this.isSelfReference, added);
                            }
                        }
                        else if ((this.parent.editSettings.newRowPosition === 'Above' || this.parent.editSettings.newRowPosition === 'Below')
                            && !ej2_base_1.isNullOrUndefined(this.batchRecords[this.addRowIndex])) {
                            added.level = this.batchRecords[parseInt(this.addRowIndex.toString(), 10)]["" + level];
                            if (added.level && this.selectedIndex > -1) {
                                added.parentItem = parentRecord;
                                added.parentUniqueID = parentUniqueID;
                                delete added.parentItem.childRecords;
                                delete added.parentItem[this.parent.childMapping];
                            }
                            added.index = this.parent.editSettings.newRowPosition === 'Below' ? this.batchIndex : this.batchIndex - 1;
                            if (this.parent.editSettings.newRowPosition === 'Below' && this.selectedIndex > -1) {
                                var childRecordCount = utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex]).length;
                                var record = utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex])[childRecordCount - 1];
                                record = ej2_base_1.isNullOrUndefined(record) ? this.batchRecords[this.addRowIndex] : record;
                                currentDataIndex = data.map(function (e) { return e["" + primaryKey_1]; }).indexOf(record["" + primaryKey_1]);
                            }
                            if (this.parent.editSettings.newRowPosition === 'Above' && this.selectedIndex > -1) {
                                var record = this.batchRecords[this.addRowIndex];
                                currentDataIndex = data.map(function (e) { return e["" + primaryKey_1]; }).indexOf(record["" + primaryKey_1]);
                            }
                            if (this.isSelfReference) {
                                added[this.parent.parentIdMapping] = parentIdMapping;
                            }
                        }
                        added.index = added.index === -1 ? 0 : added.index;
                        added.hasChildRecords = false;
                        added.childRecords = [];
                        this.batchRecords.splice(added.index, 0, added);
                        this.currentViewRecords.splice(added.index, 0, added);
                        if (currentDataIndex) {
                            indexvalue = currentDataIndex;
                        }
                        else {
                            indexvalue = added.index;
                        }
                        if (this.parent.editSettings.newRowPosition !== 'Above') {
                            indexvalue = added.index === 0 ? indexvalue : indexvalue + 1;
                        }
                        data.splice(indexvalue, 0, added);
                        this.batchAddedRecords.push(added);
                    }
                    this.parent.grid.getRowsObject()[parseInt(rowObjectIndex.toString(), 10)].data = added;
                    this.newBatchRowAdded = false;
                }
            }
        };
        BatchEdit.prototype.beforeBatchAdd = function (e) {
            var isTabLastRow = 'isTabLastRow';
            Iif (this.parent.editSettings.mode === 'Cell' && this.parent.editModule["" + isTabLastRow]) {
                e.cancel = true;
                this.parent.editModule["" + isTabLastRow] = false;
                return;
            }
            if (this.parent.editModule['isAddedRowByMethod'] && !ej2_base_1.isNullOrUndefined(this.parent.editModule['addRowIndex']) &&
                !this.parent.editModule['isAddedRowByContextMenu'] && (this.parent.grid.selectedRowIndex === -1 || this.parent.editModule['batchEditModule'].isAdd)) {
                this.selectedIndex = this.parent.editModule['selectedIndex'];
                this.addRowIndex = this.parent.editModule['addRowIndex'];
                this.addRowRecord = this.batchRecords.length ? this.batchRecords[this.selectedIndex]
                    : this.parent.getCurrentViewRecords()[this.selectedIndex];
            }
            else {
                this.selectedIndex = this.parent.grid.selectedRowIndex;
                this.addRowIndex = this.parent.grid.selectedRowIndex > -1 ? this.parent.grid.selectedRowIndex : 0;
                this.parent.editModule['addRowIndex'] = this.parent.grid.selectedRowIndex > -1 ? this.parent.grid.selectedRowIndex : 0;
                this.addRowRecord = this.parent.getSelectedRecords()[0];
            }
        };
        BatchEdit.prototype.batchAdd = function (e) {
            Eif (this.parent.editSettings.newRowPosition !== 'Bottom') {
                this.isAdd = true;
                this.newBatchRowAdded = true;
                var actualIndex = 0;
                if (!this.batchRecords.length) {
                    this.batchAddedRecords = [];
                    this.batchRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
                    this.currentViewRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
                }
                if (this.parent.editModule['isAddedRowByMethod'] && !ej2_base_1.isNullOrUndefined(this.parent.editModule['addRowIndex'])) {
                    ej2_base_2.classList(this.parent.grid.getDataRows()[0], ['e-batchrow'], []);
                }
                if (this.parent.editSettings.newRowPosition !== 'Top') {
                    var records = this.parent.grid.getCurrentViewRecords();
                    if (this.parent.editSettings.mode === 'Batch' && (this.parent.getBatchChanges()[this.addedRecords].length > 1
                        || this.parent.getBatchChanges()[this.deletedRecords].length)) {
                        records = this.batchRecords;
                    }
                    this.updateChildCount(records);
                    this.parent.notify(events.beginAdd, {});
                    this.batchChildCount = 0;
                }
                this.updateRowIndex();
                var focusModule = ej2_base_1.getValue('focusModule', this.parent.grid);
                var table = this.parent.getContentTable();
                Iif (this.parent.getBatchChanges()[this.deletedRecords].length && this.parent.editSettings.newRowPosition === 'Above') {
                    actualIndex = e.row.rowIndex;
                    focusModule.getContent().matrix.matrix = this.matrix;
                }
                else {
                    actualIndex = table.getElementsByClassName('e-batchrow')[0].rowIndex;
                }
                focusModule.getContent().matrix.current = [actualIndex, focusModule.getContent().matrix.current[1]];
                if (this.parent.editModule['isAddedRowByMethod'] && !ej2_base_1.isNullOrUndefined(this.parent.editModule['addRowIndex']) && !this.parent.editModule['isAddedRowByContextMenu']) {
                    var newlyAddedRecords = this.parent.getBatchChanges()['addedRecords'];
                    var index = parseInt(this.parent.getContentTable().getElementsByClassName('e-insertedrow')[newlyAddedRecords.length - 1].getAttribute('data-rowindex'), 10);
                    this.batchRecords.splice(index, 0, newlyAddedRecords[newlyAddedRecords.length - 1]);
                }
            }
        };
        BatchEdit.prototype.beforeBatchDelete = function (args) {
            if (!this.batchRecords.length) {
                this.batchRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
                this.currentViewRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
            }
            var focusModule = ej2_base_1.getValue('focusModule', this.parent.grid);
            this.matrix = focusModule.getContent().matrix.matrix;
            var row = [];
            var records = [];
            var primarykey = this.parent.grid.getPrimaryKeyFieldNames()[0];
            var data;
            var childs;
            var uid;
            var rowElement = Array.isArray(args.row) ? args.row[0] : args.row;
            if (!ej2_base_1.isNullOrUndefined(rowElement) && this.parent.getSelectedRows().indexOf(rowElement) === -1) {
                data = args.rowData;
                childs = utils_1.findChildrenRecords(data);
                uid = rowElement.getAttribute('data-uid');
            }
            else {
                data = this.parent.grid.getSelectedRecords()[this.parent.grid.getSelectedRecords().length - 1];
                childs = utils_1.findChildrenRecords(data);
                uid = this.parent.getSelectedRows()[0].getAttribute('data-uid');
            }
            var parentRowIndex = parseInt(this.parent.grid.getRowElementByUID(uid).getAttribute('data-rowindex'), 10);
            if (childs.length) {
                var totalCount = parentRowIndex + childs.length;
                var firstChildIndex = parentRowIndex + 1;
                for (var i = firstChildIndex; i <= totalCount; i++) {
                    row.push(this.parent.grid.getDataRows()[parseInt(i.toString(), 10)]);
                    if (this.parent.frozenRows || this.parent.frozenColumns || this.parent.getFrozenColumns()) {
                        row.push(this.parent.grid.getHeaderContent()[parseInt(i.toString(), 10)]);
                    }
                }
            }
            if (!ej2_base_1.isNullOrUndefined(data.parentItem)) {
                var parentItem = utils_1.getParentData(this.parent, data.parentItem.uniqueID);
                Eif (!ej2_base_1.isNullOrUndefined(parentItem) && parentItem.hasChildRecords) {
                    var childIndex = parentItem.childRecords.indexOf(data);
                    parentItem.childRecords.splice(childIndex, 1);
                }
                this.batchDeletedRecords = utils_1.extendArray(this.batchDeletedRecords);
                this.batchDeletedRecords.push(data);
            }
            childs.push(data);
            records = childs;
            for (var i = 0; i < records.length; i++) {
                var indexvalue = this.batchRecords.map(function (e) { return e["" + primarykey]; }).indexOf(records[parseInt(i.toString(), 10)]["" + primarykey]);
                Eif (indexvalue !== -1) {
                    this.batchRecords.splice(indexvalue, 1);
                }
            }
            for (var i = 0; i < row.length; i++) {
                if (!ej2_base_1.isNullOrUndefined(row[parseInt(i.toString(), 10)])) {
                    this.parent.grid.selectionModule.selectedRecords.push(row[parseInt(i.toString(), 10)]);
                }
            }
        };
        BatchEdit.prototype.updateRowIndex = function () {
            var rows = this.parent.grid.getDataRows();
            for (var i = 0; i < rows.length; i++) {
                rows[parseInt(i.toString(), 10)].setAttribute('data-rowindex', i.toString());
            }
        };
        BatchEdit.prototype.updateChildCount = function (records) {
            var primaryKey = this.parent.grid.getPrimaryKeyFieldNames()[0];
            var addedRecords = 'addedRecords';
            var parentItem = this.parent.editSettings.newRowPosition === 'Child' ? 'primaryParent' : 'parentItem';
            for (var i = 0; i < this.parent.getBatchChanges()["" + addedRecords].length; i++) {
                if (!ej2_base_1.isNullOrUndefined(this.parent.getBatchChanges()["" + addedRecords][parseInt(i.toString(), 10)]["" + parentItem])) {
                    if (this.parent.getBatchChanges()["" + addedRecords][parseInt(i.toString(), 10)]["" + parentItem]["" + primaryKey] === records[parseInt(this.addRowIndex.toString(), 10)]["" + primaryKey]) {
                        this.batchChildCount = this.batchChildCount + 1;
                    }
                }
            }
        };
        BatchEdit.prototype.beforeBatchSave = function (e) {
            var changeRecords = 'changedRecords';
            var deleterecords = 'deletedRecords';
            var changedRecords = e.batchChanges["" + changeRecords];
            if (e.batchChanges["" + changeRecords].length) {
                var columnName = void 0;
                for (var i = 0; i < changedRecords.length; i++) {
                    crud_actions_1.editAction({ value: changedRecords[parseInt(i.toString(), 10)], action: 'edit' }, this.parent, this.isSelfReference, this.addRowIndex, this.selectedIndex, columnName);
                }
            }
            if (e.batchChanges["" + deleterecords].length) {
                var deletedRecords = e.batchChanges["" + deleterecords];
                var record = deletedRecords;
                for (var i = 0; i < record.length; i++) {
                    this.deleteUniqueID(record[parseInt(i.toString(), 10)].uniqueID);
                    var childs = utils_1.findChildrenRecords(record[parseInt(i.toString(), 10)]);
                    for (var c = 0; c < childs.length; c++) {
                        this.deleteUniqueID(childs[parseInt(c.toString(), 10)].uniqueID);
                    }
                    e.batchChanges["" + deleterecords] = e.batchChanges["" + deleterecords].concat(childs);
                }
            }
            this.isAdd = false;
        };
        BatchEdit.prototype.deleteUniqueID = function (value) {
            var idFilter = 'uniqueIDFilterCollection';
            delete this.parent["" + idFilter]["" + value];
            var id = 'uniqueIDCollection';
            delete this.parent["" + id]["" + value];
        };
        BatchEdit.prototype.batchCancelAction = function () {
            var targetElement = 'targetElement';
            var index;
            var parentItem = 'parentItem';
            var indexvalue = 'index';
            var currentViewRecords = this.parent.grid.getCurrentViewRecords();
            var childRecords = 'childRecords';
            var data = (this.parent.grid.dataSource instanceof ej2_data_1.DataManager ?
                this.parent.grid.dataSource.dataSource.json : this.parent.grid.dataSource);
            var primaryKey = this.parent.grid.getPrimaryKeyFieldNames()[0];
            Eif (!ej2_base_1.isNullOrUndefined(this.batchAddedRecords)) {
                for (var i = 0; i < this.batchAddedRecords.length; i++) {
                    index = data.map(function (e) { return e["" + primaryKey]; }).indexOf(this.batchAddedRecords[parseInt(i.toString(), 10)]["" + primaryKey]);
                    Eif (index !== -1) {
                        data.splice(index, 1);
                    }
                    Eif (this.parent.editSettings.newRowPosition === 'Child') {
                        index = currentViewRecords.map(function (e) { return e["" + primaryKey]; })
                            .indexOf(this.batchAddedRecords[parseInt(i.toString(), 10)]["" + parentItem] ? this.batchAddedRecords[parseInt(i.toString(), 10)]["" + parentItem]["" + primaryKey]
                            : this.batchAddedRecords[parseInt(i.toString(), 10)]["" + primaryKey]);
                        Eif (!ej2_base_1.isNullOrUndefined(currentViewRecords[parseInt(index.toString(), 10)])) {
                            var children = currentViewRecords[parseInt(index.toString(), 10)]["" + childRecords];
                            for (var j = 0; children && j < children.length; j++) {
                                Eif (children[parseInt(j.toString(), 10)]["" + primaryKey] === this.batchAddedRecords[parseInt(i.toString(), 10)]["" + primaryKey]) {
                                    currentViewRecords[parseInt(index.toString(), 10)]["" + childRecords].splice(j, 1);
                                }
                            }
                        }
                    }
                }
            }
            if (!ej2_base_1.isNullOrUndefined(this.parent["" + targetElement])) {
                var row = this.parent["" + targetElement].closest('tr');
                this.parent.collapseRow(row);
                this.parent["" + targetElement] = null;
            }
            Eif (!ej2_base_1.isNullOrUndefined(this.batchDeletedRecords)) {
                for (var i = 0; i < this.batchDeletedRecords.length; i++) {
                    Eif (!ej2_base_1.isNullOrUndefined(this.batchDeletedRecords[parseInt(i.toString(), 10)]["" + parentItem])) {
                        index = currentViewRecords.map(function (e) { return e["" + primaryKey]; })
                            .indexOf(this.batchDeletedRecords[parseInt(i.toString(), 10)]["" + parentItem]["" + primaryKey]);
                        var positionIndex = this.batchDeletedRecords[parseInt(i.toString(), 10)]["" + indexvalue] === 0 ? this.batchDeletedRecords[parseInt(i.toString(), 10)]["" + indexvalue] :
                            this.batchDeletedRecords[parseInt(i.toString(), 10)]["" + indexvalue] - 1;
                        Eif (!ej2_base_1.isNullOrUndefined(currentViewRecords[parseInt(index.toString(), 10)])) {
                            currentViewRecords[parseInt(index.toString(), 10)]["" + childRecords].splice(positionIndex, 0, this.batchDeletedRecords[parseInt(i.toString(), 10)]);
                        }
                    }
                }
            }
            this.batchAddedRecords = this.batchRecords = this.batchAddRowRecord = this.currentViewRecords = [];
            this.batchRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
            this.batchIndex = 0;
            this.currentViewRecords = utils_1.extendArray(this.parent.grid.getCurrentViewRecords());
            this.batchDeletedRecords = [];
            this.parent.grid.renderModule.refresh();
        };
        BatchEdit.prototype.batchSave = function (args) {
            if (this.parent.editSettings.mode === 'Batch') {
                var i = void 0;
                var batchChanges = Object.hasOwnProperty.call(args, 'updatedRecords') ? args.updatedRecords : this.parent.getBatchChanges();
                var deletedRecords = 'deletedRecords';
                var addedRecords = 'addedRecords';
                var index = 'index';
                var uniqueID = 'uniqueID';
                var data = (this.parent.grid.dataSource instanceof ej2_data_1.DataManager ?
                    this.parent.grid.dataSource.dataSource.json : this.parent.grid.dataSource);
                var currentViewRecords = this.parent.grid.getCurrentViewRecords();
                var primarykey_1 = this.parent.grid.getPrimaryKeyFieldNames()[0];
                var level = 'level';
                var addRecords = batchChanges["" + addedRecords];
                var parentItem = 'parentItem';
                var selectedIndex = void 0;
                var addRowIndex = void 0;
                var columnName = void 0;
                var addRowRecord = void 0;
                var childRecords = 'childRecords';
                if (addRecords.length > 1 && this.parent.editSettings.newRowPosition !== 'Bottom') {
                    addRecords.reverse();
                }
                if (this.parent.editSettings.newRowPosition !== 'Bottom' && !Object.hasOwnProperty.call(args, 'updatedRecords')) {
                    data.splice(data.length - addRecords.length, addRecords.length);
                    if (this.parent.editModule['isAddedRowByMethod'] && addRecords.length && !ej2_base_1.isNullOrUndefined(this.parent.editModule['addRowIndex']) && !this.parent.editModule['isAddedRowByContextMenu']) {
                        addRecords.reverse();
                        for (var i_1 = 0; i_1 < addRecords.length; i_1++) {
                            var index_1 = parseInt(this.parent.getContentTable().getElementsByClassName('e-insertedrow')[parseInt(i_1.toString(), 10)].getAttribute('data-rowindex'), 10);
                            data.splice(index_1, 0, addRecords[parseInt(i_1.toString(), 10)]);
                        }
                    }
                    if (!this.parent.allowPaging && data.length !== currentViewRecords.length) {
                        Eif (currentViewRecords.length > addRecords.length) {
                            currentViewRecords.splice(currentViewRecords.length - addRecords.length, addRecords.length);
                        }
                    }
                    else {
                        var totalRecords = utils_1.extendArray(data);
                        Eif (totalRecords.length) {
                            var startIndex = totalRecords.map(function (e) { return e["" + primarykey_1]; })
                                .indexOf(currentViewRecords[0]["" + primarykey_1]);
                            var endIndex = startIndex + this.parent.grid.pageSettings.pageSize;
                            currentViewRecords = totalRecords.splice(startIndex, endIndex);
                        }
                    }
                }
                if (this.batchAddRowRecord.length === 0) {
                    this.batchAddRowRecord.push(this.parent.flatData[args.index]);
                }
                Iif (this.parent.editModule['isAddedRowByContextMenu']) {
                    addRecords.reverse();
                }
                for (i = 0; i < addRecords.length; i++) {
                    var taskData = ej2_base_1.extend({}, addRecords[parseInt(i.toString(), 10)]);
                    delete taskData.parentItem;
                    delete taskData.uniqueID;
                    delete taskData.index;
                    delete taskData.level;
                    delete taskData.hasChildRecords;
                    delete taskData.childRecords;
                    delete taskData.parentUniqueID;
                    if (!ej2_base_1.isNullOrUndefined(taskData.primaryParent)) {
                        delete taskData.primaryParent;
                    }
                    Iif (addRecords.length > 1 && this.parent.editModule['isAddedRowByContextMenu']) {
                        var rowPosition = this.parent.editSettings.newRowPosition;
                        this.parent.editSettings.newRowPosition = this.parent.editModule['previousNewRowPosition'];
                        this.parent.editModule['previousNewRowPosition'] = rowPosition;
                    }
                    addRecords[parseInt(i.toString(), 10)].taskData = taskData;
                    addRowRecord = this.batchAddRowRecord[parseInt(i.toString(), 10)];
                    Iif (ej2_base_1.isNullOrUndefined(addRowRecord)) {
                        addRowRecord = this.batchAddRowRecord[i - 1];
                    }
                    if (this.isSelfReference) {
                        if (!ej2_base_1.isNullOrUndefined(addRecords[parseInt(i.toString(), 10)].parentItem)) {
                            crud_actions_1.updateParentRow(primarykey_1, addRecords[parseInt(i.toString(), 10)].parentItem, 'add', this.parent, this.isSelfReference, addRecords[parseInt(i.toString(), 10)]);
                        }
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(addRowRecord)) {
                        addRowIndex = addRowRecord.index;
                    }
                    if (ej2_base_1.isNullOrUndefined(addRecords[parseInt(i.toString(), 10)].index)) {
                        addRowIndex = 0;
                    }
                    if (this.parent.editSettings.newRowPosition !== 'Top' && this.parent.editSettings.newRowPosition !== 'Bottom') {
                        if (ej2_base_1.isNullOrUndefined(addRecords[parseInt(i.toString(), 10)].parentItem) && this.selectedIndex === -1) {
                            selectedIndex = -1;
                            addRowRecord = null;
                        }
                    }
                    crud_actions_1.editAction({ value: addRecords[parseInt(i.toString(), 10)], action: 'add' }, this.parent, this.isSelfReference, addRowIndex, selectedIndex, columnName, addRowRecord);
                    selectedIndex = null;
                    if (this.parent.editSettings.newRowPosition === 'Child' && !ej2_base_1.isNullOrUndefined(addRecords[parseInt(i.toString(), 10)]["" + parentItem]) &&
                        (ej2_base_1.isNullOrUndefined(this.parent.editModule['addRowIndex']) || this.isSelfReference)) {
                        var indexValue = currentViewRecords.map(function (e) { return e["" + primarykey_1]; })
                            .indexOf(addRecords[parseInt(i.toString(), 10)]["" + parentItem]["" + primarykey_1]);
                        var children = currentViewRecords[parseInt(indexValue.toString(), 10)]["" + childRecords];
                        for (var j = 0; j < children.length; j++) {
                            Eif (children[parseInt(j.toString(), 10)]["" + primarykey_1] === addRecords[parseInt(i.toString(), 10)]["" + primarykey_1]) {
                                currentViewRecords[parseInt(indexValue.toString(), 10)]["" + childRecords].splice(j, 1);
                            }
                        }
                    }
                }
                if (batchChanges["" + deletedRecords].length) {
                    for (i = 0; i < batchChanges["" + deletedRecords].length; i++) {
                        crud_actions_1.editAction({ value: batchChanges["" + deletedRecords][parseInt(i.toString(), 10)], action: 'delete' }, this.parent, this.isSelfReference, addRowIndex, selectedIndex, columnName, addRowRecord);
                    }
                }
                this.parent.parentData = [];
                for (var i_2 = 0; i_2 < data.length; i_2++) {
                    data[parseInt(i_2.toString(), 10)]["" + index] = i_2;
                    ej2_base_1.setValue('uniqueIDCollection.' + data[parseInt(i_2.toString(), 10)]["" + uniqueID] + '.index', i_2, this.parent);
                    if (!data[parseInt(i_2.toString(), 10)]["" + level]) {
                        this.parent.parentData.push(data[parseInt(i_2.toString(), 10)]);
                    }
                }
            }
            this.batchAddRowRecord = this.batchAddedRecords = this.batchRecords = this.batchDeletedRecords = this.currentViewRecords = [];
            Iif (this.parent.editModule['isAddedRowByContextMenu']) {
                this.parent.editModule['isAddedRowByContextMenu'] = false;
            }
        };
        BatchEdit.prototype.getActualRowObjectIndex = function (index) {
            var rows = this.parent.grid.getDataRows();
            if ((this.parent.editSettings.newRowPosition === 'Below' || this.parent.editSettings.newRowPosition === 'Child')
                && this.selectedIndex > -1) {
                if (!ej2_base_1.isNullOrUndefined(this.batchRecords[this.addRowIndex]) && this.batchRecords[this.addRowIndex].expanded) {
                    Eif (this.parent.getBatchChanges()[this.addedRecords].length > 1
                        || this.parent.getBatchChanges()[this.deletedRecords].length) {
                        index += utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex]).length;
                        if (this.parent.editSettings.newRowPosition !== 'Child') {
                            var batchChildCount = this.getBatchChildCount();
                            index = index + batchChildCount;
                        }
                    }
                    else {
                        index += utils_1.findChildrenRecords(this.batchRecords[this.addRowIndex]).length;
                    }
                }
                if (index >= rows.length) {
                    index = rows.length - 1;
                }
                this.updateChildCount(this.parent.grid.getCurrentViewRecords());
                if (this.batchChildCount) {
                    index += this.batchChildCount;
                }
                this.batchChildCount = 0;
            }
            return index;
        };
        BatchEdit.prototype.immutableBatchAction = function (e) {
            e.args.cancel = true;
            var changes = this.parent.grid.getBatchChanges();
            var addedRecords = [];
            var index = 'index';
            if (Object.keys(changes).length) {
                addedRecords = changes.addedRecords;
            }
            for (var i = 0; i < addedRecords.length; i++) {
                e.rows.splice(addedRecords[parseInt(i.toString(), 10)]["" + index], 1);
            }
        };
        BatchEdit.prototype.nextCellIndex = function (args) {
            var index = 'index';
            var rowIndex = 'rowIndex';
            Eif (this.parent.getSelectedRows().length) {
                args["" + index] = this.parent.getSelectedRows()[0]["" + rowIndex];
            }
            else {
                args["" + index] = this.batchIndex;
            }
        };
        return BatchEdit;
    }());
    exports.BatchEdit = BatchEdit;
});