-
Notifications
You must be signed in to change notification settings - Fork 279
Add multi-delete for users. #3138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
f393dea
aff58fc
bf71a0b
dcf6d9b
de64a31
1ce30ca
e3cf6a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function initializeMultiDelete(options) { | ||
var $deleteButton = $(options.buttonSelector); | ||
var checkboxClass = options.checkboxClass; | ||
var deleteUrl = options.deleteUrl; | ||
|
||
function toggleDeleteButton() { | ||
var checkedCount = $('.' + checkboxClass + ':checked').length; | ||
$deleteButton.prop('disabled', checkedCount === 0); | ||
} | ||
|
||
$(document).on('change', '.' + checkboxClass, function() { | ||
var table = $(this).closest('table'); | ||
var $tableCheckboxes = table.find('.' + checkboxClass); | ||
var $selectAllInTable = table.find('.select-all'); | ||
$selectAllInTable.prop('checked', $tableCheckboxes.length > 0 && $tableCheckboxes.length === $tableCheckboxes.filter(':checked').length); | ||
toggleDeleteButton(); | ||
}); | ||
|
||
$(document).on('change', '.select-all', function() { | ||
var table = $(this).closest('table'); | ||
table.find('.' + checkboxClass).prop('checked', $(this).is(':checked')); | ||
toggleDeleteButton(); | ||
}); | ||
|
||
toggleDeleteButton(); | ||
|
||
$deleteButton.on('click', function () { | ||
var ids = $('.' + checkboxClass + ':checked').map(function () { | ||
return 'ids[]=' + $(this).val(); | ||
}).get(); | ||
if (ids.length === 0) return; | ||
|
||
var url = deleteUrl + '?' + ids.join('&'); | ||
|
||
var $tempLink = $('<a>', { | ||
'href': url, | ||
'data-ajax-modal': '' | ||
}).hide().appendTo('body'); | ||
|
||
$tempLink.trigger('click'); | ||
$tempLink.remove(); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
|
@@ -59,6 +60,13 @@ public function indexAction( | |
'name' => ['title' => 'name', 'sort' => true, 'default_sort' => true], | ||
]; | ||
|
||
if ($this->isGranted('ROLE_ADMIN')) { | ||
|
||
$table_fields = array_merge( | ||
['checkbox' => ['title' => '<input type="checkbox" class="select-all" title="Select all affiliations">', 'sort' => false, 'search' => false, 'raw' => true]], | ||
$table_fields | ||
); | ||
} | ||
|
||
if ($showFlags) { | ||
$table_fields['country'] = ['title' => 'country', 'sort' => true]; | ||
$table_fields['affiliation_logo'] = ['title' => 'logo', 'sort' => false]; | ||
|
@@ -73,6 +81,16 @@ public function indexAction( | |
$teamAffiliation = $teamAffiliationData[0]; | ||
$affiliationdata = []; | ||
$affiliationactions = []; | ||
|
||
if ($this->isGranted('ROLE_ADMIN')) { | ||
$affiliationdata['checkbox'] = [ | ||
'value' => sprintf( | ||
'<input type="checkbox" name="ids[]" value="%s" class="affiliation-checkbox">', | ||
$teamAffiliation->getAffilid() | ||
) | ||
]; | ||
} | ||
|
||
// Get whatever fields we can from the affiliation object itself. | ||
foreach ($table_fields as $k => $v) { | ||
if ($propertyAccessor->isReadable($teamAffiliation, $k)) { | ||
|
@@ -201,6 +219,20 @@ public function deleteAction(Request $request, int $affilId): Response | |
return $this->deleteEntities($request, [$teamAffiliation], $this->generateUrl('jury_team_affiliations')); | ||
} | ||
|
||
#[IsGranted('ROLE_ADMIN')] | ||
#[Route(path: '/delete-multiple', name: 'jury_team_affiliation_delete_multiple', methods: ['GET', 'POST'])] | ||
public function deleteMultipleAction(Request $request): Response | ||
{ | ||
$ids = $request->query->all('ids'); | ||
if (empty($ids)) { | ||
throw new BadRequestHttpException('No IDs specified for deletion'); | ||
} | ||
|
||
$affiliations = $this->em->getRepository(TeamAffiliation::class)->findBy(['affilid' => $ids]); | ||
|
||
return $this->deleteEntities($request, $affiliations, $this->generateUrl('jury_team_affiliations')); | ||
} | ||
|
||
#[IsGranted('ROLE_ADMIN')] | ||
#[Route(path: '/add', name: 'jury_team_affiliation_add')] | ||
public function addAction(Request $request): Response | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
{% block title %} | ||
{% if count > 1 %} | ||
Delete {{ count }} {{ type }}s | ||
Delete {{ count }} {% if type|slice(-1) == 'y' %}{{ type|slice(0, -1) }}ies{% else %}{{ type }}s{% endif %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eldering this is the fix for pluralizing |
||
{% else %} | ||
Delete {{ type }} {{ primaryKey }} - "{{ description }}" | ||
{% endif %} | ||
|
@@ -16,7 +16,7 @@ | |
</div> | ||
{% else %} | ||
{% if count > 1 %} | ||
<p>You're about to delete the following {{ count }} {{ type }}s:</p> | ||
<p>You're about to delete the following {{ count }} {% if type|slice(-1) == 'y' %}{{ type|slice(0, -1) }}ies{% else %}{{ type }}s{% endif %}:</p> | ||
<ul> | ||
{% for desc in description|split(',') %} | ||
<li>{{ desc|trim }}</li> | ||
|
@@ -46,4 +46,4 @@ | |
{% if isError %}OK{% else %}Cancel{% endif %} | ||
{% endblock %} | ||
|
||
{% block buttonText %}Delete{% endblock %} | ||
{% block buttonText %}Delete{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% if entities is not empty %} | ||
<button type="button" class="btn btn-danger me-2" id="delete-selected-button" disabled><i class="fas fa-trash-alt"></i> Delete selected</button> | ||
{% endif %} |
Uh oh!
There was an error while loading. Please reload this page.