Skip to content

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

Product variant list as data table

Paweł Kowalewskic83a7b77f481
diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.html
index 44eec8b6d9..a65e0aada9 100644
--- a/saleor/dashboard/templates/dashboard/product/product_form.html
+++ b/saleor/dashboard/templates/dashboard/product/product_form.html
@@ -62,26 +62,26 @@
{% endif %}
<div class="row" id="details">
- <div id="form-product">
- <div class="col l8" >
- <div class="row">
- {% csrf_token %}
- {{ product_form.name|materializecss }}
- {{ product_form.description|materializecss }}
- </div>
+ <form method="post" id="form-product" enctype="multipart/form-data">
+ <div class="col l8" >
+ <div class="row">
+ {% csrf_token %}
+ {{ product_form.name|materializecss }}
+ {{ product_form.description|materializecss }}
+ </div>
</div>
- <div class="col l4"><div class="row">
- {{ product_form.price|materializecss }}
- {{ product_form.weight|materializecss }}
- {{ product_form.categories|materializecss:"input-field s12" }}
- {{ product_form.attributes|materializecss:"input-field s12" }}
- </div>
+ <div class="col l4">
+ <div class="row">
+ {{ product_form.price|materializecss }}
+ {{ product_form.weight|materializecss }}
+ {{ product_form.categories|materializecss:"input-field s12" }}
+ {{ product_form.attributes|materializecss:"input-field s12" }}
+ </div>
</div>
- <div class="row">
- <div class="col s12 right-align">
-
+ <div class="col s12 right-align">
+ <div class="row">
{% if product.pk %}
<button type="submit" name="product-form" class="btn">{% trans "Update" %}</button>
{% else %}
@@ -89,41 +89,57 @@
{% endif %}
</div>
</div>
- </div>
- </div>
+ </form>
</div>
-</form>
{% if product.pk %}
- <div id="variants">
- <div class="row">
- <div class="col l12">
- <ul class="collection">
- {% for variant in variants %}
- <li class="collection-item">
- {{ variant.get_attributes_display }}, SKU: {{ variant.sku }}, price: {% gross variant.get_price_per_item %}
- <a class="light-blue-text text-lighten-1" title="{% trans "Edit variant" %}"
- href="{% url 'dashboard:variant-update' product_pk=product.pk variant_pk=variant.pk %}">
- <i class="mdi-content-create"></i>
- </a>
- <a class="materialize-red-text text-lighten-2" title="{% trans "Delete variant" %}"
- href="{% url 'dashboard:variant-delete' product_pk=product.pk variant_pk=variant.pk %}">
- <i class="mdi-action-delete"></i>
- </a>
- </li>
- {% empty %}
- <span>{% trans "No variants" %}</span>
- {% endfor %}
- </ul>
- </div>
- </div>
- <div class="row">
- <div class="col s12 right-align">
- <a href="{% url 'dashboard:variant-add' product_pk=product.pk %}" class="btn">
- <i class="mdi-content-add"></i> {% trans "Add new variant" %}
+ <div id="variants" class="card">
+ <form>
+ <div class="data-table-header">
+ <a href="{% url 'dashboard:variant-add' product_pk=product.pk %}" class="btn-data-table btn-show-when-unchecked blue-text">
+ {% trans "Add" %}
</a>
+
+ <button type="submit" class="btn-data-table btn-show-when-checked red-text" hidden>{% trans "Delete" %}</button>
</div>
- </div>
+ <table class="bordered hoverable data-table">
+ <thead>
+ <tr>
+ <th class="bulk-checkbox">
+ <input type="checkbox" id="select-all" class="filled-in switch-actions">
+ <label for="select-all"></label>
+ </th>
+ <th>{% trans "Name" %}</th>
+ <th class="right-align">{% trans "SKU" %}</th>
+ <th class="right-align">{% trans "Price" %}</th>
+ <th class="right-align">{% trans "Weight" %}</th>
+ <th>{% trans "Attributes" %}</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {% for variant in variants %}
+ <tr>
+ <td class="bulk-checkbox">
+ <input name="variant_id" type="checkbox" id="{{ variant.id }}" class="filled-in switch-actions">
+ <label for="{{ variant.id }}"></label>
+ </td>
+ <td><a class="light-blue-text text-lighten-1" title="{% trans "Edit variant" %}"
+ href="{% url 'dashboard:variant-update' product_pk=product.pk variant_pk=variant.pk %}">
+ {{ variant.name }}</a></td>
+ <td class="right-align">{{ variant.sku }}</td>
+ <td class="right-align">{% gross variant.get_price_per_item %}</td>
+ <td class="right-align">{{ variant.get_weight }}</td>
+ <td>
+ {% for name, value in variant.get_attributes_display.items %}
+ {{ name }}: {{ value }}{% if not forloop.last %},{% endif %}
+ {% endfor %}
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </form>
</div>
<div id="images">
diff --git a/saleor/dashboard/templates/dashboard/product/variant_form.html b/saleor/dashboard/templates/dashboard/product/variant_form.html
index 678b3a0af6..4308685425 100644
--- a/saleor/dashboard/templates/dashboard/product/variant_form.html
+++ b/saleor/dashboard/templates/dashboard/product/variant_form.html
@@ -12,7 +12,7 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu">
<li><a href="{% url "dashboard:products" %}">{% trans "Products" %}</a></li>
- <li><a href="{% url "dashboard:product-update" pk=product.pk %}"><i class="mdi-navigation-chevron-right"></i>{{ product }}</a></li>
+ <li><a href="{% url "dashboard:product-update" pk=product.pk %}#variants"><i class="mdi-navigation-chevron-right"></i>{{ product }}</a></li>
<li><i class="mdi-navigation-chevron-right"></i> {{ title }}</li>
</ul>
{% endblock %}
@@ -31,11 +31,10 @@
<div class="row">
<div class="col l8 offset-l2 right-align">
- <a href="{% url 'dashboard:product-update' pk=product.pk %}#variants" class="btn-flat"><i class="mdi-content-clear"></i> {% trans "Cancel" %}</a>
{% if variant.pk %}
- <button type="submit" class="btn"><i class="mdi-content-save"></i> {% trans "Update" %}</button>
+ <button type="submit" class="btn">{% trans "Update" %}</button>
{% else %}
- <button type="submit" class="btn"><i class="mdi-content-create"></i> {% trans "Create" %}</button>
+ <button type="submit" class="btn">{% trans "Create" %}</button>
{% endif %}
</div>
</div>
diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.js
index 5a31b25251..4fcb918b1b 100644
--- a/saleor/static/js_src/dashboard.js
+++ b/saleor/static/js_src/dashboard.js
@@ -30,3 +30,21 @@ if (el) {
}
});
}
+$('#select-all').on('change', function() {
+ if (this.checked) {
+ $('.switch-actions').prop('checked', true);
+ } else {
+ $('.switch-actions').prop('checked', false);
+ }
+});
+$('.switch-actions').on('change', function() {
+ var $btnChecked = $('.btn-show-when-checked');
+ var $btnUnchecked = $('.btn-show-when-unchecked');
+ if($('.switch-actions:checked').length) {
+ $btnChecked.show();
+ $btnUnchecked.hide();
+ } else {
+ $btnUnchecked.show();
+ $btnChecked.hide();
+ }
+});
diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scss
index 46e8f7ef0d..df95d3ca2a 100644
--- a/saleor/static/scss/_app.scss
+++ b/saleor/static/scss/_app.scss
@@ -43,6 +43,7 @@ $header-height: 60px;
top: $header-height/4;
i {
+ height: $header-height/2;
line-height: $header-height/2;
}
}
@@ -72,7 +73,6 @@ $header-height: 60px;
}
&.brand-logo {
- padding-top: 4px;
top: 0;
width: 100%;
@@ -85,22 +85,15 @@ $header-height: 60px;
}
a {
- font-family: "HurmeGeometricSans4-Black", sans-serif;
- font-size: 36px;
+ display: block;
height: $header-height;
- line-height: $header-height;
- letter-spacing: -4px;
- letter-spacing: -.5vmin;
- margin-left: -4px;
- margin-left: -.5vmin;
+ padding: 0;
text-align: center;
- text-transform: uppercase;
- @media (min-width: $large-screen-up) {
- font-size: 46px;
- font-size: 4vmin;
+ img {
+ height: 100%;
+ padding: 15px 0;
}
-
}
}
@@ -185,21 +178,6 @@ table {
width: calc(100% - 40px);
}
-%input-lg {
- font-size: 2.2rem;
- height: 3.5rem;
-}
-
-#form-product {
- #id_name {
- @extend %input-lg;
- }
-
- #id_price {
- @extend %input-lg;
- }
-}
-
.input-text-suffix {
float: right;
line-height: 45px;
@@ -215,8 +193,17 @@ table {
color: #999;
}
+.btn-data-table {
+ background: none;
+ border: none;
+ font-weight: bold;
+ padding: 0;
+ text-transform: uppercase;
+}
+
@import "widget/breadcrumbs";
@import "widget/category-list";
+@import "widget/data-table";
@import "widget/form";
@import "widget/product-gallery";
@import "widget/product-list";
diff --git a/saleor/static/scss/widget/_data-table.scss b/saleor/static/scss/widget/_data-table.scss
new file mode 100644
index 0000000000..8c14575dad
--- /dev/null
+++ b/saleor/static/scss/widget/_data-table.scss
@@ -0,0 +1,52 @@
+@mixin data-table {
+ &-header {
+ padding: 21px 24px;
+ }
+ input[type=checkbox].filled-in + label {
+ margin-top: 5px;
+ padding: 0;
+
+ &:after {
+ display: inline-block;
+ position: static;
+ }
+ }
+
+ th, td {
+ height: 48px;
+ overflow: hidden;
+ padding: 0 28px;
+ text-overflow: ellipsis;
+ vertical-align: middle;
+ white-space: nowrap;
+
+ &:first-child {
+ padding-left: 24px;
+ }
+
+ &:last-child {
+ padding-right: 24px;
+ }
+ }
+
+ th {
+ border-top: 1px solid $table-border-color;
+ color: map_get($grey, darken-1);
+ font-weight: normal;
+ font-size: 85%;
+ height: 56px;
+ }
+
+ .bulk-checkbox {
+ padding: 0 24px;
+ width: 1px;
+
+ + th, + td {
+ padding-left: 0;
+ }
+ }
+}
+
+.data-table {
+ @include data-table;
+}
diff --git a/saleor/static/scss/widget/_form.scss b/saleor/static/scss/widget/_form.scss
index 94a667f6a8..65b2f98adc 100644
--- a/saleor/static/scss/widget/_form.scss
+++ b/saleor/static/scss/widget/_form.scss
@@ -23,6 +23,21 @@
margin: -7px 0 15px;
font-size: $label-font-size;
}
+
+ %input-lg {
+ font-size: 2.2rem;
+ height: 3.5rem;
+ }
+
+ &#form-product {
+ #id_name {
+ @extend %input-lg;
+ }
+
+ #id_price {
+ @extend %input-lg;
+ }
+ }
}
form {
diff --git a/saleor/static/scss/widget/_select2.scss b/saleor/static/scss/widget/_select2.scss
index 4cf4c038ec..7d81767278 100644
--- a/saleor/static/scss/widget/_select2.scss
+++ b/saleor/static/scss/widget/_select2.scss
@@ -17,8 +17,20 @@
.select2-selection__choice {
background-color: map_get($blue, lighten-4);
border-color: map-get($blue, lighten-3);
+ border-radius: 2px;
line-height: 1.5;
margin-top: 10px;
+
+ &__remove {
+ @extend .mdi-navigation-close;
+ font-size: 0;
+
+ &:before {
+ display: inline-block;
+ font-family: $font-mdi;
+ font-size: 12px;
+ }
+ }
}
}