Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Dashboard tabular products list with bulk checkbox

Anna Siwik8df714c67c44
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 8d11937fb7..d51487f337 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -14,8 +14,8 @@ from ...product.models import (
Product, ProductAttribute, ProductClass, ProductImage, ProductVariant,
Stock, StockLocation)
from ...product.utils import get_availability
-from ..views import staff_member_required, superuser_required
from ...settings import DASHBOARD_PAGINATE_BY
+from ..views import staff_member_required, superuser_required
from . import forms
@@ -109,7 +109,8 @@ def product_list(request):
products = get_paginator_items(
products, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {
- 'form': form, 'products': products, 'product_classes': product_classes}
+ 'bulk_action_form': forms.ProductBulkUpdate(), 'form': form,
+ 'products': products, 'product_classes': product_classes}
return TemplateResponse(request, 'dashboard/product/list.html', ctx)
diff --git a/saleor/static/dashboard/js/components/bulk-actions.js b/saleor/static/dashboard/js/components/bulk-actions.js
index 716c9a805a..8e532d5463 100644
--- a/saleor/static/dashboard/js/components/bulk-actions.js
+++ b/saleor/static/dashboard/js/components/bulk-actions.js
@@ -1,4 +1,8 @@
$(document).ready((e) => {
+ function updateCounterSelected() {
+ const count = $('.select-item:checked').length;
+ $('.data-table-header-action-selected-items #counter').text(count);
+ }
$('.select-all').on('change', function () {
let $items = $(this).parents('form').find('.switch-actions');
if (this.checked) {
@@ -6,6 +10,10 @@ $(document).ready((e) => {
} else {
$items.prop('checked', false);
}
+ updateCounterSelected();
+ });
+ $('.select-item').on('change', function() {
+ updateCounterSelected();
});
$('.switch-actions').on('change', function () {
let $btnChecked = $(this).parents('form').find('.btn-show-when-checked');
diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.html
index dd711f9870..a9461b36d1 100644
--- a/templates/dashboard/product/list.html
+++ b/templates/dashboard/product/list.html
@@ -46,23 +46,66 @@
<div class="row">
<div class="col s12">
{% if products %}
- <ul class="collection list">
- {% for product in products %}
- <li class="collection-item avatar list-item">
- <a href="{% url 'dashboard:product-detail' pk=product.pk %}">
- <img src="{% product_first_image product size="60x60" method="crop" %}"
- srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"
- alt="" class="circle teal">
- <span class="title list-item-name">
+ <div class="card">
+ <form method="POST">
+ {% csrf_token %}
+ <div class="data-table-header-action">
+ <div class="row mb-0">
+ <div class="col s12">
+ {{ bulk_action_form.action|materializecss:"inline s4" }}
+ <input type="submit" class="btn-flat bulk-submit" value="{% trans "Submit" context "Dashboard form submit input" %}" />
+ </div>
+ </div>
+ <div class="row">
+ <div class="col s12">
+ <div class="data-table-header-action-selected-items">
+ <span id="counter">0</span> {% trans "item(s) selected" context "Dashboard bulk action summary" %}
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="data-table-container">
+ <table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th class="bulk-checkbox">
+ <input id="select-all-products" type="checkbox" class="filled-in select-all switch-actions select-item">
+ <label for="select-all-products"></label>
+ </th>
+ <th></th>
+ <th class="wide">
+ {% trans "Name" context "Products list table header" %}
+ </th>
+ <th>
+ {% trans "Price" context "Products list table header" %}
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for product in products %}
+ <tr class="avatar" data-action-go="{% url 'dashboard:product-detail' pk=product.pk %}">
+ <td class="bulk-checkbox ignore-link">
+ <input id="id_products_{{ product.pk }}" type="checkbox" name="products" value="{{ product.pk }}" class="filled-in switch-actions select-item">
+ <label for="id_products_{{ product.pk }}"></label>
+ </td>
+ <td class="avatar">
+ <img src="{% product_first_image product size="60x60" method="crop" %}"
+ srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"
+ alt="" class="circle teal">
+ </td>
+ <td>
{{ product.name }}
- </span>
- <p class="list-item-price">
+ </td>
+ <td>
{% gross product.price html=True %}
- </p>
- </a>
- </li>
- {% endfor %}
- </ul>
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </form>
+ </div>
{% paginate products %}
{% else %}
<div class="not-found">