all files / treegrid/actions/ toolbar.js

100% Statements 79/79
93.44% Branches 57/61
100% Functions 11/11
100% Lines 79/79
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   298× 298× 298×   11279×   298× 298× 298×   292× 291×     924× 924× 924× 924× 924× 924× 924× 924× 924× 924× 924× 924×   924× 924× 81× 81× 81×   72× 43× 43× 43× 23×     20×   43× 18×   43×   43× 41×       81× 31× 31×   31× 31×           390× 390× 390×   23× 23×   390×   390×   390×     390×       57×     292×        
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;
});