Spaces:
Running
Running
File size: 10,844 Bytes
5445d68 55168e2 5445d68 2e5f746 5445d68 55168e2 5445d68 55168e2 5445d68 55168e2 5445d68 f9118d2 5445d68 f9118d2 5445d68 f9118d2 5445d68 2e5f746 5445d68 2e5f746 5445d68 f55d9fd 5445d68 2e5f746 5445d68 55168e2 5445d68 |
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
import { confirmIcon } from './constants.js';
import { apiBaseUrl, output } from './main.js';
import { t, onLanguageChange } from './i18n.js';
const feedbackButton = document.getElementById('btn-feedback-face-check');
const closeFeedback = document.getElementById('close-feedback-1765253515534');
const liveChat = document.getElementById('live-chat-1765253515534');
const feedbackContainer = document.getElementById('feedback-1765253515534');
const blockNotification = document.getElementById(
'block-notification-1765336324468'
);
const blockQuestion = document.getElementById('block-question-1765336324468');
const footerFeedback = document.getElementById('footer-feedback-1765336324468');
const REQUIRED_QUESTION_IDS = ['q1', 'q2'];
const isSuccess = {};
const isLoading = {};
const isFailed = {};
let isLoadingInternal = false;
function updateFeedbackButtonLabel() {
if (!feedbackButton) return;
feedbackButton.innerText = isLoadingInternal
? t('sendingLabel')
: t('sendButton');
}
onLanguageChange(() => {
updateFeedbackButtonLabel();
});
function areRequiredQuestionsAnswered() {
return REQUIRED_QUESTION_IDS.every((id) =>
document.querySelector(`#${id} input[type="radio"]:checked`)
);
}
function syncFeedbackButtonState() {
const missingRequired = !areRequiredQuestionsAnswered();
const shouldDisable = isLoadingInternal || missingRequired;
if (feedbackButton) {
feedbackButton.disabled = shouldDisable;
feedbackButton.classList.toggle('btn-disabled', shouldDisable);
feedbackButton.classList.toggle('disable', shouldDisable);
}
}
Object.defineProperty(isSuccess, 'value', {
set(newValue) {
if (newValue) {
if (blockNotification) {
const contentSentSuccessfully = `<div class="notification-content-feedback">
${confirmIcon}
<p class="notification-message">${t('feedbackSuccess')}</p>
</div>`;
blockNotification.innerHTML = contentSentSuccessfully;
blockNotification.classList.remove('display-none');
feedbackButton.disabled = true;
feedbackButton.classList.add('btn-disabled', 'disable');
footerFeedback.classList.add('display-none');
}
if (blockQuestion) {
blockQuestion.classList.add('display-none');
}
} else {
blockNotification.classList.add('display-none');
blockQuestion.classList.remove('display-none');
blockNotification.innerHTML = '';
syncFeedbackButtonState();
footerFeedback.classList.remove('display-none');
}
this._value = newValue;
},
get() {
return this._value;
},
});
Object.defineProperty(isLoading, 'value', {
set(newValue) {
isLoadingInternal = newValue;
updateFeedbackButtonLabel();
this._value = newValue;
syncFeedbackButtonState();
},
get() {
return this._value;
},
});
function resetFeedbackForm() {
const radios = document.querySelectorAll('.question input[type="radio"]');
const textareas = document.querySelectorAll('.feedback textarea');
const stars = document.querySelectorAll('.options-stars .star');
radios.forEach((radio) => {
radio.checked = false;
});
textareas.forEach((textarea) => {
textarea.value = '';
});
stars.forEach((star) => {
star.classList.remove('active');
});
syncFeedbackButtonState();
}
function assignRadioValues() {
const enValues = {
q0: [
'Journalist / Fact Checker',
'Researcher / Student',
'Law Enforcement / OSINT',
'General User',
],
q1: [
'Spot on',
'Mostly correct',
'Mixed results',
'Missed key context',
'Completely wrong',
],
q2: [
'Yes',
'No - It was actually Real',
'No - It was actually AI-Generated',
],
q3: [
'All links worked and were relevant',
'Some links were broken/dead',
'Links were unrelated to the topic',
],
q4: [
'No issues',
'Invented dates/times',
'Invented people/names',
"Citations that don't exist",
],
q5: [
'Very Clear',
'Clear',
'Moderately Clear',
'Slightly Clear',
'Not Clear',
],
q6: ['Yes', 'Partially', 'No'],
q7: [
'Very Clear',
'Clear',
'Moderately Clear',
'Slightly Clear',
'Not Clear',
],
q8: ['Yes', 'Not Applicable', 'No'],
q9: [
'Clearly Explained',
'Well Explained',
'Moderately Explained',
'Poorly Explained',
'Not Explained',
],
};
const questions = document.querySelectorAll('.question');
questions.forEach((question) => {
const questionId = question.id;
const options = question.querySelectorAll('.option');
options.forEach((option, index) => {
const radio = option.querySelector('input[type="radio"]');
if (!radio) return;
const enList = enValues[questionId];
if (enList && enList[index]) {
radio.value = enList[index];
return;
}
// Fallbacks if question not mapped
if (questionId === '') {
radio.value = String(index + 1);
} else {
const optionText = option
.querySelector('.option-text')
?.textContent?.trim();
radio.value = optionText || radio.value || String(index + 1);
}
});
});
}
function initializeStarRatings() {
const starGroups = document.querySelectorAll('.options-stars');
starGroups.forEach((group) => {
const options = Array.from(group.querySelectorAll('.option'));
const radios = options
.map((option) => option.querySelector('input[type="radio"]'))
.filter(Boolean);
const stars = options
.map((option) => option.querySelector('.star'))
.filter(Boolean);
const updateStars = (activeIndex) => {
stars.forEach((star, index) => {
star.classList.toggle('active', index <= activeIndex);
});
};
if (radios.length === 0 || stars.length === 0) {
return;
}
radios.forEach((radio, index) => {
radio.value = radio.value || String(index + 1);
radio.addEventListener('change', () => {
updateStars(index);
});
if (radio.checked) {
updateStars(index);
}
});
if (!radios.some((radio) => radio.checked)) {
updateStars(-1);
}
});
}
function collectFeedbackData() {
const responses = {};
const questions = document.querySelectorAll('.question');
questions.forEach((question) => {
if (!question.id) return;
const radios = question.querySelectorAll('input[type="radio"]');
const selected = question.querySelector('input[type="radio"]:checked');
const textarea = question.querySelector('textarea');
if (radios.length > 0) {
if (!selected) {
responses[question.id] = '-';
} else {
let value = selected.value;
if (!value) {
const optionText = selected
.closest('.opt')
?.querySelector('.option-text')
?.textContent?.trim();
value = optionText || '-';
}
responses[question.id] = value;
}
if (textarea) {
const textValue = textarea.value.trim();
responses[`${question.id}_comments`] = textValue || '-';
}
} else if (textarea) {
const textValue = textarea.value.trim();
responses[question.id] = textValue || '-';
} else {
responses[question.id] = '-';
}
});
return responses;
}
async function handleFeedbackSubmit(event) {
event.preventDefault();
if (!areRequiredQuestionsAnswered()) {
syncFeedbackButtonState();
return;
}
isLoading.value = true;
// Simulate async feedback submission
const feedbackData = collectFeedbackData();
const _output = `${output?.readme_content?.case_summary?.title || ''}${
output?.readme_content?.case_summary?.content || ''
}${output?.readme_content?.content_classification?.title || ''}${
output?.readme_content?.content_classification?.content || ''
}${output?.readme_content?.verified_evidence?.title || ''}
${output?.readme_content?.verified_evidence?.source_details?.title || ''}${
output?.readme_content?.verified_evidence?.source_details?.content || ''
}${output?.readme_content?.verified_evidence?.where?.title || ''}${
output?.readme_content?.verified_evidence?.where?.content || ''
}${output?.readme_content?.verified_evidence?.when?.title || ''}${
output?.readme_content?.verified_evidence?.when?.content || ''
}${output?.readme_content?.verified_evidence?.who?.title || ''}${
output?.readme_content?.verified_evidence?.who?.content || ''
}${output?.readme_content?.verified_evidence?.why?.title || ''}${
output?.readme_content?.verified_evidence?.why?.content || ''
}${output?.readme_content?.forensic_analysis?.title || ''}${
output?.readme_content?.forensic_analysis?.content || ''
}${output?.readme_content?.other_evidence?.title || ''}${
output?.readme_content?.other_evidence?.content || ''
}
`;
feedbackData['q11'] = _output.trim().length > 0 ? _output.trim() : '-';
axios
.post(apiBaseUrl + 'v1/survey', feedbackData, {
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => {
console.log('Feedback submitted successfully:', response.data);
isLoading.value = false;
resetFeedbackForm();
isSuccess.value = true;
})
.catch((error) => {
console.error('Error submitting feedback:', error);
isLoading.value = false;
isFailed.value = true;
});
}
assignRadioValues();
initializeStarRatings();
syncFeedbackButtonState();
const requiredRadios = document.querySelectorAll(
'#q1 input[type="radio"], #q2 input[type="radio"]'
);
requiredRadios.forEach((radio) => {
radio.addEventListener('change', () => {
syncFeedbackButtonState();
});
});
if (feedbackButton) {
feedbackButton.addEventListener('click', handleFeedbackSubmit);
}
updateFeedbackButtonLabel();
window.collectFeedbackData = collectFeedbackData;
closeFeedback.addEventListener('click', () => {
if (feedbackContainer) {
feedbackContainer.classList.add('display-none');
liveChat.classList.remove('display-none');
isLoading.value = false;
isFailed.value = false;
isSuccess.value = false;
}
});
liveChat.addEventListener('click', () => {
if (feedbackContainer) {
feedbackContainer.classList.remove('display-none');
liveChat.classList.add('display-none');
}
});
|