Skip to content

Commit 9bf826b

Browse files
committed
Add a warning log when clarifications are claimed
1 parent 2d6f4ff commit 9bf826b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

webapp/src/Controller/Jury/ClarificationController.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,25 @@ public function changeQueueAction(Request $request, int $clarId): Response
346346
return $this->redirectToRoute('jury_clarification', ['id' => $clarId]);
347347
}
348348

349+
#[Route('/check-claimed', name: 'check_if_claimed', methods: ['GET'])]
350+
public function checkIfClaimed(Request $request): Response
351+
{
352+
$clarid = $request->query->get('clarid');
353+
$currentUserName = $this->getUser()->getuserName();
354+
355+
$queryBuilder = $this->em->createQueryBuilder()
356+
->select('clar.jury_member')
357+
->from(Clarification::class, 'clar')
358+
->where('clar.clarid = :clarid')
359+
->setParameter('clarid', $clarid);
360+
$claimedJuryMember = $queryBuilder->getQuery()->getSingleResult();
361+
362+
return $this->json([
363+
'isClaimedByOther' => $claimedJuryMember['jury_member'] !== null && $claimedJuryMember['jury_member'] !== $currentUserName,
364+
'ClaimedBy' => $claimedJuryMember['jury_member'],
365+
]);
366+
}
367+
349368
protected function processSubmittedClarification(
350369
FormInterface $form,
351370
?Clarification $inReplTo = null

webapp/templates/jury/partials/clarification_form.html.twig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,30 @@
3333

3434
</div>
3535
{{ form_end(form) }}
36+
37+
<script>
38+
$(function () {
39+
var $body = $('body');
40+
41+
$body.on('submit', 'form[name=jury_clarification]', function () {
42+
var clarid = {{ origclar | json_encode(constant('JSON_HEX_TAG')) | raw }}.clarid;
43+
44+
fetch(`/jury/clarifications/check-claimed?clarid=${clarid}`, {
45+
method: 'GET',
46+
headers: {
47+
'Content-Type': 'application/json',
48+
}
49+
})
50+
.then(response => response.json())
51+
.then(data => {
52+
if (data.isClaimedByOther === true) {
53+
confirm(`This clarification has been claimed by ${data.ClaimedBy}. Are you sure you want to send this message?`);
54+
}
55+
})
56+
.catch(error => {
57+
console.error('Error:', error);
58+
alert('An error occurred while checking claim status.');
59+
});
60+
});
61+
});
62+
</script>

0 commit comments

Comments
 (0)