@@ -8,6 +8,12 @@ function determineExemptions(event) {
88 var values = Array . from ( document . querySelectorAll ( `#${ legislationName } input[name='exemption-condition']:checked` ) ) . map ( ( input ) => input . value ) ;
99 var checkedValues = [ ...new Set ( values ) ] ;
1010
11+ // If simple quiz and exempt, go directly to SHARE IT Act Quiz
12+ if ( legislationName === "start" && ( checkedValues . length === 0 || checkedValues [ 0 ] === "exempt" ) ) {
13+ handleClick ( event , true ) ;
14+ return ;
15+ }
16+
1117 const results = determineResults ( checkedValues , legislationName ) ;
1218
1319 // Display results
@@ -19,12 +25,20 @@ function determineExemptions(event) {
1925function determineResults ( checkedValues , legislationName ) {
2026 var text = "" ;
2127
22- // Project is not exempted
23- if ( checkedValues . length === 1 && checkedValues [ 0 ] . includes ( "none" ) ) {
28+ // Project is not exempt - simple quiz
29+ if ( legislationName == "start" ) {
30+ if ( checkedValues [ 0 ] !== "exempt" ) {
31+ text = `<h4>Your project is qualified for sharing and reuse according to the SHARE IT Act and M-16-21.</h4>
32+ <p>We've marked this in the form below for you as: <strong>${ checkedValues [ 0 ] } </strong></p>`
33+ }
34+ }
35+
36+ // Project is not exempt
37+ else if ( ( checkedValues . length === 1 && checkedValues [ 0 ] . includes ( "none" ) ) || checkedValues . length === 0 ) {
2438
2539 if ( legislationName === "share-it-act" ) {
2640 text = `<h4>Your project is: <div class="not-exempt"><strong>NOT EXEMPTED</strong></div></h4>
27- <p>Please complete <strong>Part 2 </strong> to determine additional project exemptions.</p>` ;
41+ <p>Please complete <strong>Part 1c </strong> to determine additional project exemptions.</p>` ;
2842 }
2943 else {
3044 text = `<h4>Your project is: <div class="not-exempt"><strong>NOT EXEMPTED</strong></div></h4>
@@ -39,43 +53,80 @@ function determineResults(checkedValues, legislationName) {
3953 text = `<h4>Your project is: <strong>EXEMPTED</strong></h4>
4054 <p>We've marked this in the form below for you as: <strong>${ selections } </strong></p>
4155 <p>Be sure to include a 1–2 sentence justification in the <code>exemptionText</code> field to support the exemption determination.</p>` ;
56+ }
4257
43- // Applies value to usageType on form
44- try {
45- const form = window . formIOInstance
46-
47- const component = form . getComponent ( 'usageType' ) ;
48- var currentSelection = component . getValue ( ) || [ ] ;
58+ setValue ( checkedValues ) ;
4959
50- checkedValues . forEach ( selected => {
51- currentSelection [ selected ] = true ;
52- } ) ;
60+ return text ;
61+ }
5362
54- form . getComponent ( 'usageType' ) . setValue ( currentSelection ) ;
63+ function handleClick ( event , exempt = false ) {
64+ const legislationName = event . target . id ;
65+ const quizContainer = document . querySelector ( `#${ legislationName } .exemptions` ) ;
66+ var resultsContainer = document . querySelector ( `#${ legislationName } .results` ) ;
67+
68+ // Determine next quiz
69+ var nextQuiz = "" ;
70+ if ( legislationName === "start" ) {
71+ if ( exempt ) {
72+ nextQuiz = "share-it-act" ;
5573 }
56- catch ( error ) {
57- console . error ( "Form fill error:" , error ) ;
74+ else {
75+ nextQuiz = "start" ;
5876 }
5977 }
78+ else if ( legislationName === "share-it-act" ) {
79+ nextQuiz = "m-16-21" ;
80+ }
81+ else {
82+ nextQuiz = "start" ;
83+ }
6084
61- return text ;
85+ event . preventDefault ( ) ;
86+ resetQuiz ( legislationName ) ;
87+
88+ // Display
89+ resultsContainer . style . display = "none" ;
90+ quizContainer . style . display = "none" ;
91+
92+ const nextQuizDiv = document . querySelector ( `#${ nextQuiz } .exemptions` ) ;
93+ const nextQuizContainer = document . querySelector ( `#${ nextQuiz } .exemptions-quiz-container` ) ;
94+ nextQuizDiv . style . display = "block" ;
95+ nextQuizContainer . style . display = "block" ;
6296}
6397
64- function handleClick ( event ) {
65- const legislationName = event . target . id ;
98+ function setValue ( checkedValues ) {
99+ // Applies value to usageType on form
100+ try {
101+ const form = window . formIOInstance
66102
67- const quizContainer = document . querySelector ( `#${ legislationName } .exemptions-quiz-container` ) ;
68- const resultsContainer = document . querySelector ( `#${ legislationName } .results` ) ;
103+ const component = form . getComponent ( 'usageType' ) ;
104+ var currentSelection = component . getValue ( ) || [ ] ;
105+
106+ checkedValues . forEach ( selected => {
107+ currentSelection [ selected ] = true ;
108+ } ) ;
109+
110+ form . getComponent ( 'usageType' ) . setValue ( currentSelection ) ;
111+ }
112+ catch ( error ) {
113+ console . error ( "Form fill error:" , error ) ;
114+ }
115+ }
116+
117+ function resetQuiz ( legislationName ) {
118+ var checkboxes = { } ;
119+
120+ if ( legislationName === "start" ) {
121+ checkboxes = document . querySelectorAll ( `#${ legislationName } .usa-radio__input` ) ;
122+ }
123+ else {
124+ checkboxes = document . querySelectorAll ( `#${ legislationName } .usa-checkbox__input` ) ;
125+ }
69126
70- event . preventDefault ( ) ;
71- //Uncheck checkboxes
72- const checkboxes = document . querySelectorAll ( `#${ legislationName } .usa-checkbox__input` ) ;
73127 checkboxes . forEach ( ( checkbox ) => {
74128 checkbox . checked = false ;
75129 } ) ;
76-
77- resultsContainer . style . display = "none" ;
78- quizContainer . style . display = "block" ;
79130}
80131
81132window . determineExemptions = determineExemptions ;
0 commit comments