16733 fix bulk edit/delete buttons with quick search (#17130)

* 16733 fix bulk edit/delete buttons with quick search

* 16733 fix bulk edit/delete buttons with quick search

* 16733 fix bulk edit/delete buttons with quick search

* Wrap bulk action buttons with .bulk-action-buttons for replacement via HTMX

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson 2024-08-27 13:50:05 -07:00 committed by GitHub
parent 5ebdb7c9d2
commit 7bae448eaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 17 deletions

View File

@ -178,6 +178,8 @@ class ObjectListView(BaseMultiObjectView, ActionsMixin, TableMixin):
table.columns.hide('pk') table.columns.hide('pk')
return render(request, 'htmx/table.html', { return render(request, 'htmx/table.html', {
'table': table, 'table': table,
'model': model,
'actions': actions,
}) })
context = { context = {

View File

@ -81,15 +81,7 @@ Context:
{% if table.paginator.num_pages > 1 %} {% if table.paginator.num_pages > 1 %}
<div id="select-all-box" class="d-none card d-print-none"> <div id="select-all-box" class="d-none card d-print-none">
<div class="form col-md-12"> <div class="form col-md-12">
<div class="card-body"> <div class="card-body d-flex justify-content-between">
<div class="float-end">
{% if 'bulk_edit' in actions %}
{% bulk_edit_button model query_params=request.GET %}
{% endif %}
{% if 'bulk_delete' in actions %}
{% bulk_delete_button model query_params=request.GET %}
{% endif %}
</div>
<div class="form-check"> <div class="form-check">
<input type="checkbox" id="select-all" name="_all" class="form-check-input" /> <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
<label for="select-all" class="form-check-label"> <label for="select-all" class="form-check-label">
@ -98,6 +90,14 @@ Context:
{% endblocktrans %} {% endblocktrans %}
</label> </label>
</div> </div>
<div class="bulk-action-buttons">
{% if 'bulk_edit' in actions %}
{% bulk_edit_button model query_params=request.GET %}
{% endif %}
{% if 'bulk_delete' in actions %}
{% bulk_delete_button model query_params=request.GET %}
{% endif %}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -123,12 +123,14 @@ Context:
{# Form buttons #} {# Form buttons #}
<div class="btn-list d-print-none mt-2"> <div class="btn-list d-print-none mt-2">
{% block bulk_buttons %} {% block bulk_buttons %}
{% if 'bulk_edit' in actions %} <div class="bulk-action-buttons">
{% bulk_edit_button model query_params=request.GET %} {% if 'bulk_edit' in actions %}
{% endif %} {% bulk_edit_button model query_params=request.GET %}
{% if 'bulk_delete' in actions %} {% endif %}
{% bulk_delete_button model query_params=request.GET %} {% if 'bulk_delete' in actions %}
{% endif %} {% bulk_delete_button model query_params=request.GET %}
{% endif %}
</div>
{% endblock %} {% endblock %}
</div> </div>
{# /Form buttons #} {# /Form buttons #}

View File

@ -1,5 +1,6 @@
{# Render an HTMX-enabled table with paginator #} {# Render an HTMX-enabled table with paginator #}
{% load helpers %} {% load helpers %}
{% load buttons %}
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
<div class="htmx-container table-responsive"> <div class="htmx-container table-responsive">
@ -14,5 +15,19 @@
{% endwith %} {% endwith %}
</div> </div>
{# Include the updated object count for display elsewhere on the page #} {% if request.htmx %}
<div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div> {# Include the updated object count for display elsewhere on the page #}
<div hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>
{# Update the bulk action buttons with new query parameters #}
{% if actions %}
<div class="bulk-action-buttons" hx-swap-oob="outerHTML:.bulk-action-buttons">
{% if 'bulk_edit' in actions %}
{% bulk_edit_button model query_params=request.GET %}
{% endif %}
{% if 'bulk_delete' in actions %}
{% bulk_delete_button model query_params=request.GET %}
{% endif %}
</div>
{% endif %}
{% endif %}