all files / common/popups/ context-menu.js

56.36% Statements 31/55
23.53% Branches 8/34
87.5% Functions 7/8
56.36% Lines 31/55
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   144× 144×                                                                                                       144× 144×                            
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/base/css-constant", "@syncfusion/ej2-navigations"], function (require, exports, ej2_base_1, ej2_base_2, cls, ej2_navigations_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PivotContextMenu = (function () {
        function PivotContextMenu(parent) {
            this.parent = parent;
            this.parent.contextMenuModule = this;
        }
        PivotContextMenu.prototype.render = function () {
            this.renderContextMenu();
        };
        PivotContextMenu.prototype.renderContextMenu = function () {
            var menuItems = [
                { text: this.parent.localeObj.getConstant('addToFilter'), id: this.parent.element.id + '_Filters' },
                { text: this.parent.localeObj.getConstant('addToRow'), id: this.parent.element.id + '_Rows' },
                { text: this.parent.localeObj.getConstant('addToColumn'), id: this.parent.element.id + '_Columns' },
                { text: this.parent.localeObj.getConstant('addToValue'), id: this.parent.element.id + '_Values' }
            ];
            var menuOptions = {
                cssClass: cls.PIVOT_CONTEXT_MENU_CLASS + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                items: menuItems,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                beforeOpen: this.onBeforeMenuOpen.bind(this),
                select: this.onSelectContextMenu.bind(this)
            };
            var cMenu = ej2_base_1.createElement('ul', {
                id: this.parent.element.id + '_PivotContextMenu'
            });
            this.parent.element.appendChild(cMenu);
            this.menuObj = new ej2_navigations_1.ContextMenu(menuOptions);
            this.menuObj.isStringTemplate = true;
            this.menuObj.appendTo(cMenu);
        };
        PivotContextMenu.prototype.onBeforeMenuOpen = function (args) {
            var items = [].slice.call(args.element.querySelectorAll('li'));
            var fieldType = this.parent.dataType === 'olap' ? this.fieldElement.getAttribute('data-type') :
                this.fieldElement.querySelector('.' + cls.PIVOT_BUTTON_CONTENT_CLASS).getAttribute('data-type');
            ej2_base_2.removeClass(items, cls.MENU_DISABLE);
            Eif (fieldType === 'CalculatedField' || fieldType === 'isMeasureFieldsAvail') {
                for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
                    var item = items_1[_i];
                    if (item.textContent !== this.parent.localeObj.getConstant('addToValue')) {
                        ej2_base_2.addClass([item], cls.MENU_DISABLE);
                    }
                }
            }
            else if (fieldType === 'isMeasureAvail') {
                for (var _a = 0, items_2 = items; _a < items_2.length; _a++) {
                    var item = items_2[_a];
                    if (item.textContent !== this.parent.localeObj.getConstant('addToRow') &&
                        item.textContent !== this.parent.localeObj.getConstant('addToColumn')) {
                        ej2_base_2.addClass([item], cls.MENU_DISABLE);
                    }
                }
            }
            else if (this.parent.dataType === 'olap') {
                for (var _b = 0, items_3 = items; _b < items_3.length; _b++) {
                    var item = items_3[_b];
                    if (item.textContent === this.parent.localeObj.getConstant('addToValue')) {
                        ej2_base_2.addClass([item], cls.MENU_DISABLE);
                        break;
                    }
                }
            }
        };
        PivotContextMenu.prototype.onSelectContextMenu = function (menu) {
            if (menu.element.textContent !== null) {
                var fieldName = this.fieldElement.getAttribute('data-uid');
                var dropClass = menu.item.id.replace(this.parent.element.id + '_', '').toLowerCase();
                this.parent.pivotCommon.dataSourceUpdate.control = this.parent.getModuleName() === 'pivotview' ? this.parent :
                    (this.parent.pivotGridModule ? this.parent.pivotGridModule : this.parent);
                this.parent.pivotCommon.dataSourceUpdate.btnElement = this.fieldElement;
                this.parent.pivotCommon.dataSourceUpdate.updateDataSource(fieldName, dropClass, -1);
                this.parent.updateDataSource(true);
                this.fieldElement = undefined;
            }
        };
        PivotContextMenu.prototype.destroy = function () {
            Eif (!this.parent.isDestroyed) {
                return;
            }
            if (this.menuObj && !this.menuObj.isDestroyed) {
                this.menuObj.destroy();
                if (ej2_base_1.select('#' + this.parent.element.id + '_PivotContextMenu', document)) {
                    ej2_base_1.remove(ej2_base_1.select('#' + this.parent.element.id + '_PivotContextMenu', document));
                }
            }
            else {
                return;
            }
        };
        return PivotContextMenu;
    }());
    exports.PivotContextMenu = PivotContextMenu;
});