all files / grid/actions/ command-column.js

98.25% Statements 56/57
90.48% Branches 19/21
100% Functions 10/10
98.25% Lines 56/57
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       15× 15× 15× 15×                   7966×                        
define(["require", "exports", "@syncfusion/ej2-base", "../base/constant", "../base/enum", "../renderer/command-column-renderer"], function (require, exports, ej2_base_1, constant_1, enum_1, command_column_renderer_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CommandColumn = (function () {
        function CommandColumn(parent, locator) {
            this.parent = parent;
            this.locator = locator;
            this.addEventListener();
        }
        CommandColumn.prototype.initiateRender = function () {
            var cellFac = this.locator.getService('cellRendererFactory');
            cellFac.addCellRenderer(enum_1.CellType.CommandColumn, new command_column_renderer_1.CommandColumnRenderer(this.parent, this.locator));
        };
        CommandColumn.prototype.commandClickHandler = function (e) {
            var gObj = this.parent;
            var gID = gObj.element.id;
            var target = ej2_base_1.closest(e.target, 'button');
            if (!target || !gObj.editModule || !ej2_base_1.closest(e.target, '.e-unboundcell')) {
                return;
            }
            var buttonObj = target.ej2_instances[0];
            var type = buttonObj.commandType;
            Iif (buttonObj.disabled) {
                return;
            }
            switch (type) {
                case 'Edit':
                    gObj.editModule.endEdit();
                    gObj.editModule.startEdit(ej2_base_1.closest(target, 'tr'));
                    break;
                case 'Cancel':
                    gObj.editModule.closeEdit();
                    break;
                case 'Save':
                    gObj.editModule.endEdit();
                    break;
                case 'Delete':
                    gObj.editModule.endEdit();
                    gObj.clearSelection();
                    gObj.selectRow(parseInt(ej2_base_1.closest(target, 'tr').getAttribute('aria-rowindex'), 10), false);
                    gObj.editModule.deleteRecord();
                    break;
            }
        };
        CommandColumn.prototype.getModuleName = function () {
            return 'commandColumn';
        };
        CommandColumn.prototype.destroy = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.removeEventListener();
        };
        CommandColumn.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(constant_1.click, this.commandClickHandler);
            this.parent.off(constant_1.initialEnd, this.initiateRender);
            this.parent.off(constant_1.keyPressed, this.keyPressHandler);
        };
        CommandColumn.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(constant_1.click, this.commandClickHandler, this);
            this.parent.on(constant_1.initialEnd, this.initiateRender, this);
            this.parent.on(constant_1.keyPressed, this.keyPressHandler, this);
        };
        CommandColumn.prototype.keyPressHandler = function (e) {
            Eif (e.action === 'enter' && ej2_base_1.closest(e.target, '.e-unboundcelldiv')) {
                this.commandClickHandler(e);
                e.preventDefault();
            }
        };
        return CommandColumn;
    }());
    exports.CommandColumn = CommandColumn;
});