var FormRulesSettings=(function(){var ConditionEvaluators=[]; var InputTypeParsers=[]; var RuleValueParsers=[]; var FieldSelectors=[]; var ActionExecutors=[]; function ConditionEvaluator(name,conditionEvaluator){this.name=name; this.conditionEvaluator=conditionEvaluator; }ConditionEvaluator.prototype.canProcess=function(name){return name===this.name; }; ConditionEvaluator.prototype.process=function(currentValue,ruleValue,inputType){if(!InputTypeParsers||InputTypeParsers.length===0){return false; }var inputTypeParser; for(var inputValueIndex=0; inputValueIndex-1){throw"Container with attribute [data-sf-role='"+fieldContainerDataSfRole+"'] have been registered already."; }else{FieldSelectors.push(new FieldSelector(fieldContainerDataSfRole,elementSelector,additionalFilter)); }},removeFieldSelector:function(fieldContainerDataSfRole){for(var i=0; i-1; }); FormRulesSettings.addConditionEvaluator("NotContains",function(currentValue,ruleValue){return currentValue.search(new RegExp(ruleValue,"i"))===-1; }); var isFilledFunction=function(currentValue){if(typeof currentValue==="number"&¤tValue!==currentValue){return false; }return currentValue&¤tValue.toString().length>0; }; FormRulesSettings.addConditionEvaluator("IsFilled",isFilledFunction); FormRulesSettings.addConditionEvaluator("IsNotFilled",function(currentValue){return !isFilledFunction(currentValue); }); FormRulesSettings.addConditionEvaluator("FileSelected",function(currentValue){return currentValue&¤tValue.length>0; }); FormRulesSettings.addConditionEvaluator("FileNotSelected",function(currentValue){return !currentValue||currentValue.length===0; }); FormRulesSettings.addConditionEvaluator("IsGreaterThan",function(currentValue,ruleValue){return currentValue>ruleValue; }); FormRulesSettings.addConditionEvaluator("IsLessThan",function(currentValue,ruleValue){return currentValue0?separator:this.formContainer; this.pages=$(this.formContainer).find(this.separatorSelector); this._initializeFormRules(); this.iterationsMaxCount=50; var that=this; this.formContainer.on("form-page-changed",function(e,nextIndex,previousIndex){that._updateSkipPages(previousIndex,nextIndex); }); },process:function(){if(!this._hasRules()){return; }this.hiddenFields=this._getHiddenFields(); this.skipFields=this._getSkipFields(); var context=this._contextInitialization(); var updatedContext=this._evaluateFormRules(context); this._applyActionsState(updatedContext); this.hiddenFields=updatedContext.hiddenFields; this._setHiddenFields(this.hiddenFields); this._setExecutedActions(updatedContext.activeActions); },_hasRules:function(){return this.formRules&&this.formRules.length!==0; },_evaluateFormRules:function(context){var currentFieldsVisibility=$.map(context.fields,function(field){return field.Visible; }); var updatedContext=this._updateContext(context); var updatedFieldsVisibility=$.map(updatedContext.fields,function(field){return field.Visible; }); var noChanges=this._compareArrays(currentFieldsVisibility,updatedFieldsVisibility); if(context.iterationsCounter>this.iterationsMaxCount||noChanges){return updatedContext; }context.iterationsCounter++; return this._evaluateFormRules(updatedContext); },_updateContext:function(context){var actions=this._getRulesActionsState(context); for(var i=0; i-1){action.executor.undoUpdateState(context,action.data); context.activeActions.splice(activeActionIndex,1); }}}return context; },_getRulesActionsState:function(context){var actions=[]; var that=this; var addOrUpdateAction=function(actions,currentAction,applyRule){var actionIndex=that._actionItemIndexOf(actions,currentAction.data); if(actionIndex===-1){if(applyRule){for(var actionIndex=0; actionIndex0){for(var h=0; h0&&formRulesElement.val().length>0?JSON.parse(formRulesElement.val()):null; if(deserializedFormRules){for(var ruleIndex=0; ruleIndexrulePageIndex?conditionTargetPageIndex:rulePageIndex; }for(var actionIndex=0; actionIndex=0; i--){if(filteredActions.filter(function(a){return ruleActions[i].executor.isConflict(ruleActions[i].data,a.data); }).length===0){filteredActions.push(ruleActions[i]); }}return filteredActions.reverse(); },_contextInitialization:function(){var executedActions=this._getExecutedActions(); return{fields:this._fieldsInitialization(),executedActions:executedActions.slice(),activeActions:executedActions.slice(),formContainer:this.formContainer,formContainerSelector:this.formContainerSelector,iterationsCounter:0,hiddenFields:this.hiddenFields,skipToPageCollection:[],helper:{showField:this._showField.bind(this),hideField:this._hideField.bind(this),getFieldElement:this._getFieldElement.bind(this),getFieldStartSelector:this._getFieldStartSelector.bind(this),getFieldEndSelector:this._getFieldEndSelector.bind(this),fieldIndexOf:this._fieldIndexOf.bind(this),arrayIndexOf:this._arrayIndexOf.bind(this),actionItemIndexOf:this._actionItemIndexOf.bind(this)}}; },_fieldsInitialization:function(){var fields=[]; var formRuleFields=this._getFormRulesFields(); for(var i=0; i0){for(var k=0; k=0; fieldIndex--){var fieldPageIndex=this._getFieldPageContainerIndex(this.skipFields[fieldIndex]); if(nextIndex-1){this.skipFields.splice(index,1); var fieldElement=this._getFieldElement(fieldControlId); fieldElement.removeAttr("disabled"); }},_actionItemIndexOf:function(actions,actionData){for(var i=0; i0){var fieldAllElements=$(scriptWrapper).nextUntil(this._getFieldEndSelector(fieldControlId)); var fieldContainerNames=FormRulesSettings.getFieldsContainerNames(); if(fieldContainerNames&&fieldContainerNames.length>0){for(var i=0; i0){return FormRulesSettings.getFieldValueElements(fieldContainer); }}}}return $(); },_showField:function(context,fieldControlId){var invalidTags=["script"]; var index=this._arrayIndexOf(context.hiddenFields,fieldControlId); if(index>-1){context.hiddenFields.splice(index,1); var scriptWrapper=$(context.formContainer).find(this._getFieldStartSelector(fieldControlId)); if(scriptWrapper&&scriptWrapper.length>0){var fieldElement=this._getFieldElement(fieldControlId); if(fieldElement&&fieldElement.length>0){fieldElement.removeAttr("disabled"); }$(scriptWrapper).nextUntil(this._getFieldEndSelector(fieldControlId)).each(function(i,element){if(invalidTags.indexOf(element.tagName.toLowerCase())<0){$(element).show(); }}); }}},_hideField:function(context,fieldControlId){var index=this._arrayIndexOf(context.hiddenFields,fieldControlId); if(index===-1){context.hiddenFields.push(fieldControlId); var scriptWrapper=$(context.formContainer).find(this._getFieldStartSelector(fieldControlId)); if(scriptWrapper&&scriptWrapper.length>0){var fieldElement=this._getFieldElement(fieldControlId); if(fieldElement&&fieldElement.length>0){fieldElement.attr("disabled","disabled"); }$(scriptWrapper).nextUntil(this._getFieldEndSelector(fieldControlId)).each(function(i,element){$(element).hide(); }); }}},_getFieldType:function(fieldControlId){var fieldElement=this._getFieldElement(fieldControlId); var fieldType=fieldElement.data("sf-input-type"); if(!fieldType){fieldType=this._getFieldElement(fieldControlId).attr("type"); }return fieldType; },_getFieldValues:function(fieldControlId){var fieldContainer=this._getFieldContainer(fieldControlId); return FormRulesSettings.getFieldValues(fieldContainer); },_getFieldContainer:function(fieldControlId){return this._getFieldElement(fieldControlId).closest(this.fieldContainerSelector); },_getFieldPageContainer:function(fieldControlId){var element=this._getFieldElement(fieldControlId); var separator=element.closest(this.separatorSelector); return separator.length>0?separator:element.closest(this.formContainerSelector); },_getFieldPageContainerIndex:function(fieldControlId){var fieldPageContainer=this._getFieldPageContainer(fieldControlId); return this.pages.index(fieldPageContainer); },_fieldIndexOf:function(fields,fieldControlId){for(var i=0; i0){var formRulesExecutor=null; var cachedFormRulesExecutorObject=formRuleExecutorsCache.filter(function(e){return e.formContainer===formContainer[0]; })[0]; if(resetElementCache!==true&&cachedFormRulesExecutorObject){formRulesExecutor=cachedFormRulesExecutorObject.formRulesExecutor; }else{formRulesExecutor=new FormRulesExecutor($(this)); if(resetElementCache===true){formRuleExecutorsCache=formRuleExecutorsCache.filter(function(e){return e.formContainer!==cachedFormRulesExecutorObject.formContainer; }); }formRuleExecutorsCache.push({formContainer:formContainer[0],formRulesExecutor:formRulesExecutor}); }formRulesExecutor.process(); }}}); $(document).ready(function(){setTimeout(function(){var formContainerSelector=getFormContainerSelector(); var formContainers=$(formContainerSelector); formContainers.each(function(i,element){if(typeof $.fn.processFormRules==="function"){$(element).processFormRules(true); }}); }); }); function getFormContainerSelector(){var selector='[data-sf-role="form-container"]'; if($(selector).length>0){return selector; }return"#PublicWrapper"; }}(jQuery));