all files / common/actions/ node-state-modified.js

77.78% Statements 49/63
60.2% Branches 59/98
100% Functions 5/5
77.78% Lines 49/63
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   219×   35× 35× 35× 35× 35× 35× 32×       35× 35×     35×   34×                                                               34× 28× 28×     28×                         28×     27×         33× 33×   27× 27× 27×       27×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/css-constant"], function (require, exports, ej2_base_1, cls) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var NodeStateModified = (function () {
        function NodeStateModified(parent) {
            this.parent = parent;
        }
        NodeStateModified.prototype.onStateModified = function (args, fieldName) {
            var droppedClass = '';
            var nodeDropped = true;
            var target = ej2_base_1.closest(args.target, '.' + cls.DROPPABLE_CLASS);
            var droppedPosition = -1;
            this.parent.dataSourceUpdate.btnElement = args.element ? args.element.parentElement : undefined;
            if (target) {
                droppedClass = target.classList[1] === cls.ROW_AXIS_CLASS ?
                    'rows' : target.classList[1] === cls.COLUMN_AXIS_CLASS ? 'columns' : target.classList[1] === cls.VALUE_AXIS_CLASS ?
                    'values' : target.classList[1] === cls.FILTER_AXIS_CLASS ? 'filters' : '';
            }
            Eif (this.parent.dataType === 'olap' || this.parent.dataType === 'pivot') {
                var actualFieldName = (this.parent.dataType === 'olap' && this.parent.engineModule.fieldList[fieldName] &&
                    this.parent.engineModule.fieldList[fieldName].isCalculatedField ?
                    this.parent.engineModule.fieldList[fieldName].tag : fieldName);
                if (args.cancel && droppedClass === '') {
                    nodeDropped = false;
                    return nodeDropped;
                }
                else Iif ((this.parent.dataSourceUpdate.btnElement &&
                    (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'true' &&
                        (droppedClass === 'filters' || droppedClass === 'values'))) ||
                    (this.parent.dataSourceUpdate.btnElement &&
                        (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' &&
                            actualFieldName.toLowerCase().indexOf('[measures].') > -1 && this.parent.dataType === 'olap' &&
                            (droppedClass === 'filters' || droppedClass === 'rows' || droppedClass === 'columns'))) ||
                    (this.parent.dataSourceUpdate.btnElement &&
                        (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' && this.parent.dataType === 'olap' &&
                            actualFieldName.toLowerCase().indexOf('[measures].') === -1 &&
                            this.parent.engineModule.fieldList[fieldName] &&
                            this.parent.engineModule.fieldList[fieldName].isNamedSets &&
                            (droppedClass === 'filters' || droppedClass === 'values'))) ||
                    (this.parent.dataSourceUpdate.btnElement &&
                        (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' && this.parent.dataType === 'olap' &&
                            actualFieldName.toLowerCase().indexOf('[measures].') === -1 && droppedClass === 'values'))) {
                    var title = this.parent.localeObj.getConstant('warning');
                    var description = this.parent.localeObj.getConstant('fieldDropErrorAction');
                    this.parent.errorDialog.createErrorDialog(title, description);
                    nodeDropped = false;
                    return nodeDropped;
                }
            }
            else {
                if ((args.cancel && droppedClass === '') ||
                    (this.parent.dataSourceUpdate.btnElement && this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'true' &&
                        ((droppedClass === 'filters' || droppedClass === 'values') ||
                            droppedClass.indexOf(this.parent.dataSourceSettings.valueAxis) > -1))) {
                    nodeDropped = false;
                    return nodeDropped;
                }
            }
            if (droppedClass !== '') {
                Eif (this.parent.dataType === 'olap' || this.parent.dataType === 'pivot') {
                    var actualFieldName = (this.parent.dataType === 'olap' && this.parent.engineModule.fieldList[fieldName] &&
                        this.parent.engineModule.fieldList[fieldName].isCalculatedField ?
                        this.parent.engineModule.fieldList[fieldName].tag : fieldName);
                    Iif ((actualFieldName.toLowerCase().indexOf('[measures].') > -1 && this.parent.dataType === 'olap' &&
                        (droppedClass === 'filters' || droppedClass === 'rows' || droppedClass === 'columns')) ||
                        (this.parent.engineModule.fieldList[fieldName] &&
                            this.parent.engineModule.fieldList[fieldName].isNamedSets && droppedClass === 'filters') ||
                        (this.parent.dataType === 'olap' && droppedClass === 'values' &&
                            actualFieldName.toLowerCase().indexOf('[measures].') === -1)) {
                        var title = this.parent.localeObj.getConstant('warning');
                        var description = this.parent.localeObj.getConstant('fieldDropErrorAction');
                        this.parent.errorDialog.createErrorDialog(title, description);
                        nodeDropped = false;
                        return nodeDropped;
                    }
                }
                if (this.parent.dataType === 'pivot' && this.parent.engineModule.fieldList[fieldName] &&
                    this.parent.engineModule.fieldList[fieldName].aggregateType === 'CalculatedField' && droppedClass !== 'values') {
                    var title = this.parent.localeObj.getConstant('warning');
                    var description = this.parent.localeObj.getConstant('dropAction');
                    this.parent.errorDialog.createErrorDialog(title, description);
                    nodeDropped = false;
                    return nodeDropped;
                }
                droppedPosition = this.getButtonPosition(args.target, droppedClass);
            }
            else if (this.parent.engineModule.fieldList[fieldName]) {
                this.parent.engineModule.fieldList[fieldName].isSelected = false;
                Iif (this.parent.dataType === 'olap') {
                    this.parent.engineModule.updateFieldlistData(fieldName);
                }
            }
            nodeDropped = this.parent.dataSourceUpdate.updateDataSource(fieldName, droppedClass, droppedPosition);
            return nodeDropped;
        };
        NodeStateModified.prototype.getButtonPosition = function (target, droppedClass) {
            var droppedPosition = -1;
            var targetBtn = ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_WRAPPER_CLASS);
            if (!ej2_base_1.isNullOrUndefined(targetBtn)) {
                targetBtn = targetBtn.querySelector('.' + cls.PIVOT_BUTTON_CLASS);
                var axisPanel = this.parent.element.querySelector('.e-' + droppedClass);
                var pivotButtons = [].slice.call(axisPanel.querySelectorAll('.' + cls.PIVOT_BUTTON_CLASS));
                for (var i = 0, n = pivotButtons.length; i < n; i++) {
                    Eif (pivotButtons[i].id === targetBtn.id) {
                        droppedPosition = i;
                        break;
                    }
                }
            }
            return droppedPosition;
        };
        return NodeStateModified;
    }());
    exports.NodeStateModified = NodeStateModified;
});