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

This commit is contained in:
Jeremy Stretch 2024-08-27 15:30:07 -04:00
parent 5feb0a227f
commit 1416888030
2 changed files with 32 additions and 31 deletions

View File

@ -81,19 +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 %}
<span class="bulk-edit-button">
{% bulk_edit_button model query_params=request.GET %}
</span>
{% endif %}
{% if 'bulk_delete' in actions %}
<span class="bulk-delete-button">
{% bulk_delete_button model query_params=request.GET %}
</span>
{% 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">
@ -102,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>
@ -127,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 %}
<div class="bulk-action-buttons">
{% if 'bulk_edit' in actions %} {% if 'bulk_edit' in actions %}
{% bulk_edit_button model query_params=request.GET %} {% bulk_edit_button model query_params=request.GET %}
{% endif %} {% endif %}
{% if 'bulk_delete' in actions %} {% if 'bulk_delete' in actions %}
{% bulk_delete_button model query_params=request.GET %} {% bulk_delete_button model query_params=request.GET %}
{% endif %} {% endif %}
</div>
{% endblock %} {% endblock %}
</div> </div>
{# /Form buttons #} {# /Form buttons #}

View File

@ -15,16 +15,19 @@
{% endwith %} {% endwith %}
</div> </div>
{% if request.htmx %}
{# Include the updated object count for display elsewhere on the page #} {# Include the updated object count for display elsewhere on the page #}
<div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div> <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 %} {% if 'bulk_edit' in actions %}
<div class="d-none" hx-swap-oob="innerHTML:.bulk-edit-button">
{% bulk_edit_button model query_params=request.GET %} {% bulk_edit_button model query_params=request.GET %}
</div>
{% endif %} {% endif %}
{% if 'bulk_delete' in actions %} {% if 'bulk_delete' in actions %}
<div class="d-none" hx-swap-oob="innerHTML:.bulk-delete-button">
{% bulk_delete_button model query_params=request.GET %} {% bulk_delete_button model query_params=request.GET %}
{% endif %}
</div> </div>
{% endif %} {% endif %}
{% endif %}