Skip to content

Commit e81158c

Browse files
committed
Add multi-delete for team affiliations.
Part of #229.
1 parent 09dcacf commit e81158c

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

webapp/src/Controller/Jury/TeamAffiliationController.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1718
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1819
use Symfony\Component\HttpKernel\KernelInterface;
1920
use Symfony\Component\PropertyAccess\PropertyAccess;
@@ -59,6 +60,13 @@ public function indexAction(
5960
'name' => ['title' => 'name', 'sort' => true, 'default_sort' => true],
6061
];
6162

63+
if ($this->isGranted('ROLE_ADMIN')) {
64+
$table_fields = array_merge(
65+
['checkbox' => ['title' => '<input type="checkbox" class="select-all" title="Select all affiliations">', 'sort' => false, 'search' => false, 'raw' => true]],
66+
$table_fields
67+
);
68+
}
69+
6270
if ($showFlags) {
6371
$table_fields['country'] = ['title' => 'country', 'sort' => true];
6472
$table_fields['affiliation_logo'] = ['title' => 'logo', 'sort' => false];
@@ -73,6 +81,16 @@ public function indexAction(
7381
$teamAffiliation = $teamAffiliationData[0];
7482
$affiliationdata = [];
7583
$affiliationactions = [];
84+
85+
if ($this->isGranted('ROLE_ADMIN')) {
86+
$affiliationdata['checkbox'] = [
87+
'value' => sprintf(
88+
'<input type="checkbox" name="ids[]" value="%s" class="affiliation-checkbox">',
89+
$teamAffiliation->getAffilid()
90+
)
91+
];
92+
}
93+
7694
// Get whatever fields we can from the affiliation object itself.
7795
foreach ($table_fields as $k => $v) {
7896
if ($propertyAccessor->isReadable($teamAffiliation, $k)) {
@@ -201,6 +219,20 @@ public function deleteAction(Request $request, int $affilId): Response
201219
return $this->deleteEntities($request, [$teamAffiliation], $this->generateUrl('jury_team_affiliations'));
202220
}
203221

222+
#[IsGranted('ROLE_ADMIN')]
223+
#[Route(path: '/delete-multiple', name: 'jury_team_affiliation_delete_multiple', methods: ['GET', 'POST'])]
224+
public function deleteMultipleAction(Request $request): Response
225+
{
226+
$ids = $request->query->all('ids');
227+
if (empty($ids)) {
228+
throw new BadRequestHttpException('No IDs specified for deletion');
229+
}
230+
231+
$affiliations = $this->em->getRepository(TeamAffiliation::class)->findBy(['affilid' => $ids]);
232+
233+
return $this->deleteEntities($request, $affiliations, $this->generateUrl('jury_team_affiliations'));
234+
}
235+
204236
#[IsGranted('ROLE_ADMIN')]
205237
#[Route(path: '/add', name: 'jury_team_affiliation_add')]
206238
public function addAction(Request $request): Response

webapp/templates/jury/team_affiliations.html.twig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,24 @@
1515
{{ macros.table(team_affiliations, table_fields) }}
1616

1717
{%- if is_granted('ROLE_ADMIN') %}
18-
19-
<p>
18+
<p class="mt-4">
19+
{% include 'jury/partials/_delete_button.html.twig' with {'entities': team_affiliations} %}
2020
{{ button(path('jury_team_affiliation_add'), 'Add new affiliation', 'primary', 'plus') }}
2121
</p>
2222
{%- endif %}
2323

2424
{% endblock %}
25+
26+
{% block extrafooter %}
27+
{{ parent() }}
28+
<script src="{{ asset('js/multi-delete.js') }}"></script>
29+
<script>
30+
$(function() {
31+
initializeMultiDelete({
32+
buttonSelector: '#delete-selected-button',
33+
checkboxClass: 'affiliation-checkbox',
34+
deleteUrl: '{{ path('jury_team_affiliation_delete_multiple') }}'
35+
});
36+
});
37+
</script>
38+
{% endblock %}

0 commit comments

Comments
 (0)