Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add Dropzone for product images
Paweł Kowalewski6ea66ed70e8d
diff --git a/Gruntfile.js b/Gruntfile.jsindex 07baad4dae..04f29af3a8 100644--- a/Gruntfile.js+++ b/Gruntfile.js@@ -170,7 +170,7 @@ module.exports = function(grunt) {},sass: {files: ["saleor/static/scss/**/*.scss"],- tasks: ["sass", "postcss"]+ tasks: ["sass", "concat", "postcss"]},uglify: {files: ["saleor/static/js_src/**/*.js"],diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.htmlindex c9bca60d91..f490cf846f 100644--- a/saleor/dashboard/templates/dashboard/product/product_form.html+++ b/saleor/dashboard/templates/dashboard/product/product_form.html@@ -234,10 +234,6 @@{% csrf_token %}<input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">- <div class="fallback">- <input name="image_0" type="file" multiple />- </div>-<ul class="row product-gallery" id="product-gallery" data-post-url="{{ images_reorder_url }}">{% for image in images %}<li class="col s6 m3 card product-gallery-item" data-id="{{ image.pk }}">@@ -261,12 +257,65 @@{% trans "Edit" %}</a>- <a href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">+ <a href="#modal-product-image-delete-{{ image.pk }}" class="modal-trigger">{% trans "Delete" %}</a>++ <div class="modal" id="modal-product-image-delete-{{ image.pk }}">+ <form action="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}" method="post">+ {% csrf_token %}+ <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">++ <div class="modal-content">+ <h5>{% trans "Are you sure?" %}</h5>++ <img class="responsive-img" src="{{ image.image.crop.400x250 }}" alt="">++ <p>+ {% blocktrans %}You are about to delete an image.{% endblocktrans %}+ </p>+ </div>++ <div class="modal-footer">+ <button type="submit" class="modal-action waves-effect waves-green btn-flat blue-text">{% trans "Yes" %}</button>+ <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat blue-text">{% trans "No" %}</a>+ </div>+ </form>+ </div></div></li>{% endfor %}++ <li class="col s6 m3 card product-gallery-item dropzone-ghost">+ <div class="card-image product-gallery-item-image--ghost">+ {% trans "New image" %}+ </div>++ <div class="dz-progress">+ <span class="dz-upload" data-dz-uploadprogress></span>+ </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">filename</span>+ </div>++ <div class="card-action">+ <a href="#">+ {% trans "Edit" %}+ </a>++ <a href="#">+ {% trans "Delete" %}+ </a>+ </div>+ </li></ul></form></div>@@ -276,10 +325,59 @@{% endif %}<script type="application/template" id="template">- <li class="col s6 m3 card product-gallery-item" data-id="{{ image.pk }}">+{# <div class="dz-preview dz-file-preview">#}+{# <div class="dz-image">#}+{# <img data-dz-thumbnail />#}+{# </div>#}+{##}+{# <div class="dz-details">#}+{# <div class="dz-size">#}+{# <span data-dz-size></span>#}+{# </div>#}+{##}+{# <div class="dz-filename">#}+{# <span data-dz-name></span>#}+{# </div>#}+{# </div>#}+{##}+{# <div class="dz-progress">#}+{# <span class="dz-upload" data-dz-uploadprogress></span>#}+{# </div>#}+{##}+{# <div class="dz-error-message">#}+{# <span data-dz-errormessage></span>#}+{# </div>#}+{##}+{# <div class="dz-success-mark">#}+{# <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"#}+{# xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">#}+{# <title>Check</title>#}+{# <defs></defs>#}+{# <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">#}+{# <path d="M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" stroke-opacity="0.198794158" stroke="#747474" fill-opacity="0.816519475" fill="#FFFFFF" sketch:type="MSShapeGroup"></path>#}+{# </g>#}+{# </svg>#}+{# </div>#}+{##}+{# <div class="dz-error-mark">#}+{# <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">#}+{# <title>Error</title>#}+{# <defs></defs>#}+{# <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">#}+{# <g id="Check-+-Oval-2" sketch:type="MSLayerGroup" stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">#}+{# <path d="M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" sketch:type="MSShapeGroup"></path>#}+{# </g>#}+{# </g>#}+{# </svg>#}+{# </div>#}+{# </div>#}+ <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 />-{# <img class="responsive-img" src="{{ image.image.crop.400x250 }}" alt="">#}+ </div>++ <div class="dz-progress">+ <span class="dz-upload" data-dz-uploadprogress></span></div><div class="card-content">@@ -290,24 +388,22 @@<span class="grey-text">{% trans "No description" %}</span>{% endif %}</span>- <span class="product-gallery-item-desc">{{ image.image.name }}</span>+ <span class="product-gallery-item-desc">filename</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="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">#}-{# {% trans "Delete" %}#}-{# </a>#}+ <a href="#">+ {% trans "Edit" %}+ </a>++ <a href="#">+ {% trans "Delete" %}+ </a></div></li></script></div>--<div class="fixed-action-btn"><a class="btn-fab btn-fab-hidden btn-floating btn-large waves-effect waves-light teal" id="images-btn"href="{% url 'dashboard:product-image-add' product_pk=product.pk %}" title="{% trans "Add image" %}">diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.jsindex 9447d87ad5..449ac79fa2 100644--- a/saleor/static/js_src/dashboard.js+++ b/saleor/static/js_src/dashboard.js@@ -16,6 +16,22 @@ $(document).ready(function() {$tabs.find('a.active').parent().click();}});+Dropzone.options.productImageForm = {+ paramName: "image_0",+ maxFilesize: 20,+ previewsContainer: ".product-gallery",+ thumbnailWidth: 400,+ thumbnailHeight: 250,+ previewTemplate: $("#template").html(),+ init: function() {+ var $dropzoneGhost = $('.dropzone-ghost');+ var $gallery = $('.product-gallery');++ this.on('complete', function() {+ $dropzoneGhost.remove().appendTo($gallery);+ });+ }+};var el = document.getElementById('product-gallery');if (el) {var sortable = Sortable.create(el, {diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scssindex 27d7480764..5115e32b1d 100644--- a/saleor/static/scss/_app.scss+++ b/saleor/static/scss/_app.scss@@ -281,20 +281,12 @@ table {width: 100%;}}-- .card-action {- button {- @extend a;- background: none;- border: none;- padding: 0;- }- }}@import "widget/breadcrumbs";@import "widget/category-list";@import "widget/data-table";+@import "widget/dropzone";@import "widget/form";@import "widget/product-gallery";@import "widget/product-list";diff --git a/saleor/static/scss/widget/_dropzone.scss b/saleor/static/scss/widget/_dropzone.scssnew file mode 100644index 0000000000..35c4bd6fab--- /dev/null+++ b/saleor/static/scss/widget/_dropzone.scss@@ -0,0 +1,28 @@+@mixin dropzone {+ height: 82vh;+ position: relative;++ & li.dropzone-ghost {+ display: none;+ opacity: .75;+ }++ &.dz-drag-hover {+ &:after {+ position: absolute;+ top: 0;+ bottom: 0;+ left: 0;+ right: 0;+ content: "";+ }++ li.dropzone-ghost {+ display: block;+ }+ }+}++.dropzone {+ @include dropzone;+}diff --git a/saleor/static/scss/widget/_product-gallery.scss b/saleor/static/scss/widget/_product-gallery.scssindex 3287725fa2..ad5844e5d0 100644--- a/saleor/static/scss/widget/_product-gallery.scss+++ b/saleor/static/scss/widget/_product-gallery.scss@@ -20,6 +20,12 @@&-image {cursor: move;++ &--ghost {+ background: map_get($grey, lighten-5);+ padding: 61px 0 60px;+ text-align: center;+ }}&-title, &-desc {