Просмотр исходного кода

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>
Arthur Hanson 1 год назад
Родитель
Сommit
7bae448eaf

+ 2 - 0
netbox/netbox/views/generic/bulk_views.py

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

+ 17 - 15
netbox/templates/generic/object_list.html

@@ -81,15 +81,7 @@ Context:
         {% if table.paginator.num_pages > 1 %}
           <div id="select-all-box" class="d-none card d-print-none">
             <div class="form col-md-12">
-              <div class="card-body">
-                <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="card-body d-flex justify-content-between">
                 <div class="form-check">
                   <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
                   <label for="select-all" class="form-check-label">
@@ -98,6 +90,14 @@ Context:
                     {% endblocktrans %}
                   </label>
                 </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>
@@ -123,12 +123,14 @@ Context:
           {# Form buttons #}
           <div class="btn-list d-print-none mt-2">
             {% block bulk_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 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>
             {% endblock %}
           </div>
           {# /Form buttons #}

+ 17 - 2
netbox/templates/htmx/table.html

@@ -1,5 +1,6 @@
 {# Render an HTMX-enabled table with paginator #}
 {% load helpers %}
+{% load buttons %}
 {% load render_table from django_tables2 %}
 
 <div class="htmx-container table-responsive">
@@ -14,5 +15,19 @@
   {% endwith %}
 </div>
 
-{# 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>
+{% if request.htmx %}
+  {# 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 %}