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;
});
|