-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexemptionQuizHandler.js
More file actions
133 lines (109 loc) · 4.92 KB
/
exemptionQuizHandler.js
File metadata and controls
133 lines (109 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function determineExemptions(event) {
const legislationName = event.target.id;
const quizContainer = document.querySelector(`#${legislationName} .exemptions-quiz-container`);
const resultsContainer = document.querySelector(`#${legislationName} .results`);
const exemptionResult = document.querySelector(`#${legislationName} .exemption-result`);
var values = Array.from(document.querySelectorAll(`#${legislationName} input[name='exemption-condition']:checked`)).map((input) => input.value);
var checkedValues = [...new Set(values)];
// If simple quiz and exempt, go directly to SHARE IT Act Quiz
if (legislationName === "start" && (checkedValues.length === 0 || checkedValues[0] === "exempt")) {
handleClick(event, true);
return;
}
const results = determineResults(checkedValues, legislationName);
// Display results
quizContainer.style.display = "none";
resultsContainer.style.display = "block";
exemptionResult.innerHTML = results;
}
function determineResults(checkedValues, legislationName) {
var text = "";
// Project is not exempt - simple quiz
if (legislationName == "start") {
if (checkedValues[0] !== "exempt") {
text = `<h3 class="usa-heading margin-top-neg-05">Your project is qualified for sharing and reuse according to the SHARE IT Act and M-16-21.</h3>
<p>We've marked this in the form below for you as: <strong>${checkedValues[0]}</strong></p>`
}
}
// Project is not exempt
else if ((checkedValues.length === 1 && checkedValues[0].includes("none")) || checkedValues.length === 0) {
if (legislationName === "share-it-act") {
text = `<h3 class="usa-heading margin-top-neg-05">Your project is: <div class="not-exempt"><strong>NOT EXEMPTED</strong></div></h3>
<p>Please complete <strong>Part 1c</strong> to determine additional project exemptions.</p>`;
}
else {
text = `<h3 class="usa-heading margin-top-neg-05">Your project is: <div class="not-exempt"><strong>NOT EXEMPTED</strong></div></h3>
<p>If your project is NOT exempted from both M-16-21 AND the SHARE IT Act, please mark the following on the form: </p>
<p>If your repository is public, mark <code>usageType</code> as <strong>openSource</strong>.</p>
<p>If your repository is private, mark <code>usageType</code> as <strong>governmentWideReuse</strong>.</p>`;
}
}
// Project is exempted
else {
const selections = checkedValues.join(", ");
text = `<h3 class="usa-heading margin-top-neg-05">Your project is: <strong>EXEMPTED</strong></h3>
<p>We've marked this in the form below for you as: <strong>${selections}</strong></p>
<p>Be sure to include a 1–2 sentence justification in the <code>exemptionText</code> field to support the exemption determination.</p>`;
}
setValue(checkedValues);
return text;
}
function handleClick(event, exempt = false) {
const legislationName = event.target.id;
const quizContainer = document.querySelector(`#${legislationName}.exemptions`);
var resultsContainer = document.querySelector(`#${legislationName} .results`);
// Determine next quiz
var nextQuiz = "";
if (legislationName === "start") {
if (exempt) {
nextQuiz = "share-it-act";
}
else {
nextQuiz = "start";
}
}
else if (legislationName === "share-it-act") {
nextQuiz = "m-16-21";
}
else {
nextQuiz = "start";
}
event.preventDefault();
resetQuiz(legislationName);
// Display
resultsContainer.style.display = "none";
quizContainer.style.display = "none";
const nextQuizDiv = document.querySelector(`#${nextQuiz}.exemptions`);
const nextQuizContainer = document.querySelector(`#${nextQuiz} .exemptions-quiz-container`);
nextQuizDiv.style.display = "block";
nextQuizContainer.style.display = "block";
}
function setValue(checkedValues) {
// Applies value to usageType on form
try {
const form = window.formIOInstance
const component = form.getComponent('usageType');
var currentSelection = component.getValue() || [];
checkedValues.forEach(selected => {
currentSelection[selected] = true;
});
form.getComponent('usageType').setValue(currentSelection);
}
catch (error) {
console.error("Form fill error:", error);
}
}
function resetQuiz(legislationName) {
var checkboxes = {};
if (legislationName === "start") {
checkboxes = document.querySelectorAll(`#${legislationName} .usa-radio__input`);
}
else {
checkboxes = document.querySelectorAll(`#${legislationName} .usa-checkbox__input`);
}
checkboxes.forEach((checkbox) => {
checkbox.checked = false;
});
}
window.determineExemptions = determineExemptions;
window.handleClick = handleClick;