Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix product image dropzone
weronka74958813c9e5
diff --git a/saleor/static/js/dashboard.js b/saleor/static/js/dashboard.jsindex af41343671..bf0dc1ca7f 100644--- a/saleor/static/js/dashboard.js+++ b/saleor/static/js/dashboard.js@@ -6,6 +6,23 @@ import Sortable from 'sortablejs'import '../scss/dashboard.scss'+function openModal() {+ $('.modal-trigger-custom').on('click', function (e) {+ var that = this+ $.ajax({+ url: $(this).data('href'),+ method: 'get',+ success: function (response) {+ var $modal = $($(that).attr('href'))+ $modal.html(response)+ initSelects()+ $modal.openModal()+ }+ })++ e.preventDefault()+ })+}$(document).ready(function() {initSelects()@@ -27,23 +44,7 @@ $(document).ready(function() {$tabs.find('a.active').parent().click()}-- $('.modal-trigger-custom').on('click', function (e) {- var that = this- $.ajax({- url: $(this).data('href'),- method: 'get',- success: function (response) {- var $modal = $($(that).attr('href'))- $modal.html(response)- initSelects()- $modal.openModal()- }- })-- e.preventDefault()- })-+ openModal()var $messages = $('.message')var timeout = 0var offset = 100@@ -114,11 +115,13 @@ Dropzone.options.productImageForm = {editLinkHref[editLinkHref.length - 2] = response.id$(e.previewElement).find('.card-action-edit').attr('href', editLinkHref.join('/'))$(e.previewElement).find('.card-action-edit').show()- var deleteLinkHref = $(e.previewElement).find('.card-action-delete').attr('href')+ var deleteLinkHref = $(e.previewElement).find('.card-action-delete').attr('data-href')deleteLinkHref = deleteLinkHref.split('/')deleteLinkHref[deleteLinkHref.length - 3] = response.id- $(e.previewElement).find('.card-action-delete').attr('href', deleteLinkHref.join('/'))+ $(e.previewElement).find('.card-action-delete').attr('data-href', deleteLinkHref.join('/'))$(e.previewElement).find('.card-action-delete').show()+ $('.no-images').addClass('hide')+ openModal()})}}diff --git a/templates/dashboard/product/product_form.html b/templates/dashboard/product/product_form.htmlindex e4c2d7ef51..cf8cf77856 100644--- a/templates/dashboard/product/product_form.html+++ b/templates/dashboard/product/product_form.html@@ -273,16 +273,15 @@</form></div>- <div id="images" class="tab-content">- {% if images %}+ <div id="images" class="tab-content"><div class="row"><div class="col l12"><form action="{% url 'dashboard:product-images-upload' product_pk=product.pk %}" class="dropzone" id="product-image-form"><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">@@ -312,7 +311,9 @@</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="card-content"><span class="product-gallery-item-title product-gallery-item-title--noclip card-title black-text">@@ -323,13 +324,10 @@</ul></form></div>- </div>- {% else %}- <p>{% trans "This product has no images yet." %}</p>- {% endif %}+ </div><script type="application/template" id="template">- <li class="col s6 m3 card product-gallery-item dz-preview dz-file-preview">+ <li class="col s6 m3 card product-gallery-item dz-preview dz-file-preview" data-id="{{ image.pk }}"><div class="card-image product-gallery-item-image"><img data-dz-thumbnail /></div>@@ -348,11 +346,11 @@</div><div class="card-action">- <a class="card-action-edit" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=0 %}" hidden>+ <a class="card-action-edit" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=0 %}">{% trans "Edit" %}</a>- <a class="card-action-delete" href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=0 %}" hidden>+ <a href="#base-modal" class="card-action-delete modal-trigger-custom" data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=0 %}">{% trans "Delete" %}</a>