/**
* Created by george.calcea on 12/27/2016.
*/
/**
* Class that handles the condition tree (condition type, operator, value)
* @param {Definitions} fieldDefinitions
* @param {Object} ruleData
* @param {callable} changeCallback
* @constructor
*/
var Condition = function (fieldDefinitions, ruleData) {
this.fieldDefinitions = fieldDefinitions;
this.ruleData = ruleData;
this.id = guid();
this.init();
};
/**
* Init internal parameters
*/
Condition.prototype.init = function () {
var descriptionIcon = $("");
this.wrapper = $('
', {class: 'condition-wrapper row'});
this.parameterSelectWrapper = $('
', {class: 'condition-select-wrapper col-sm-3'});
this.wrapper.append(this.parameterSelectWrapper);
this.wrapper.append(descriptionIcon);
this.operatorSelectWrapper = $('
', {class: 'condition-operators-wrapper col-sm-3'});
this.wrapper.append(this.operatorSelectWrapper);
this.valueFieldWrapper = $('
', {class: 'condition-values-wrapper col-sm-3'});
this.wrapper.append(this.valueFieldWrapper);
this.help = descriptionIcon;
if ($.isEmptyObject(this.ruleData)) {
this.selectedCondition = this.fieldDefinitions.getFirstConditionDefinition();
this.selectedOperator = this.selectedCondition.getFirstOperatorDefinition();
} else {
this.selectedCondition = this.fieldDefinitions.getParameterDefinition(this.ruleData.name);
this.selectedOperator = this.selectedCondition.getOperatorDefinition(this.ruleData.operator);
}
this.help.attr("title",this.selectedCondition.getDescription());
this.help.tooltip();
this.generateFieldObject();
};
/**
* Returns the HTML for current condition manager
* @param {jQuery} parentWrapper
*/
Condition.prototype.appendHtml = function (parentWrapper) {
parentWrapper.append(this.wrapper);
this.wrapper.prepend(this.getRemoveButtonHtml());
this.appendConditionsSelect(this.parameterSelectWrapper.empty());
this.appendOperatorsSelect(this.operatorSelectWrapper.empty());
this.field.appendHtml(this.valueFieldWrapper.empty());
};
/**
* Returns an Jquery object for conditions select
* @param {jQuery} wrapper
*/
Condition.prototype.appendConditionsSelect = function (wrapper) {
var select = $('