define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-base"], function (require, exports, ej2_grids_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ContextMenu = (function () {
function ContextMenu(parent) {
ej2_grids_1.Grid.Inject(ej2_grids_1.ContextMenu);
this.parent = parent;
this.addEventListener();
}
ContextMenu.prototype.addEventListener = function () {
this.parent.on('contextMenuOpen', this.contextMenuOpen, this);
this.parent.on('contextMenuClick', this.contextMenuClick, this);
};
ContextMenu.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off('contextMenuOpen', this.contextMenuOpen);
this.parent.off('contextMenuClick', this.contextMenuClick);
};
ContextMenu.prototype.contextMenuOpen = function (args) {
var addRow = ej2_base_1.select('#' + this.parent.element.id + '_gridcontrol_cmenu_AddRow', args.element);
var editRecord = ej2_base_1.select('#' + this.parent.element.id + '_gridcontrol_cmenu_Edit', args.element);
var indent = ej2_base_1.select('#' + this.parent.element.id + '_gridcontrol_cmenu_Indent', args.element);
var outdent = ej2_base_1.select('#' + this.parent.element.id + '_gridcontrol_cmenu_Outdent', args.element);
if (addRow) {
if (this.parent.grid.editSettings.allowAdding === false || this.parent.grid.isEdit) {
addRow.style.display = 'none';
}
else {
addRow.style.display = 'block';
}
}
if ((this.parent.editSettings.mode === 'Cell' || this.parent.editSettings.mode === 'Batch')
&& !(ej2_base_1.isNullOrUndefined(editRecord)) && !(editRecord.classList.contains('e-menu-hide'))) {
editRecord.style.display = 'none';
}
var tObj = this.parent;
var selectedrow = tObj.getSelectedRows()[0];
if ((indent || outdent) && !ej2_base_1.isNullOrUndefined(selectedrow)) {
var targetElement = args.event.target.closest('td');
if (ej2_base_1.isNullOrUndefined(targetElement) || (!ej2_base_1.isNullOrUndefined(targetElement) && (!targetElement.classList.contains('e-rowcell') ||
targetElement.querySelectorAll('.e-gridform').length !== 0))) {
for (var _i = 0, _a = args.items; _i < _a.length; _i++) {
var items = _a[_i];
if (items.text === 'Outdent' || items.text === 'Indent') {
tObj.grid.contextMenuModule['hiddenItems'].push(items.text);
}
}
tObj.grid.contextMenuModule.contextMenu.hideItems(tObj.grid.contextMenuModule['hiddenItems']);
indent.style.display = outdent.style.display = 'none';
}
else {
if (selectedrow.rowIndex === 0 || tObj.getSelectedRowIndexes().length > 1) {
indent.style.display = outdent.style.display = 'none';
}
else Eif (args['name'] !== 'rowDeselected' || (!ej2_base_1.isNullOrUndefined(selectedrow) && tObj.grid.isCheckBoxSelection)) {
var selectedItem = tObj.getCurrentViewRecords()[selectedrow.rowIndex];
Eif (!ej2_base_1.isNullOrUndefined(selectedItem)) {
if ((selectedItem.level > tObj.getCurrentViewRecords()[selectedrow.rowIndex - 1].level)) {
indent.style.display = 'none';
}
else {
indent.style.display = 'block';
}
Iif ((selectedItem.level === tObj.getCurrentViewRecords()[selectedrow.rowIndex - 1].level)) {
indent.style.display = 'block';
}
if ((selectedItem.level === 0)) {
outdent.style.display = 'none';
}
else {
outdent.style.display = 'block';
}
}
}
}
}
else {
if (((indent || outdent) || tObj.grid.isEdit) && ej2_base_1.isNullOrUndefined(selectedrow)) {
for (var _b = 0, _c = args.items; _b < _c.length; _b++) {
var items = _c[_b];
if (items.text === 'Outdent' || items.text === 'Indent') {
tObj.grid.contextMenuModule['hiddenItems'].push(items.text);
}
}
tObj.grid.contextMenuModule.contextMenu.hideItems(tObj.grid.contextMenuModule['hiddenItems']);
indent.style.display = outdent.style.display = 'none';
}
}
};
ContextMenu.prototype.contextMenuClick = function (args) {
if (args.item.id === 'Above' || args.item.id === 'Below' || args.item.id === 'Child') {
this.parent.notify('savePreviousRowPosition', args);
this.parent.setProperties({ editSettings: { newRowPosition: args.item.id } }, true);
this.parent.editModule['isAddedRowByContextMenu'] = true;
this.parent.addRecord();
}
if (args.item.id === this.parent.element.id + '_gridcontrol_cmenu_Indent' || args.item.id === this.parent.element.id + '_gridcontrol_cmenu_Outdent') {
Eif (!ej2_base_1.isNullOrUndefined(this.parent.rowDragAndDropModule)) {
var indentOutdentAction = 'indentOutdentAction';
var action = args.item.id === this.parent.element.id + '_gridcontrol_cmenu_Indent' ? 'indent' : 'outdent';
this.parent.rowDragAndDropModule["" + indentOutdentAction](null, action);
}
}
};
ContextMenu.prototype.getModuleName = function () {
return 'contextMenu';
};
ContextMenu.prototype.destroy = function () {
this.removeEventListener();
};
ContextMenu.prototype.getContextMenu = function () {
return this.parent.grid.contextMenuModule.getContextMenu();
};
return ContextMenu;
}());
exports.ContextMenu = ContextMenu;
});
|