all files / treegrid/actions/ context-menu.js

98.68% Statements 75/76
91.3% Branches 63/69
100% Functions 10/10
98.68% Lines 75/76
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 117 118 119 120   19× 19× 19×   19× 19×   20× 19×     22× 22× 22× 22× 22×         22×     22× 22× 22×   40× 40× 10×                                     14× 13× 13×           12×   12×       11279×   20×          
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;
});