Skip to content

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

Add drag and drop to product gallery

Paweł Kowalewski7ef1a3e113cf
diff --git a/Gruntfile.js b/Gruntfile.js
index b8d608be04..b1d251eb66 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -142,6 +142,7 @@ module.exports = function(grunt) {
"saleor/static/js/dashboard.js": [
"saleor/static/components/jquery/dist/jquery.js",
"saleor/static/components/materialize/dist/js/materialize.js",
+ "saleor/static/components/Sortable/Sortable.js",
"saleor/static/js_src/dashboard.js"
]
}
@@ -159,7 +160,7 @@ module.exports = function(grunt) {
tasks: ["sass", "postcss"]
},
uglify: {
- files: ["saleor/static/js/**/*.js"],
+ files: ["saleor/static/js_src/**/*.js"],
tasks: ["uglify"]
}
}
diff --git a/bower.json b/bower.json
index 866daf50d5..260eefae93 100644
--- a/bower.json
+++ b/bower.json
@@ -12,6 +12,7 @@
"components-font-awesome": "~4.3.0",
"zocial-less": "~1.0.0",
"materialize": "~0.96.1",
- "jquery": "~2.1.4"
+ "jquery": "~2.1.4",
+ "Sortable": "[email protected]:RubaXa/Sortable.git#~1.2.0"
}
}
diff --git a/saleor/dashboard/templates/dashboard/product/list.html b/saleor/dashboard/templates/dashboard/product/list.html
index 1d321e8330..b40edc3499 100644
--- a/saleor/dashboard/templates/dashboard/product/list.html
+++ b/saleor/dashboard/templates/dashboard/product/list.html
@@ -49,32 +49,6 @@
</li>
{% endfor %}
</ul>
-
- <table class="striped">
- <thead>
- <tr>
- <th colspan="2" class="col-sm-6">{% trans "Name" %}</th>
- <th class="col-sm-4">{% trans "Collection" %}</th>
- <th class="col-sm-2 right-align">{% trans "Price" %}</th>
- </tr>
- </thead>
- <tbody>
- {% for product in products %}
- <tr>
- <td class="col-sm-1">
- {% if product.images.exists %}
- <img class="img-responsive" src="{{ product.images.first.image.crop.50x50 }}" alt="">
- {% else %}
- <img class="img-responsive" src="http://placehold.it/50x50/&text=Product Image" alt="">
- {% endif %}
- </td>
- <td class="col-sm-5"><a href="{% url 'dashboard:product-update' pk=product.pk %}">{{ product.name }}</a></td>
- <td>{{ product.collection }}</td>
- <td class="text-right">{% gross product.price %}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
{% include "dashboard/includes/_pagination.html" with page_obj=products %}
</div>
</div>
diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.html
index 80d53d218d..556ae47fe3 100644
--- a/saleor/dashboard/templates/dashboard/product/product_form.html
+++ b/saleor/dashboard/templates/dashboard/product/product_form.html
@@ -1,7 +1,7 @@
{% extends "dashboard/base.html" %}
{% load prices_i18n %}
{% load i18n %}
-{% load bootstrap %}
+{% load materializecss %}
{% load static %}
{% block title %}{{ title }} - {% trans "Products" %} - {{ block.super }}{% endblock %}
@@ -9,31 +9,41 @@
{% block page_title %}{{ title }}{% endblock %}
{% block content %}
-<form class="form form-vertical" method="post" id="product-form" enctype="multipart/form-data">
- <div class="row">
- <div class="col l8">
- <div class="form-message alert alert-success" hidden="hidden">
- <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
- <span class="glyphicon glyphicon-ok-sign"></span>
- <span class="message-content">{% trans "Data saved" %}</span>
+<form method="post" id="product-form" enctype="multipart/form-data">
+ <div class="row" hidden>
+ <div class="col s12">
+ <div class="card green">
+{# <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>#}
+{# <span class="glyphicon glyphicon-ok-sign"></span>#}
+ <span class="card-content white-text">{% trans "Data saved" %}</span>
</div>
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="col s12">
+ <ul class="tabs">
+ <li class="tab col s4"><a class="active" href="#details">{% trans "Details" %}</a></li>
+ <li class="tab col s4"><a href="#variants">{% trans "Variants" %}</a></li>
+ <li class="tab col s4"><a href="#images">{% trans "Images" %}</a></li>
+ </ul>
+ </div>
+ </div>
- <div class="panel panel-default">
- <div class="panel-heading">
- <span class="panel-title">{% trans "Details" %}</span>
- </div>
- <div class="panel-body">
- {% csrf_token %}
- {{ form|as_vertical_form }}
- </div>
+ <div class="row" id="details">
+ <div class="col l12">
+ <div class="row">
+ {% csrf_token %}
+ {{ form|materializecss }}
</div>
+ </div>
+ </div>
- {{ variant_formset.management_form }}
- <div class="panel panel-default">
- <div class="panel-heading">
- <span class="panel-title">{% trans "Variants" %}</span>
- </div>
- <table class="table">
+ <div class="row" id="variants">
+ <div class="col l12">
+ <div class="row">
+ {{ variant_formset.management_form }}
+ <table class="striped">
<thead>
<tr>
<th>{% trans "SKU" %}</th>
@@ -52,13 +62,13 @@
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
- {{ form.sku|as_vertical_form:False }}
+ {{ form.sku|materializecss }}
</td>
{% for field in form.visible_fields %}
{% if field.name != 'sku' and field.name != 'DELETE' %}
<td>
<div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
- {{ field|as_vertical_form:False }}
+ {{ field|materializecss }}
{% if field.errors %}
{% for error in field.errors %}
<span class="label label-danger">{{ error }}</span>
@@ -79,13 +89,13 @@
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
- {{ form.sku|as_vertical_form:False }}
+ {{ form.sku|materializecss }}
</td>
{% for field in form.visible_fields %}
{% if field.name != 'sku' and field.name != 'DELETE' %}
<td>
<div class="{% if field.errors %} has-error{% endif %}{% if field.required %} required{% endif %}">
- {{ field|as_vertical_form:False }}
+ {{ field|materializecss }}
{% if field.errors %}
{% for error in field.errors %}
<span class="label label-danger">{{ error }}</span>
@@ -102,36 +112,45 @@
</table>
</div>
</div>
+ </div>
- <div class="col-lg-4">
- <div class="panel panel-default">
- <div class="panel-heading">
- <span class="panel-title">Product image</span>
- </div>
- <div class="panel-body">
- {% if product.images.exists %}
- <img class="img-responsive" src="{{ product.images.first.image.thumbnail.300x300 }}" alt="">
- {% else %}
- <img class="img-responsive" src="http://placehold.it/300x300/&text=Product Image" alt="">
- {% endif %}
- </div>
- </div>
+ <div class="row" id="images">
+ <div class="col l12">
+ <ul class="row product-gallery" id="product-gallery">
+ {% for image in images %}
+ <li class="col s6 m4 product-gallery-item" data-id="{{ image.pk }}">
+ <img class="responsive-img" src="{{ image.image.crop.300x300 }}" alt="">
+ {% if image.alt %}
+ <span class="product-gallery-item-text">{{ image.alt }}</span>
+ {% endif %}
+ <a class="product-gallery-item-create teal-text text-lighten-2"
+ href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=image.pk %}">
+ <i class="mdi-content-create"></i>
+ </a>
+ <a class="product-gallery-item-remove red-text"
+ href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">
+ <i class="mdi-content-remove"></i>
+ </a>
+ </li>
+ {% endfor %}
+ </ul>
</div>
</div>
+
<div class="row">
- <div class="col-lg-12">
+ <div class="col l12">
<p>
{% if product.pk %}
- <span class="pull-right">
- <a href="{% url 'dashboard:product-delete' pk=product.pk %}" class="btn btn-danger"><i class="glyphicon glyphicon-trash"></i> {% trans "Delete" %}</a>
+ <span class="right">
+ <a href="{% url 'dashboard:product-delete' pk=product.pk %}" class="btn red"><i class="mdi-content-remove"></i> {% trans "Delete" %}</a>
</span>
{% endif %}
{% if product.pk %}
- <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-refresh"></i> {% trans "Update" %}</button>
+ <button type="submit" class="btn"><i class="mdi-content-save"></i> {% trans "Update" %}</button>
{% else %}
- <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-upload"></i> {% trans "Create" %}</button>
+ <button type="submit" class="btn"><i class="mdi-content-create"></i> {% trans "Create" %}</button>
{% endif %}
- <a href="{% url 'dashboard:products' %}" class="btn btn-default"><i class="glyphicon glyphicon-remove"></i> {% trans "Cancel" %}</a>
+ <a href="{% url 'dashboard:products' %}" class="btn"><i class="mdi-content-remove"></i> {% trans "Cancel" %}</a>
</p>
</div>
</div>
diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.js
index 1d440a74a7..52da249d79 100644
--- a/saleor/static/js_src/dashboard.js
+++ b/saleor/static/js_src/dashboard.js
@@ -1,3 +1,10 @@
-$(".button-collapse").sideNav();
-$("select").material_select();
+$('.button-collapse').sideNav();
+$('select:not(.browser-default)').material_select();
$('.modal-trigger').leanModal();
+$('ul.tabs').find('.tab').on('click', function(e) {
+ window.history.pushState(null, null, e.target.hash);
+});
+var el = document.getElementById('product-gallery');
+var sortable = Sortable.create(el, {
+ onUpdate: function(e) {}
+});
diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scss
index 644d692aa7..1191de6358 100644
--- a/saleor/static/scss/_app.scss
+++ b/saleor/static/scss/_app.scss
@@ -164,6 +164,8 @@ table {
right: 0;
}
+@import "widget/product-gallery";
+
/* Global Styles */
/* ------------------------------- */
diff --git a/saleor/static/scss/widget/_product-gallery.scss b/saleor/static/scss/widget/_product-gallery.scss
new file mode 100644
index 0000000000..e8500a9f5d
--- /dev/null
+++ b/saleor/static/scss/widget/_product-gallery.scss
@@ -0,0 +1,46 @@
+@mixin product-gallery {
+ &-item {
+ cursor: move;
+ margin-bottom: $gutter-width;
+ position: relative;
+ text-align: center;
+
+ &-text {
+ background: rgba(black, .5);
+ bottom: 0;
+ color: white;
+ height: 48px;
+ line-height: 48px;
+ left: $gutter-width/2;
+ overflow: hidden;
+ padding: 0 calc(#{$gutter-width/2} + 48px) 0 $gutter-width/2;
+ position: absolute;
+ right: $gutter-width/2;
+ text-align: left;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &-create, &-remove {
+ bottom: 0;
+ font-size: 20px;
+ line-height: 48px;
+ position: absolute;
+ right: $gutter-width/2;
+ width: 48px;
+ }
+
+ &-remove {
+ bottom: auto;
+ top: 0;
+ }
+ }
+
+ .sortable-ghost {
+ opacity: .4;
+ }
+}
+
+.product-gallery {
+ @include product-gallery;
+}