Spaces:
Sleeping
Sleeping
munyakarg commited on
Commit ·
2b845ef
1
Parent(s): 60a2a37
fix timing of results
Browse files- front-end/photo.html +5 -1
- static/css/styles.css +33 -4
- static/script/photo.js +12 -6
- static/script/script.js +195 -39
front-end/photo.html
CHANGED
|
@@ -19,7 +19,11 @@
|
|
| 19 |
</div>
|
| 20 |
<div> <button id="continuebutton">Continue</button></div>
|
| 21 |
</div>
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</div>
|
| 24 |
</div>
|
| 25 |
<script src="{{ url_for('static', filename='script/photo.js') }}" defer></script>
|
|
|
|
| 19 |
</div>
|
| 20 |
<div> <button id="continuebutton">Continue</button></div>
|
| 21 |
</div>
|
| 22 |
+
<div class="processing-overlay" id="processingOverlay">
|
| 23 |
+
<div class="spinner"></div>
|
| 24 |
+
<p>Processing your image...</p>
|
| 25 |
+
<p>This may take a few moments.</p>
|
| 26 |
+
</div>
|
| 27 |
</div>
|
| 28 |
</div>
|
| 29 |
<script src="{{ url_for('static', filename='script/photo.js') }}" defer></script>
|
static/css/styles.css
CHANGED
|
@@ -301,8 +301,37 @@ body {
|
|
| 301 |
border: 5px solid #FFFFFF;
|
| 302 |
object-fit: cover;
|
| 303 |
}
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
}
|
|
|
|
| 301 |
border: 5px solid #FFFFFF;
|
| 302 |
object-fit: cover;
|
| 303 |
}
|
| 304 |
+
p {
|
| 305 |
+
margin: 10px 0;
|
| 306 |
+
text-align: center;
|
| 307 |
+
font-size: medium;
|
| 308 |
+
}
|
| 309 |
+
.processing-overlay {
|
| 310 |
+
display: none;
|
| 311 |
+
position: fixed;
|
| 312 |
+
top: 0;
|
| 313 |
+
left: 0;
|
| 314 |
+
width: 100%;
|
| 315 |
+
height: 100%;
|
| 316 |
+
background: rgba(0,0,0,0.7);
|
| 317 |
+
z-index: 9999;
|
| 318 |
+
justify-content: center;
|
| 319 |
+
align-items: center;
|
| 320 |
+
flex-direction: column;
|
| 321 |
+
color: white;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
.spinner {
|
| 325 |
+
border: 4px solid #f3f3f3;
|
| 326 |
+
border-top: 4px solid #3498db;
|
| 327 |
+
border-radius: 50%;
|
| 328 |
+
width: 40px;
|
| 329 |
+
height: 40px;
|
| 330 |
+
animation: spin 1s linear infinite;
|
| 331 |
+
margin-bottom: 20px;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
@keyframes spin {
|
| 335 |
+
0% { transform: rotate(0deg); }
|
| 336 |
+
100% { transform: rotate(360deg); }
|
| 337 |
}
|
static/script/photo.js
CHANGED
|
@@ -58,6 +58,7 @@
|
|
| 58 |
}, false);
|
| 59 |
|
| 60 |
continuebutton.addEventListener('click', function() {
|
|
|
|
| 61 |
continueToResults();
|
| 62 |
});
|
| 63 |
|
|
@@ -108,7 +109,7 @@
|
|
| 108 |
var dataUrl = canvas.toDataURL('image/png');
|
| 109 |
sessionStorage.setItem('capturedPhoto', dataUrl);
|
| 110 |
// console.log("Image:", dataUrl);
|
| 111 |
-
|
| 112 |
// Upload the captured image
|
| 113 |
fetch('/upload', {
|
| 114 |
method: "POST",
|
|
@@ -130,14 +131,19 @@
|
|
| 130 |
|
| 131 |
// Check if the result element exists before trying to update it
|
| 132 |
// const resultElement = document.getElementById('result');
|
| 133 |
-
if (result) {
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
})
|
| 139 |
.catch(error => {
|
| 140 |
console.error('Error:', error);
|
|
|
|
|
|
|
| 141 |
});
|
| 142 |
}
|
| 143 |
|
|
|
|
| 58 |
}, false);
|
| 59 |
|
| 60 |
continuebutton.addEventListener('click', function() {
|
| 61 |
+
|
| 62 |
continueToResults();
|
| 63 |
});
|
| 64 |
|
|
|
|
| 109 |
var dataUrl = canvas.toDataURL('image/png');
|
| 110 |
sessionStorage.setItem('capturedPhoto', dataUrl);
|
| 111 |
// console.log("Image:", dataUrl);
|
| 112 |
+
document.getElementById('processingOverlay').style.display = 'flex';
|
| 113 |
// Upload the captured image
|
| 114 |
fetch('/upload', {
|
| 115 |
method: "POST",
|
|
|
|
| 131 |
|
| 132 |
// Check if the result element exists before trying to update it
|
| 133 |
// const resultElement = document.getElementById('result');
|
| 134 |
+
if (result.success) {
|
| 135 |
+
sessionStorage.setItem('session_id', result.session_id);
|
| 136 |
+
sessionStorage.setItem('model_results', JSON.stringify(result.results));
|
| 137 |
+
window.location.href = 'results.html'; //
|
| 138 |
+
} else {
|
| 139 |
+
alert('Error: ' + result.error);
|
| 140 |
+
document.getElementById('processingOverlay').style.display = 'none';
|
| 141 |
+
}
|
| 142 |
})
|
| 143 |
.catch(error => {
|
| 144 |
console.error('Error:', error);
|
| 145 |
+
alert('Upload failed. Please try again.');
|
| 146 |
+
document.getElementById('processingOverlay').style.display = 'none';
|
| 147 |
});
|
| 148 |
}
|
| 149 |
|
static/script/script.js
CHANGED
|
@@ -14,7 +14,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 14 |
// Tap to Begin screen
|
| 15 |
if (tapToBeginScreen) {
|
| 16 |
tapToBeginScreen.addEventListener("click", function () {
|
| 17 |
-
window.location.href = "terms.html";
|
| 18 |
});
|
| 19 |
}
|
| 20 |
|
|
@@ -56,43 +56,143 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 56 |
})
|
| 57 |
.catch(function (err) {
|
| 58 |
console.log("An error occurred: " + err);
|
|
|
|
| 59 |
});
|
| 60 |
|
| 61 |
// Capture photo
|
| 62 |
if (captureButton) {
|
| 63 |
-
captureButton.addEventListener("click", function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
canvas.width = video.videoWidth;
|
| 65 |
canvas.height = video.videoHeight;
|
| 66 |
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
// Show the captured image and hide the live cam
|
| 70 |
-
window.location.href = "results.html";
|
| 71 |
|
| 72 |
-
|
| 73 |
if (stream) {
|
| 74 |
stream.getTracks().forEach(track => track.stop());
|
| 75 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
});
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
// Results page
|
| 81 |
-
if (resultsPage
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
| 89 |
|
| 90 |
-
//
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
//
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
// End Session button
|
|
@@ -105,19 +205,50 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 105 |
// Restart button
|
| 106 |
if (restartButton) {
|
| 107 |
restartButton.addEventListener("click", function () {
|
|
|
|
| 108 |
window.location.href = "index.html";
|
| 109 |
});
|
| 110 |
}
|
| 111 |
|
| 112 |
-
// Yes button
|
| 113 |
const yesButton = document.getElementById("yesButton");
|
| 114 |
if (yesButton) {
|
| 115 |
-
yesButton.addEventListener("click", function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
window.location.href = "thankyou.html";
|
| 117 |
});
|
| 118 |
}
|
| 119 |
|
| 120 |
-
// No button
|
| 121 |
const noButton = document.getElementById("noButton");
|
| 122 |
if (noButton) {
|
| 123 |
noButton.addEventListener("click", function () {
|
|
@@ -127,9 +258,12 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 127 |
|
| 128 |
// Automatically restart session after 15 seconds on thank you page
|
| 129 |
if (thankYouPage) {
|
|
|
|
|
|
|
|
|
|
| 130 |
setTimeout(function () {
|
| 131 |
window.location.href = "index.html";
|
| 132 |
-
}, 15000);
|
| 133 |
}
|
| 134 |
|
| 135 |
// Function to toggle visibility of subcategories and their text inputs
|
|
@@ -165,13 +299,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 165 |
case 'white':
|
| 166 |
toggleSubcategories(event.target, 'whiteSubcategories', 'whiteInput');
|
| 167 |
break;
|
| 168 |
-
case 'native-american':
|
| 169 |
-
toggleSubcategories(event.target, 'nativeSubcategories', 'nativeAmericanInput');
|
| 170 |
-
break;
|
| 171 |
case 'other':
|
| 172 |
toggleSubcategories(event.target, '', 'otherInput');
|
| 173 |
break;
|
| 174 |
-
// Add more cases as needed for other categories
|
| 175 |
default:
|
| 176 |
break;
|
| 177 |
}
|
|
@@ -199,37 +329,63 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 199 |
case 'white':
|
| 200 |
toggleSubcategories(checkbox, 'whiteSubcategories', 'whiteInput');
|
| 201 |
break;
|
| 202 |
-
case 'native-american':
|
| 203 |
-
toggleSubcategories(checkbox, 'nativeSubcategories', 'nativeAmericanInput');
|
| 204 |
-
break;
|
| 205 |
-
// Add more cases as needed for other categories
|
| 206 |
default:
|
| 207 |
break;
|
| 208 |
}
|
| 209 |
});
|
| 210 |
|
| 211 |
-
// Add event listener for ethnicity form submission
|
| 212 |
if (ethnicityForm) {
|
| 213 |
-
ethnicityForm.addEventListener("submit", function (event) {
|
| 214 |
-
event.preventDefault();
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
});
|
| 217 |
}
|
| 218 |
|
| 219 |
-
//
|
| 220 |
if (submitButton) {
|
| 221 |
submitButton.addEventListener("click", function () {
|
| 222 |
-
// Redirect to the Thank You page
|
| 223 |
window.location.href = "thankyou.html";
|
| 224 |
});
|
| 225 |
}
|
| 226 |
-
|
|
|
|
|
|
|
| 227 |
if (conButton) {
|
| 228 |
conButton.addEventListener("click", function () {
|
| 229 |
-
// Redirect to the Thank You page
|
| 230 |
window.location.href = "race.html";
|
| 231 |
});
|
| 232 |
}
|
|
|
|
|
|
|
|
|
|
| 233 |
if (backButton) {
|
| 234 |
backButton.addEventListener("click", function () {
|
| 235 |
window.location.href = "results.html";
|
|
@@ -240,4 +396,4 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 240 |
window.location.href = "gender.html";
|
| 241 |
});
|
| 242 |
}
|
| 243 |
-
});
|
|
|
|
| 14 |
// Tap to Begin screen
|
| 15 |
if (tapToBeginScreen) {
|
| 16 |
tapToBeginScreen.addEventListener("click", function () {
|
| 17 |
+
window.location.href = "terms.html";
|
| 18 |
});
|
| 19 |
}
|
| 20 |
|
|
|
|
| 56 |
})
|
| 57 |
.catch(function (err) {
|
| 58 |
console.log("An error occurred: " + err);
|
| 59 |
+
alert("Camera access is required for this study. Please enable camera permissions.");
|
| 60 |
});
|
| 61 |
|
| 62 |
// Capture photo
|
| 63 |
if (captureButton) {
|
| 64 |
+
captureButton.addEventListener("click", async function () {
|
| 65 |
+
// Disable button to prevent double-clicks
|
| 66 |
+
captureButton.disabled = true;
|
| 67 |
+
captureButton.textContent = "Processing...";
|
| 68 |
+
|
| 69 |
+
// Capture the image
|
| 70 |
canvas.width = video.videoWidth;
|
| 71 |
canvas.height = video.videoHeight;
|
| 72 |
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 73 |
+
const imageData = canvas.toDataURL("image/png");
|
| 74 |
+
capturedImage.src = imageData;
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
// Stop the camera
|
| 77 |
if (stream) {
|
| 78 |
stream.getTracks().forEach(track => track.stop());
|
| 79 |
}
|
| 80 |
+
|
| 81 |
+
try {
|
| 82 |
+
// Send image to backend
|
| 83 |
+
const response = await fetch('/upload', {
|
| 84 |
+
method: 'POST',
|
| 85 |
+
headers: {
|
| 86 |
+
'Content-Type': 'application/json',
|
| 87 |
+
},
|
| 88 |
+
body: JSON.stringify({ image: imageData })
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
const data = await response.json();
|
| 92 |
+
|
| 93 |
+
if (data.success) {
|
| 94 |
+
// Store session ID and results
|
| 95 |
+
sessionStorage.setItem('session_id', data.session_id);
|
| 96 |
+
sessionStorage.setItem('model_results', JSON.stringify(data.results));
|
| 97 |
+
sessionStorage.setItem('captured_image', imageData);
|
| 98 |
+
|
| 99 |
+
console.log('Results stored:', data.results);
|
| 100 |
+
|
| 101 |
+
// Redirect to results page
|
| 102 |
+
window.location.href = "results.html";
|
| 103 |
+
} else {
|
| 104 |
+
alert('Error processing image: ' + (data.error || 'Unknown error'));
|
| 105 |
+
captureButton.disabled = false;
|
| 106 |
+
captureButton.textContent = "Capture Photo";
|
| 107 |
+
}
|
| 108 |
+
} catch (error) {
|
| 109 |
+
console.error('Error uploading image:', error);
|
| 110 |
+
alert('Failed to process image. Please try again.');
|
| 111 |
+
captureButton.disabled = false;
|
| 112 |
+
captureButton.textContent = "Capture Photo";
|
| 113 |
+
}
|
| 114 |
});
|
| 115 |
}
|
| 116 |
}
|
| 117 |
|
| 118 |
// Results page
|
| 119 |
+
if (resultsPage) {
|
| 120 |
+
// Load and display AI results when page loads
|
| 121 |
+
window.addEventListener('load', function() {
|
| 122 |
+
const modelResults = sessionStorage.getItem('model_results');
|
| 123 |
+
const capturedImage = sessionStorage.getItem('captured_image');
|
| 124 |
|
| 125 |
+
if (!modelResults) {
|
| 126 |
+
alert('No results found. Please start over.');
|
| 127 |
+
window.location.href = 'index.html';
|
| 128 |
+
return;
|
| 129 |
+
}
|
| 130 |
|
| 131 |
+
// Display the captured image if available
|
| 132 |
+
const imgElement = document.getElementById('capturedImageDisplay');
|
| 133 |
+
if (imgElement && capturedImage) {
|
| 134 |
+
imgElement.src = capturedImage;
|
| 135 |
+
}
|
| 136 |
|
| 137 |
+
// Parse and display the AI results
|
| 138 |
+
try {
|
| 139 |
+
const results = JSON.parse(modelResults);
|
| 140 |
+
const aiResultsDiv = document.getElementById("aiResults");
|
| 141 |
+
|
| 142 |
+
if (aiResultsDiv) {
|
| 143 |
+
// Format the results nicely
|
| 144 |
+
aiResultsDiv.innerHTML = `
|
| 145 |
+
<h3>AI Model Predictions:</h3>
|
| 146 |
+
<pre>${JSON.stringify(results, null, 2)}</pre>
|
| 147 |
+
`;
|
| 148 |
+
}
|
| 149 |
+
} catch (error) {
|
| 150 |
+
console.error('Error parsing results:', error);
|
| 151 |
+
alert('Error displaying results. Please try again.');
|
| 152 |
+
}
|
| 153 |
});
|
| 154 |
+
|
| 155 |
+
// Handle user info form submission
|
| 156 |
+
if (userInfoForm) {
|
| 157 |
+
userInfoForm.addEventListener("submit", function (event) {
|
| 158 |
+
event.preventDefault();
|
| 159 |
+
|
| 160 |
+
const sessionId = sessionStorage.getItem('session_id');
|
| 161 |
+
const userAge = document.getElementById("userAge").value;
|
| 162 |
+
const userRace = Array.from(document.getElementById("userRace").selectedOptions).map(option => option.value);
|
| 163 |
+
const userGender = document.getElementById("userGender").value;
|
| 164 |
+
|
| 165 |
+
// Store user responses
|
| 166 |
+
sessionStorage.setItem('user_age', userAge);
|
| 167 |
+
sessionStorage.setItem('user_race', JSON.stringify(userRace));
|
| 168 |
+
sessionStorage.setItem('user_gender', userGender);
|
| 169 |
+
|
| 170 |
+
// Send to backend
|
| 171 |
+
fetch('/save_survey', {
|
| 172 |
+
method: 'POST',
|
| 173 |
+
headers: {
|
| 174 |
+
'Content-Type': 'application/json',
|
| 175 |
+
},
|
| 176 |
+
body: JSON.stringify({
|
| 177 |
+
session_id: sessionId,
|
| 178 |
+
age: userAge,
|
| 179 |
+
race: userRace,
|
| 180 |
+
gender: userGender
|
| 181 |
+
})
|
| 182 |
+
}).then(response => response.json())
|
| 183 |
+
.then(data => {
|
| 184 |
+
if (data.success) {
|
| 185 |
+
window.location.href = "gender.html";
|
| 186 |
+
} else {
|
| 187 |
+
alert('Error saving data. Please try again.');
|
| 188 |
+
}
|
| 189 |
+
})
|
| 190 |
+
.catch(error => {
|
| 191 |
+
console.error('Error:', error);
|
| 192 |
+
alert('Error saving data. Please try again.');
|
| 193 |
+
});
|
| 194 |
+
});
|
| 195 |
+
}
|
| 196 |
}
|
| 197 |
|
| 198 |
// End Session button
|
|
|
|
| 205 |
// Restart button
|
| 206 |
if (restartButton) {
|
| 207 |
restartButton.addEventListener("click", function () {
|
| 208 |
+
sessionStorage.clear(); // Clear session data
|
| 209 |
window.location.href = "index.html";
|
| 210 |
});
|
| 211 |
}
|
| 212 |
|
| 213 |
+
// Yes button (send results)
|
| 214 |
const yesButton = document.getElementById("yesButton");
|
| 215 |
if (yesButton) {
|
| 216 |
+
yesButton.addEventListener("click", async function () {
|
| 217 |
+
const sessionId = sessionStorage.getItem('session_id');
|
| 218 |
+
const contactMethod = document.getElementById('contactMethod')?.value || 'none';
|
| 219 |
+
const contactInfo = document.getElementById('contactInfo')?.value || '';
|
| 220 |
+
|
| 221 |
+
if (contactMethod !== 'none' && contactInfo) {
|
| 222 |
+
try {
|
| 223 |
+
const response = await fetch('/send_results', {
|
| 224 |
+
method: 'POST',
|
| 225 |
+
headers: {
|
| 226 |
+
'Content-Type': 'application/json',
|
| 227 |
+
},
|
| 228 |
+
body: JSON.stringify({
|
| 229 |
+
session_id: sessionId,
|
| 230 |
+
contact_method: contactMethod,
|
| 231 |
+
contact_info: contactInfo
|
| 232 |
+
})
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
const data = await response.json();
|
| 236 |
+
|
| 237 |
+
if (data.success) {
|
| 238 |
+
if (data.sent) {
|
| 239 |
+
alert('Results sent successfully!');
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
} catch (error) {
|
| 243 |
+
console.error('Error sending results:', error);
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
window.location.href = "thankyou.html";
|
| 248 |
});
|
| 249 |
}
|
| 250 |
|
| 251 |
+
// No button (skip sending results)
|
| 252 |
const noButton = document.getElementById("noButton");
|
| 253 |
if (noButton) {
|
| 254 |
noButton.addEventListener("click", function () {
|
|
|
|
| 258 |
|
| 259 |
// Automatically restart session after 15 seconds on thank you page
|
| 260 |
if (thankYouPage) {
|
| 261 |
+
// Clear session storage
|
| 262 |
+
sessionStorage.clear();
|
| 263 |
+
|
| 264 |
setTimeout(function () {
|
| 265 |
window.location.href = "index.html";
|
| 266 |
+
}, 15000);
|
| 267 |
}
|
| 268 |
|
| 269 |
// Function to toggle visibility of subcategories and their text inputs
|
|
|
|
| 299 |
case 'white':
|
| 300 |
toggleSubcategories(event.target, 'whiteSubcategories', 'whiteInput');
|
| 301 |
break;
|
|
|
|
|
|
|
|
|
|
| 302 |
case 'other':
|
| 303 |
toggleSubcategories(event.target, '', 'otherInput');
|
| 304 |
break;
|
|
|
|
| 305 |
default:
|
| 306 |
break;
|
| 307 |
}
|
|
|
|
| 329 |
case 'white':
|
| 330 |
toggleSubcategories(checkbox, 'whiteSubcategories', 'whiteInput');
|
| 331 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
default:
|
| 333 |
break;
|
| 334 |
}
|
| 335 |
});
|
| 336 |
|
| 337 |
+
// Add event listener for ethnicity form submission
|
| 338 |
if (ethnicityForm) {
|
| 339 |
+
ethnicityForm.addEventListener("submit", async function (event) {
|
| 340 |
+
event.preventDefault();
|
| 341 |
+
|
| 342 |
+
const sessionId = sessionStorage.getItem('session_id');
|
| 343 |
+
|
| 344 |
+
// Collect all checked ethnicities
|
| 345 |
+
const selectedEthnicities = [];
|
| 346 |
+
mainCategories.forEach(checkbox => {
|
| 347 |
+
if (checkbox.checked) {
|
| 348 |
+
selectedEthnicities.push(checkbox.value || checkbox.id);
|
| 349 |
+
}
|
| 350 |
+
});
|
| 351 |
+
|
| 352 |
+
// Save ethnicity data
|
| 353 |
+
try {
|
| 354 |
+
await fetch('/save_survey', {
|
| 355 |
+
method: 'POST',
|
| 356 |
+
headers: {
|
| 357 |
+
'Content-Type': 'application/json',
|
| 358 |
+
},
|
| 359 |
+
body: JSON.stringify({
|
| 360 |
+
session_id: sessionId,
|
| 361 |
+
race: selectedEthnicities
|
| 362 |
+
})
|
| 363 |
+
});
|
| 364 |
+
} catch (error) {
|
| 365 |
+
console.error('Error saving ethnicity:', error);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
window.location.href = "thankyou.html";
|
| 369 |
});
|
| 370 |
}
|
| 371 |
|
| 372 |
+
// Submit button
|
| 373 |
if (submitButton) {
|
| 374 |
submitButton.addEventListener("click", function () {
|
|
|
|
| 375 |
window.location.href = "thankyou.html";
|
| 376 |
});
|
| 377 |
}
|
| 378 |
+
|
| 379 |
+
// Continue button
|
| 380 |
+
const conButton = document.getElementById("conButton");
|
| 381 |
if (conButton) {
|
| 382 |
conButton.addEventListener("click", function () {
|
|
|
|
| 383 |
window.location.href = "race.html";
|
| 384 |
});
|
| 385 |
}
|
| 386 |
+
|
| 387 |
+
// Back buttons
|
| 388 |
+
const backButton = document.getElementById("backButton");
|
| 389 |
if (backButton) {
|
| 390 |
backButton.addEventListener("click", function () {
|
| 391 |
window.location.href = "results.html";
|
|
|
|
| 396 |
window.location.href = "gender.html";
|
| 397 |
});
|
| 398 |
}
|
| 399 |
+
});
|