Skip to content

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

Fix product image uploads and dropzone.js

Marco Badan4968268668c5
diff --git a/saleor/dashboard/product/api.py b/saleor/dashboard/product/api.py
index 1fb67f2076..f475a33a5d 100644
--- a/saleor/dashboard/product/api.py
+++ b/saleor/dashboard/product/api.py
@@ -23,6 +23,7 @@ class UploadImageSerializer(serializers.ModelSerializer):
class ProductImageSerializer(serializers.ModelSerializer):
class Meta:
model = ProductImage
+ fields = ('id', 'image', 'order')
@staff_member_required
diff --git a/saleor/static/js/dashboard.js b/saleor/static/js/dashboard.js
index 735ddd4379..1ecc39b0b6 100644
--- a/saleor/static/js/dashboard.js
+++ b/saleor/static/js/dashboard.js
@@ -154,7 +154,7 @@ Dropzone.options.productImageForm = {
maxFilesize: 20,
previewsContainer: '.product-gallery',
thumbnailWidth: 400,
- thumbnailHeight: 250,
+ thumbnailHeight: 400,
previewTemplate: $('#template').html(),
clickable: false,
init: function() {
@@ -164,7 +164,7 @@ Dropzone.options.productImageForm = {
this.on('complete', function() {
$dropzoneGhost.remove().appendTo($gallery);
}).on('success', function(e, response) {
- $(e.previewElement).find('.product-gallery-item-desc').html(e.name);
+ $(e.previewElement).find('.product-gallery-item-desc').html(response.image);
$(e.previewElement).attr('data-id', response.id);
let editLinkHref = $(e.previewElement).find('.card-action-edit').attr('href');
editLinkHref = editLinkHref.split('/');
diff --git a/saleor/static/scss/dashboard/widget/_dropzone.scss b/saleor/static/scss/dashboard/widget/_dropzone.scss
index 0217300bfd..2e5c5d3bb3 100644
--- a/saleor/static/scss/dashboard/widget/_dropzone.scss
+++ b/saleor/static/scss/dashboard/widget/_dropzone.scss
@@ -8,7 +8,7 @@
cursor: initial;
}
- & li.dropzone-ghost {
+ & div.dropzone-ghost {
display: none;
opacity: .75;
}
@@ -24,7 +24,7 @@
top: 0;
}
- li.dropzone-ghost {
+ div.dropzone-ghost {
display: block;
}
}
diff --git a/saleor/static/scss/dashboard/widget/_product-gallery.scss b/saleor/static/scss/dashboard/widget/_product-gallery.scss
index adb6920d05..2cac5b51db 100644
--- a/saleor/static/scss/dashboard/widget/_product-gallery.scss
+++ b/saleor/static/scss/dashboard/widget/_product-gallery.scss
@@ -1,5 +1,5 @@
@mixin product-gallery {
- & &-item {
+ &-item {
margin: 0 $gutter-width/2 $gutter-width !important;
padding: 0;
display: block;
diff --git a/templates/dashboard/product/product_form.html b/templates/dashboard/product/product_form.html
index b2a63270b5..cfcac011a0 100644
--- a/templates/dashboard/product/product_form.html
+++ b/templates/dashboard/product/product_form.html
@@ -293,49 +293,52 @@
<div class="dz-message"></div>
{% csrf_token %}
<input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">
- <ul class="row product-gallery" id="product-gallery" data-post-url="{% url 'dashboard:product-images-reorder' product_pk=product.pk %}">
- {% if images %}
- {% for image in images %}
- <li class="col s6 m3 card product-gallery-item" data-id="{{ image.pk }}">
- <div class="card-image product-gallery-item-image">
- <img class="responsive-img" src="{{ image.image.crop.400x400 }}" alt="">
- </div>
-
- <div class="card-content">
- <span class="product-gallery-item-title card-title black-text" title="{{ image.alt }}">
- {% if image.alt %}
- {{ image.alt }}
- {% else %}
- <span class="grey-text">{% trans "No description" %}</span>
- {% endif %}
- </span>
- <span class="product-gallery-item-desc" title="{{ image.image.name }}">{{ image.image.name }}</span>
- </div>
-
- <div class="card-action">
- <a href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=image.pk %}">
- {% trans "Edit" %}
- </a>
-
- <a href="#base-modal" class="modal-trigger-custom"
- data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">
- {% trans "Delete" %}
- </a>
- </div>
- <div class="sortable__drag-area"></div>
- </li>
- {% endfor %}
- {% else %}
- <p class="no-images">{% trans "This product has no images yet." %}</p>
- {% endif %}
- <li class="col s6 m3 card product-gallery-item dropzone-ghost">
+ <div class="row ">
+ <ul class="product-gallery" id="product-gallery" data-post-url="{% url 'dashboard:product-images-reorder' product_pk=product.pk %}">
+ {% if images %}
+ {% for image in images %}
+ <li class="col s6 m3 card product-gallery-item" data-id="{{ image.pk }}">
+ <div class="card-image product-gallery-item-image">
+ <img class="responsive-img" src="{{ image.image.crop.400x400 }}" alt="">
+ </div>
+
+ <div class="card-content">
+ <span class="product-gallery-item-title card-title black-text" title="{{ image.alt }}">
+ {% if image.alt %}
+ {{ image.alt }}
+ {% else %}
+ <span class="grey-text">{% trans "No description" %}</span>
+ {% endif %}
+ </span>
+ <span class="product-gallery-item-desc" title="{{ image.image.name }}">{{ image.image.name }}</span>
+ </div>
+
+ <div class="card-action">
+ <a href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=image.pk %}">
+ {% trans "Edit" %}
+ </a>
+
+ <a href="#base-modal" class="modal-trigger-custom"
+ data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">
+ {% trans "Delete" %}
+ </a>
+ </div>
+ <div class="sortable__drag-area"></div>
+ </li>
+ {% endfor %}
+ {% else %}
+ <p class="no-images">{% trans "This product has no images yet." %}</p>
+ {% endif %}
+
+ </ul>
+ <div class="col s6 m3 card product-gallery-item dropzone-ghost">
<div class="card-content">
<span class="product-gallery-item-title product-gallery-item-title--noclip card-title black-text">
<span class="grey-text">{% trans "Drop images here to upload" %}</span>
</span>
</div>
- </li>
- </ul>
+ </div>
+ </div>
</form>
</div>
</div>
@@ -370,6 +373,7 @@
&nbsp;
</div>
+ <div class="sortable__drag-area"></div>
</li>
</script>
</div>