define(["require", "exports", "@syncfusion/ej2-grids", "../base/constant", "@syncfusion/ej2-base"], function (require, exports, ej2_grids_1, events, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Toolbar = (function () {
function Toolbar(parent) {
ej2_grids_1.Grid.Inject(ej2_grids_1.Toolbar);
this.parent = parent;
this.addEventListener();
}
Toolbar.prototype.getModuleName = function () {
return 'toolbar';
};
Toolbar.prototype.addEventListener = function () {
this.parent.on(events.rowSelected, this.refreshToolbar, this);
this.parent.on(events.rowDeselected, this.refreshToolbar, this);
this.parent.on(events.toolbarClick, this.toolbarClickHandler, this);
};
Toolbar.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off(events.rowSelected, this.refreshToolbar);
this.parent.off(events.rowDeselected, this.refreshToolbar);
this.parent.off(events.toolbarClick, this.toolbarClickHandler);
};
Toolbar.prototype.refreshToolbar = function (args) {
var toolbarElement = this.parent.grid.toolbarModule.getToolbar();
Eif (!ej2_base_1.isNullOrUndefined(toolbarElement)) {
var tObj = this.parent;
var indentElement = void 0;
var outdentElement = void 0;
var indentID = tObj.element.id + '_gridcontrol_indent';
var outdentID = tObj.element.id + '_gridcontrol_outdent';
var indentEle = toolbarElement.querySelector('#' + indentID);
var outdentEle = toolbarElement.querySelector('#' + outdentID);
var row = args.row;
var selectedrow = tObj.getSelectedRows()[0];
if (!ej2_base_1.isNullOrUndefined(row[0])) {
row = row[0];
}
row = (!ej2_base_1.isNullOrUndefined(selectedrow) && selectedrow.rowIndex !== row.rowIndex) ? selectedrow : row;
if (indentEle !== null && outdentEle !== null) {
indentElement = toolbarElement.querySelector('#' + indentID).parentElement;
outdentElement = toolbarElement.querySelector('#' + outdentID).parentElement;
if (row.rowIndex === 0 || tObj.getSelectedRowIndexes().length > 1) {
indentElement.classList.add('e-hidden');
outdentElement.classList.add('e-hidden');
}
else if (args['name'] !== 'rowDeselected' || (!ej2_base_1.isNullOrUndefined(selectedrow) && tObj.grid.isCheckBoxSelection)) {
var selectedItem = tObj.getCurrentViewRecords()[row.rowIndex];
Eif (!ej2_base_1.isNullOrUndefined(selectedItem)) {
if ((selectedItem.level > tObj.getCurrentViewRecords()[row.rowIndex - 1].level)) {
indentElement.classList.add('e-hidden');
}
else {
indentElement.classList.remove('e-hidden');
}
if (selectedItem.level === tObj.getCurrentViewRecords()[row.rowIndex - 1].level) {
indentElement.classList.remove('e-hidden');
}
if (selectedItem.level === 0) {
outdentElement.classList.add('e-hidden');
}
if (selectedItem.level !== 0) {
outdentElement.classList.remove('e-hidden');
}
}
}
if (args['name'] === 'rowDeselected' && ej2_base_1.isNullOrUndefined(selectedrow) && !tObj.grid.isCheckBoxSelection) {
Eif (this.parent.toolbar['includes']('Indent')) {
indentElement.classList.add('e-hidden');
}
Eif (this.parent.toolbar['includes']('Outdent')) {
outdentElement.classList.add('e-hidden');
}
}
}
}
};
Toolbar.prototype.toolbarClickHandler = function (args) {
var tObj = this.parent;
var indentOutdentAction = 'indentOutdentAction';
if (this.parent.editSettings.mode === 'Cell' && this.parent.grid.editSettings.mode === 'Batch' &&
args.item.id === this.parent.grid.element.id + '_update') {
args.cancel = true;
this.parent.grid.editModule.saveCell();
}
if (args.item.id === this.parent.grid.element.id + '_expandall') {
this.parent.expandAll();
}
if (args.item.id === this.parent.grid.element.id + '_collapseall') {
this.parent.collapseAll();
}
if (args.item.id === tObj.grid.element.id + '_indent' && tObj.getSelectedRecords().length
&& !ej2_base_1.isNullOrUndefined(tObj.rowDragAndDropModule)) {
this.parent.rowDragAndDropModule["" + indentOutdentAction](null, 'indent');
}
if (args.item.id === tObj.grid.element.id + '_outdent' && tObj.getSelectedRecords().length
&& !ej2_base_1.isNullOrUndefined(tObj.rowDragAndDropModule)) {
this.parent.rowDragAndDropModule["" + indentOutdentAction](null, 'outdent');
}
};
Toolbar.prototype.getToolbar = function () {
return this.parent.grid.toolbarModule.getToolbar();
};
Toolbar.prototype.enableItems = function (items, isEnable) {
this.parent.grid.toolbarModule.enableItems(items, isEnable);
};
Toolbar.prototype.destroy = function () {
this.removeEventListener();
};
return Toolbar;
}());
exports.Toolbar = Toolbar;
});
|