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;
});
|