all files / grid/actions/ edit.js

94.29% Statements 380/403
83.2% Branches 213/256
95.52% Functions 64/67
94.26% Lines 378/401
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   65×           65× 65× 65× 65× 65× 65× 65× 65×   72× 72× 516× 24× 24×     492×         8073×   107× 94×   13× 13× 13× 14× 14×                 68×   68× 68×   71×   64×   62×                                   44× 44×   41×     36× 29×   40×     40× 40× 40× 40×   19×     14× 14× 14×   318×   36×   35× 35× 35×   35× 35×   34× 25×     32×   28×     58×   10× 10× 10× 10× 10×     48×   14×         43×         15×     30×   55× 55×   45× 45× 45×   407× 407×   125× 125×   35×   35×     36×   36×   407×   670× 670× 22× 22×   670×   65×                     65×             130× 130× 130×                 130× 130× 130× 130×   38×   25×         12× 12×   25×   65×     65× 65× 65× 65× 65× 65× 65× 65× 65× 65× 65× 65×   62× 61×     174× 174× 61×   174×   123× 123× 123× 48× 48× 48× 48× 48×   42× 42× 42×             48×     48× 48×   48× 48×       981×   117× 117× 359× 359× 353× 353×     117×   359× 359× 359× 359× 359×         359×           359×   193× 193×   12× 12×     125× 125×   1054×   125× 125× 519× 519× 519× 219×         219×       125× 473× 430×               203× 203× 137×   203×   62× 62× 62× 62× 62× 62× 62× 62× 62× 62× 62×     76×           11× 11×   15×         15×       23× 23×   12×   137× 137× 137× 137× 137× 137× 137× 137× 572× 40×   532×   531× 71×     137×     128×   137×   146× 146×     128×     22×       22× 22× 22× 22× 22×             150× 150× 139×     150×     128× 128× 128× 60× 34×     26×         22× 22× 22× 22× 22× 20×     22× 22×     22× 22×   22× 22× 22×                 22× 22× 22× 22× 22× 22× 22× 22× 22× 22×       22× 22× 20× 20× 20×            
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"], 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) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Edit = (function () {
        function Edit(parent, serviceLocator) {
            this.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
            };
            this.editType = { 'Inline': inline_edit_1.InlineEdit, 'Normal': inline_edit_1.InlineEdit, 'Batch': batch_edit_1.BatchEdit, 'Dialog': dialog_edit_1.DialogEdit };
            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 _this = this;
            this.parent.columns.forEach(function (col) {
                if (_this.parent.editSettings.template || col.editTemplate) {
                    var templteCell = 'templateedit';
                    col.edit = ej2_base_2.extend(new _this.editCellType[templteCell](_this.parent), col.edit || {});
                }
                else {
                    col.edit = ej2_base_2.extend(new _this.editCellType[col.editType && _this.editCellType[col.editType] ?
                        col.editType : 'defaultedit'](_this.parent, _this.serviceLocator), col.edit || {});
                }
            });
        };
        Edit.prototype.getModuleName = function () {
            return 'edit';
        };
        Edit.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            var gObj = this.parent;
            var newProp = e.properties;
            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':
                        Eif (gObj.editSettings.allowAdding || gObj.editSettings.allowEditing || gObj.editSettings.allowDeleting) {
                            this.initialEnd();
                        }
                        break;
                    case 'mode':
                        this.updateEditObj();
                        gObj.isEdit = 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.wireEvents = function () {
            ej2_base_1.EventHandler.add(this.parent.getContent(), 'touchstart', this.tapEvent, this);
        };
        Edit.prototype.unwireEvents = function () {
            ej2_base_1.EventHandler.remove(this.parent.getContent(), 'touchstart', this.tapEvent);
        };
        Edit.prototype.tapEvent = function (e) {
            if (this.getUserAgent()) {
                if (!Global.timer) {
                    Global.timer = setTimeout(function () {
                        Global.timer = null;
                    }, 300);
                }
                else {
                    clearTimeout(Global.timer);
                    Global.timer = null;
                    this.parent.notify(events.doubleTap, e);
                }
            }
        };
        Edit.prototype.getUserAgent = function () {
            var userAgent = window.navigator.userAgent.toLowerCase();
            return /iphone|ipod|ipad/.test(userAgent);
        };
        Edit.prototype.startEdit = function (tr) {
            var gObj = this.parent;
            if (!gObj.editSettings.allowEditing || gObj.isEdit || gObj.editSettings.mode === 'Batch') {
                return;
            }
            if (!gObj.getSelectedRows().length) {
                if (!tr) {
                    this.showDialog('EditOperationAlert', this.alertDObj);
                    return;
                }
            }
            else if (!tr) {
                tr = gObj.getSelectedRows()[0];
            }
            Iif (tr.style.display === 'none') {
                return;
            }
            this.editModule.startEdit(tr);
            this.refreshToolbar();
            gObj.element.querySelector('.e-gridpopup').style.display = 'none';
            this.parent.notify('start-edit', {});
        };
        Edit.prototype.closeEdit = function () {
            if (this.parent.editSettings.mode === 'Batch' && this.parent.editSettings.showConfirmDialog
                && this.parent.element.querySelectorAll('.e-updatedtd').length) {
                this.showDialog('CancelEdit', this.dialogObj);
                return;
            }
            this.editModule.closeEdit();
            this.refreshToolbar();
            this.parent.notify('close-edit', {});
        };
        Edit.prototype.refreshToolbar = function () {
            this.parent.notify(events.toolbarRefresh, {});
        };
        Edit.prototype.addRecord = function (data, index) {
            if (!this.parent.editSettings.allowAdding) {
                return;
            }
            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) {
                    this.showDialog('DeleteOperationAlert', this.alertDObj);
                    return;
                }
            }
            if (gObj.editSettings.showDeleteConfirmDialog) {
                this.showDialog('ConfirmDelete', this.dialogObj);
                return;
            }
            this.editModule.deleteRecord(fieldname, data);
        };
        Edit.prototype.deleteRow = function (tr) {
            this.deleteRecord(null, this.parent.getCurrentViewRecords()[parseInt(tr.getAttribute('aria-rowindex'), 10)]);
        };
        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, {});
                Eif (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 () {
            Eif (this.formObj) {
                return this.formObj.validate();
            }
            return false;
        };
        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 () {
            this.editModule.endEdit();
            this.refreshToolbar();
        };
        Edit.prototype.showDialog = function (content, obj) {
            obj.content = '<div>' + this.l10n.getConstant(content) + '</div>';
            obj.dataBind();
            obj.show();
        };
        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);
                    }
                    break;
            }
            return val;
        };
        Edit.prototype.destroyToolTip = function () {
            var elements = [].slice.call(this.parent.element.querySelectorAll('.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';
        };
        Edit.prototype.createConfirmDlg = function () {
            this.dialogObj = this.dlgWidget([
                {
                    click: this.dlgOk.bind(this),
                    buttonModel: { content: this.l10n.getConstant('OKButton'), cssClass: 'e-primary', isPrimary: true }
                },
                {
                    click: this.dlgCancel.bind(this),
                    buttonModel: { 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: 'e-flat', isPrimary: true }
                }
            ], 'EditAlert');
        };
        Edit.prototype.alertClick = function () {
            this.alertDObj.hide();
        };
        Edit.prototype.dlgWidget = function (btnOptions, name) {
            var div = ej2_base_3.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' }
            };
            options.buttons = btnOptions;
            var obj = new ej2_popups_1.Dialog(options);
            obj.appendTo(div);
            return obj;
        };
        Edit.prototype.dlgCancel = function () {
            this.dialogObj.hide();
        };
        Edit.prototype.dlgOk = function (e) {
            switch (this.dialogObj.element.querySelector('.e-dlg-content').firstElementChild.innerText) {
                case this.l10n.getConstant('ConfirmDelete'):
                    this.editModule.deleteRecord();
                    break;
                case this.l10n.getConstant('CancelEdit'):
                    this.editModule.closeEdit();
                    break;
                case this.l10n.getConstant('BatchSaveConfirm'):
                    this.endEditing();
                    break;
                case this.l10n.getConstant('BatchSaveLostChanges'):
                    this.executeAction();
                    break;
            }
            this.dlgCancel();
        };
        Edit.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.inBoundModelChanged, this.onPropertyChanged, this);
            this.parent.on(events.initialEnd, this.initialEnd, this);
            this.parent.on(events.keyPressed, this.keyPressHandler, this);
            this.parent.on(events.autoCol, this.updateColTypeObj, this);
            this.parent.on(events.tooltipDestroy, this.destroyToolTip, this);
            this.parent.on(events.preventBatch, this.preventBatch, this);
            this.parent.on(events.destroyForm, this.destroyForm, 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);
            this.parent.on(events.initialEnd, this.wireEvents, this);
        };
        Edit.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.inBoundModelChanged, this.onPropertyChanged);
            this.parent.off(events.initialEnd, this.initialEnd);
            this.parent.off(events.keyPressed, this.keyPressHandler);
            this.parent.off(events.autoCol, this.updateColTypeObj);
            this.parent.off(events.tooltipDestroy, this.destroyToolTip);
            this.parent.off(events.preventBatch, this.preventBatch);
            this.parent.off(events.destroyForm, this.destroyForm);
            this.parent.removeEventListener(events.actionComplete, this.actionCompleteFunction);
            this.parent.removeEventListener(events.actionBegin, this.actionBeginFunction);
            this.parent.off(events.initialEnd, this.unwireEvents);
        };
        Edit.prototype.actionComplete = function (e) {
            var actions = ['add', 'beginEdit', 'save', 'delete', 'cancel'];
            if (actions.indexOf(e.requestType) < 0) {
                this.parent.isEdit = false;
            }
            this.refreshToolbar();
        };
        Edit.prototype.getCurrentEditedData = function (form, editedData) {
            var _this = this;
            var gObj = this.parent;
            if (gObj.editSettings.template) {
                [].slice.call(form.elements).forEach(function (element) {
                    Eif (element.hasAttribute('name')) {
                        var field = util_1.setComplexFieldID(element.getAttribute('name'));
                        var column = gObj.getColumnByField(field) || { field: field, type: element.getAttribute('type') };
                        var value = void 0;
                        if (column.type === 'checkbox' || column.type === 'boolean') {
                            value = element.checked;
                        }
                        else Eif (element.value) {
                            value = element.value;
                            Iif (element.ej2_instances &&
                                element.ej2_instances.length &&
                                !ej2_base_4.isNullOrUndefined(element.ej2_instances[0].value)) {
                                element.blur();
                                value = element.ej2_instances[0].value;
                            }
                        }
                        Iif (column.edit && typeof column.edit.read === 'string') {
                            value = ej2_base_2.getValue(column.edit.read, window)(element, value);
                        }
                        else Eif (column.edit && column.edit.read) {
                            value = column.edit.read(element, value);
                        }
                        value = gObj.editModule.getValueFromType(column, value);
                        ej2_base_4.setValue(column.field, ej2_base_1.isUndefined(value) || value === 'null' ? null : value, editedData);
                    }
                });
                return editedData;
            }
            gObj.columnModel.filter(function (col) { return col.editTemplate; }).forEach(function (col) {
                var value = _this.getValue(col, form[util_1.getComplexFieldID(col.field)]);
                ej2_base_4.setValue(col.field, ej2_base_1.isUndefined(value) || value === 'null' ? null : value, editedData);
            });
            var inputs = [].slice.call(form.querySelectorAll('.e-field'));
            for (var i = 0, len = inputs.length; i < len; i++) {
                var col = gObj.getColumnByUid(inputs[i].getAttribute('e-mappinguid'));
                if (col && col.field) {
                    var value = this.getValue(col, inputs[i]);
                    ej2_base_4.setValue(col.field, ej2_base_1.isUndefined(value) || value === 'null' ? null : value, editedData);
                }
            }
            return editedData;
        };
        Edit.prototype.getValue = function (col, input) {
            var value = input.value;
            var gObj = this.parent;
            var temp = col.edit.read;
            Eif (col.type !== 'checkbox') {
                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));
                }
            }
            else {
                value = input.checked;
            }
            return value;
        };
        Edit.prototype.onActionBegin = function (e) {
            var restrictedRequestTypes = ['filterafteropen', 'filterbeforeopen', 'filterchoicerequest', 'save'];
            if (this.parent.editSettings.mode !== 'Batch' && this.formObj && !this.formObj.isDestroyed
                && restrictedRequestTypes.indexOf(e.requestType) === -1) {
                this.destroyWidgets();
                this.destroyForm();
            }
        };
        Edit.prototype.destroyWidgets = function (cols) {
            var gObj = this.parent;
            if (gObj.editSettings.template) {
                this.parent.destroyTemplate(['editSettingsTemplate']);
            }
            if (gObj.columnModel.some(function (column) { return !ej2_base_4.isNullOrUndefined(column.editTemplate); })) {
                this.parent.destroyTemplate(['editTemplate']);
            }
            cols = cols ? cols : this.parent.getColumns();
            for (var _i = 0, cols_1 = cols; _i < cols_1.length; _i++) {
                var col = cols_1[_i];
                var temp = col.edit.destroy;
                if (col.edit.destroy) {
                    Iif (typeof temp === 'string') {
                        temp = ej2_base_2.getValue(temp, window);
                        temp();
                    }
                    else {
                        col.edit.destroy();
                    }
                }
            }
            [].slice.call(this.formObj.element.elements).forEach(function (element) {
                if (element.hasAttribute('name')) {
                    Iif (element.ej2_instances &&
                        element.ej2_instances.length &&
                        !element.ej2_instances[0].isDestroyed) {
                        element.ej2_instances[0].destroy();
                    }
                }
            });
        };
        Edit.prototype.destroyForm = function () {
            this.destroyToolTip();
            if (this.formObj && !this.formObj.isDestroyed) {
                this.formObj.destroy();
            }
            this.destroyToolTip();
        };
        Edit.prototype.destroy = function () {
            this.destroyForm();
            this.removeEventListener();
            var elem = this.dialogObj.element;
            this.dialogObj.destroy();
            ej2_base_3.remove(elem);
            elem = this.alertDObj.element;
            this.alertDObj.destroy();
            ej2_base_3.remove(elem);
            this.unwireEvents();
            Eif (this.editModule) {
                this.editModule.destroy();
            }
        };
        Edit.prototype.keyPressHandler = function (e) {
            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')) {
                        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, 'e-gridcontent') || (this.parent.frozenRows
                            && util_1.parentsUntil(e.target, 'e-headercontent')))
                        && !document.querySelectorAll('.e-popup-open').length) {
                        e.preventDefault();
                        this.endEdit();
                    }
                    break;
                case 'escape':
                    this.closeEdit();
                    break;
            }
        };
        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) {
            var gObj = this.parent;
            var frzCols = gObj.getFrozenColumns();
            var form = gObj.element.querySelector('.e-gridform');
            var mForm = gObj.element.querySelectorAll('.e-gridform')[1];
            var rules = {};
            var mRules = {};
            cols = cols ? cols : gObj.columns;
            cols.forEach(function (col, index) {
                if (!col.visible) {
                    return;
                }
                if (index < frzCols && col.validationRules) {
                    rules[util_1.getComplexFieldID(col.field)] = col.validationRules;
                }
                else if (index >= frzCols && col.validationRules) {
                    mRules[util_1.getComplexFieldID(col.field)] = col.validationRules;
                }
            });
            if (frzCols && this.parent.editSettings.mode !== 'Dialog') {
                this.parent.editModule.mFormObj = this.createFormObj(mForm, mRules);
            }
            else {
                rules = ej2_base_2.extend(rules, mRules);
            }
            this.parent.editModule.formObj = this.createFormObj(form, rules);
        };
        Edit.prototype.createFormObj = function (form, rules) {
            var _this = this;
            return new ej2_inputs_1.FormValidator(form, {
                rules: rules,
                validationComplete: function (args) {
                    _this.validationComplete(args);
                },
                customPlacement: function (inputElement, error) {
                    _this.valErrorPlacement(inputElement, error);
                }
            });
        };
        Edit.prototype.valErrorPlacement = function (inputElement, error) {
            Eif (this.parent.isEdit) {
                var id = error.getAttribute('for');
                var elem = this.getElemTable(inputElement).querySelector('#' + id + '_Error');
                Eif (!elem) {
                    this.createTooltip(inputElement, error, id, '');
                }
                else {
                    elem.querySelector('.e-tip-content').innerHTML = error.innerHTML;
                }
            }
        };
        Edit.prototype.getElemTable = function (inputElement) {
            var isFHdr;
            if (this.parent.editSettings.mode !== 'Dialog') {
                isFHdr = (this.parent.frozenRows && this.parent.frozenRows
                    > (parseInt(ej2_base_1.closest(inputElement, '.e-row').getAttribute('aria-rowindex'), 10) || 0));
            }
            return this.parent.editSettings.mode !== 'Dialog' ? isFHdr ? this.parent.getHeaderTable() : this.parent.getContentTable() :
                this.parent.element.querySelector('#' + this.parent.element.id + '_dialogEdit_wrapper');
        };
        Edit.prototype.validationComplete = function (args) {
            Eif (this.parent.isEdit) {
                var elem = this.getElemTable(args.element).querySelector('#' + args.inputName + '_Error');
                if (elem) {
                    if (args.status === 'failure') {
                        elem.style.display = '';
                    }
                    else {
                        elem.style.display = 'none';
                    }
                }
            }
        };
        Edit.prototype.createTooltip = function (element, error, name, display) {
            var gcontent = this.parent.getContent().firstElementChild;
            var isScroll = gcontent.scrollHeight > gcontent.clientHeight;
            var isInline = this.parent.editSettings.mode !== 'Dialog';
            var isFHdr;
            if (isInline) {
                isFHdr = (this.parent.frozenRows && this.parent.frozenRows
                    > (parseInt(ej2_base_1.closest(element, '.e-row').getAttribute('aria-rowindex'), 10) || 0));
            }
            var fCont = this.parent.getContent().querySelector('.e-frozencontent');
            var table = isInline ?
                (isFHdr ? this.parent.getHeaderTable() : this.parent.getContentTable()) :
                this.parent.element.querySelector('#' + this.parent.element.id + '_dialogEdit_wrapper').querySelector('.e-dlg-content');
            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 = ej2_base_3.createElement('div', {
                className: 'e-tooltip-wrap e-control e-popup e-griderror',
                id: name + '_Error',
                styles: 'display:' + display + ';top:' +
                    ((isFHdr ? inputClient.top + inputClient.height : inputClient.bottom - client.top
                        - (this.parent.getFrozenColumns() ? fCont.scrollTop : 0)) + table.scrollTop + 9) + 'px;left:' +
                    (inputClient.left - left + table.scrollLeft + inputClient.width / 2) + 'px;' +
                    'max-width:' + inputClient.width + 'px;text-align:center;'
            });
            var content = ej2_base_3.createElement('div', { className: 'e-tip-content' });
            content.appendChild(error);
            var arrow = ej2_base_3.createElement('div', { className: 'e-arrow-tip e-tip-top' });
            arrow.appendChild(ej2_base_3.createElement('div', { className: 'e-arrow-tip-outer e-tip-top' }));
            arrow.appendChild(ej2_base_3.createElement('div', { className: 'e-arrow-tip-inner e-tip-top' }));
            div.appendChild(content);
            div.appendChild(arrow);
            table.appendChild(div);
            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;
            }
            div.style.left = (parseInt(div.style.left, 10) - div.offsetWidth / 2) + 'px';
            if (!isScroll && isInline && !this.parent.allowPaging) {
                gcontent.style.position = 'static';
                var pos = ej2_popups_2.calculateRelativeBasedPosition(input, div);
                div.style.top = pos.top + inputClient.height + 9 + 'px';
            }
        };
        return Edit;
    }());
    exports.Edit = Edit;
    var Global;
    (function (Global) {
        Global.timer = null;
    })(Global = exports.Global || (exports.Global = {}));
});