Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/3.3 cdv edit #96

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
hanuman (3.2.2)
hanuman (3.3)
active_model_serializers (~> 0.8.1)
acts-as-taggable-on (~> 4.0.0)
amoeba (~> 3.1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class @ConditionalLogic
self.boundElements = []

#scan page and find all objects with conditional logic rules
findRules: (runCalcs, runConditionals, $context) ->
findRules: (runCalcs, runLookups, $context) ->
self.allowCascade = false
problemWithCL = false
$context.find("[data-rule!=''][data-rule]").each ->
Expand Down Expand Up @@ -69,8 +69,7 @@ class @ConditionalLogic
inRepeater = true

if rule.type != "Hanuman::CalculationRule"
if runConditionals
self.checkConditionsAndHideShow(rule.conditions, ancestorId, $ruleContainer, $ruleContainer, inRepeater, matchType, rule, true)
self.checkConditionsAndHideShow(rule.conditions, ancestorId, $ruleContainer, $ruleContainer, inRepeater, matchType, rule, runLookups)

if runCalcs && rule.type == "Hanuman::CalculationRule"
self.updateCalculation(rule, $ruleContainer)
Expand Down Expand Up @@ -125,7 +124,7 @@ class @ConditionalLogic
matchingCondition = _.where(conditions, {question_id: Number(questionId)})
if matchingCondition.length > 0
if conditions.length > 1
self.checkConditionsAndHideShow(conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, this, false)
self.checkConditionsAndHideShow(conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, this, true)
else
hideQuestions = self.setHideQuestions(conditions[0], $triggerElement)
if this.type == "Hanuman::VisibilityRule"
Expand All @@ -147,7 +146,7 @@ class @ConditionalLogic
matchingCondition = _.where(conditions, {question_id: Number(questionId)})
if matchingCondition.length > 0
if conditions.length > 1
self.checkConditionsAndHideShow(conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, this, false)
self.checkConditionsAndHideShow(conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, this, true)
else
hideQuestions = self.setHideQuestions(conditions[0], $triggerElement)
if this.type == "Hanuman::VisibilityRule"
Expand All @@ -156,7 +155,7 @@ class @ConditionalLogic
self.setLookupValue(this.value, $ruleElement)
return

checkConditionsAndHideShow: (conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, rule, onLoad) ->
checkConditionsAndHideShow: (conditions, ancestorId, $ruleElement, $container, inRepeater, matchType, rule, runLookups) ->
conditionMetTracker = []
$.each conditions, (index, condition) ->
if inRepeater
Expand Down Expand Up @@ -193,7 +192,7 @@ class @ConditionalLogic

if rule.type == "Hanuman::VisibilityRule"
self.hideShowQuestions(hideShow, ancestorId, $ruleElement, $container, inRepeater)
else if hideShow == false && rule.type == "Hanuman::LookupRule"
else if hideShow == false && rule.type == "Hanuman::LookupRule" && runLookups == true
self.setLookupValue(rule.value, $ruleElement)

setLookupValue: (value, $ruleElement) ->
Expand Down Expand Up @@ -674,5 +673,7 @@ $ ->
$context = $('.form-container-survey')
if $('input#run_cl').length
#call findRules on document ready
# if edit, don't run lookup rules, if new do run lookup rules
cl = new ConditionalLogic
cl.findRules(false, true, $context)
isNewSurvey = $('form').attr('id') is 'new_survey'
cl.findRules(false, isNewSurvey, $context)
9 changes: 6 additions & 3 deletions app/assets/javascripts/hanuman/hanuman-repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ $(document).ready(function(){

// bind ConditionalLogic and re-run the logic to hide and show
$context = $('.form-container-survey')
// $context = $clonedContainer
$contextForConditionals = $clonedContainer
cl = new ConditionalLogic;
cl.findRules(false, true, $context);
// bind CL on all context
cl.findRules(false, false, $context);
// run CDV only on new repeater context
cl.findRules(false, true, $contextForConditionals);

// bind wetland calcs
// window.initializeCoverFields();
Expand Down Expand Up @@ -434,7 +437,7 @@ $(document).ready(function(){
updateRepeaterControls();
$context = $('.form-container-survey')
cl = new ConditionalLogic;
cl.findRules(true, true, $context);
cl.findRules(true, false, $context);
// re-run wetland calcs
window.runAllWetlandCalcs();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hanuman/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hanuman
VERSION = "3.2.2"
VERSION = "3.3"
end