Skip to content

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

Move category edit to separate view

Paweł Kowalewski4cedcc166b09
diff --git a/saleor/dashboard/category/urls.py b/saleor/dashboard/category/urls.py
index 739557ef0b..629a45d69e 100644
--- a/saleor/dashboard/category/urls.py
+++ b/saleor/dashboard/category/urls.py
@@ -11,6 +11,8 @@ urlpatterns = [
views.category_create, name='category-add'),
url(r'^(?P<root_pk>[0-9]+)/add/$',
views.category_create, name='category-add'),
+ url(r'^(?P<root_pk>[0-9]+)/edit/$',
+ views.category_edit, name='category-edit'),
url(r'^(?P<pk>[0-9]+)/delete/$',
views.category_delete, name='category-delete')
]
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 272dfc2c31..550687864f 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -50,6 +50,26 @@ def category_create(request, root_pk=None):
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
+@staff_member_required
+def category_edit(request, root_pk=None):
+ category = get_object_or_404(Category, pk=root_pk)
+ form = CategoryForm(request.POST or None, instance=category,
+ initial={'parent': category.parent_id})
+ status = 200
+ if form.is_valid():
+ category = form.save()
+ messages.success(request, _('Added category %s') % category)
+ if root_pk:
+ return redirect('dashboard:category-children-list', root_pk=root_pk)
+ else:
+ return redirect('dashboard:category-root-list')
+ elif form.errors:
+ status = 400
+ ctx = {'category': category, 'form': form, 'status': status}
+ template = 'dashboard/category/modal_edit.html'
+ return TemplateResponse(request, template, ctx, status=status)
+
+
@staff_member_required
def category_delete(request, pk):
category = get_object_or_404(Category, pk=pk)
diff --git a/saleor/dashboard/templates/dashboard/base.html b/saleor/dashboard/templates/dashboard/base.html
index 4bc103bfe8..8d71b288aa 100644
--- a/saleor/dashboard/templates/dashboard/base.html
+++ b/saleor/dashboard/templates/dashboard/base.html
@@ -96,6 +96,8 @@
</main>
<div class="hide-on-large-only"></div>
+ <div id="base-modal" class="modal"></div>
+ <div id="base-modal-fixed" class="modal modal-fixed-footer"></div>
<!-- Core Scripts - Include with every page -->
<script src="{% static "js/dashboard.js" %}"></script>
diff --git a/saleor/dashboard/templates/dashboard/category/list.html b/saleor/dashboard/templates/dashboard/category/list.html
index 57c3c9f5a1..c44a2c77df 100644
--- a/saleor/dashboard/templates/dashboard/category/list.html
+++ b/saleor/dashboard/templates/dashboard/category/list.html
@@ -34,7 +34,7 @@
</a>
<ul id="category-delete" class="dropdown-content">
<li>
- <a class="modal-trigger" href="#modal-category-edit">
+ <a class="modal-trigger-custom" data-href="{% url 'dashboard:category-edit' root_pk=root.pk %}" href="#base-modal">
{% trans "Edit category" %}
</a>
</li>
@@ -54,7 +54,11 @@
{% if path %}
{% for node in path %}
{% if forloop.last %}
- <li title="{{ node.name }}"><span class="breadcrumbs--ellipsed-item">{{ node.name }}</span></li>
+ <li title="{{ node.name }}">
+ <span class="breadcrumbs--ellipsed-item">
+ {{ node.name }}
+ </span>
+ </li>
{% else %}
<li>
<a title="{{ node.name }}" href="{% url 'dashboard:category-children-list' root_pk=node.pk %}">
@@ -108,7 +112,7 @@
{% if root %}
<div id="modal-category-delete" class="modal">
- <form action="{% url "dashboard:category-delete" pk=root.pk %}" method="post">
+ <form action="{% url "dashboard:category-delete" pk=root.pk %}" method="post" class="form-async">
{% csrf_token %}
<div class="modal-content">
<h5>{% trans "Are you sure?" %}</h5>
@@ -125,27 +129,4 @@
</form>
</div>
{% endif %}
-
- {% if form %}
- <div id="modal-category-edit" class="modal">
- <form method="post" id="form-category" enctype="multipart/form-data">
- {% csrf_token %}
- <div class="modal-content">
- <h5>{% trans "Edit" %} {{ root }}</h5>
-
- <div class="row">
- {{ form.parent }}
- {{ form.name|materializecss:"s8 m10" }}
- {{ form.hidden|materializecss:"s4 m2" }}
- {{ form.description|materializecss }}
- </div>
- </div>
-
- <div class="modal-footer">
- <button type="submit" class="modal-action btn-flat blue-text">{% trans "Update" %}</button>
- <a href="#!" class="modal-action modal-close btn-flat blue-text">{% trans "Cancel" %}</a>
- </div>
- </form>
- </div>
- {% endif %}
{% endblock %}
diff --git a/saleor/dashboard/templates/dashboard/category/modal_edit.html b/saleor/dashboard/templates/dashboard/category/modal_edit.html
new file mode 100644
index 0000000000..b22e245fbe
--- /dev/null
+++ b/saleor/dashboard/templates/dashboard/category/modal_edit.html
@@ -0,0 +1,22 @@
+{% load materializecss %}
+{% load i18n %}
+{% load mptt_tags %}
+
+<form method="post" id="form-category" class="form-async" action="{% url 'dashboard:category-edit' root_pk=category.pk %}">
+ {% csrf_token %}
+ <div class="modal-content">
+ <h5>{% trans "Edit" %} {{ category }}</h5>
+
+ <div class="row">
+ {{ form.parent }}
+ {{ form.name|materializecss:"s8 m10" }}
+ {{ form.hidden|materializecss:"s4 m2" }}
+ {{ form.description|materializecss }}
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <button type="submit" class="modal-action btn-flat blue-text">{% trans "Update" %}</button>
+ <a href="#!" class="modal-action modal-close btn-flat blue-text">{% trans "Cancel" %}</a>
+ </div>
+</form>
diff --git a/saleor/dashboard/templates/dashboard/includes/_orders_table.html b/saleor/dashboard/templates/dashboard/includes/_orders_table.html
index 8e8830cbb8..3c4da12885 100644
--- a/saleor/dashboard/templates/dashboard/includes/_orders_table.html
+++ b/saleor/dashboard/templates/dashboard/includes/_orders_table.html
@@ -17,7 +17,7 @@
{% for order in orders %}
<tr>
<td>
- <a href="{% url 'dashboard:order-details' pk=order.pk %}">#{{ order.id }}</a>
+ <a href="{% url 'dashboard:order-details' order_pk=order.pk %}">#{{ order.id }}</a>
</td>
<td>{% render_status order.status order.get_status_display %}</td>
<td>{% render_status order.get_last_payment_status order.get_last_payment_status_display %}</td>
diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.html
index 97466d3f15..d86c9cad09 100644
--- a/saleor/dashboard/templates/dashboard/order/detail.html
+++ b/saleor/dashboard/templates/dashboard/order/detail.html
@@ -302,7 +302,4 @@
</tbody>
</table>
</div>
-
- <div id="base-modal" class="modal"></div>
- <div id="base-modal-fixed" class="modal modal-fixed-footer"></div>
{% endblock %}
diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.js
index 52a1cfa92d..103ae2f8cb 100644
--- a/saleor/static/js_src/dashboard.js
+++ b/saleor/static/js_src/dashboard.js
@@ -1,8 +1,9 @@
-$('.button-collapse').sideNav();
$(document).ready(function() {
- var $tabs = $('ul.tabs');
initSelects();
+ $('.button-collapse').sideNav();
+ $('.modal-trigger').leanModal();
+ var $tabs = $('ul.tabs');
if ($tabs.length) {
$tabs.find('.tab').on('click', function (e) {
window.history.pushState(null, null, e.target.hash);
diff --git a/saleor/static/scss/widget/_breadcrumbs.scss b/saleor/static/scss/widget/_breadcrumbs.scss
index 80a5d635ba..d0f78cc7a3 100644
--- a/saleor/static/scss/widget/_breadcrumbs.scss
+++ b/saleor/static/scss/widget/_breadcrumbs.scss
@@ -48,6 +48,10 @@
vertical-align: bottom;
}
}
+
+ [class^=mdi-] {
+ display: inline;
+ }
}
&--with-menu {
@@ -59,7 +63,7 @@
}
&--ellipsed {
- li span {
+ &-item {
@media (min-width: $large-screen) {
display: inline-block;
}
diff --git a/saleor/static/scss/widget/_list.scss b/saleor/static/scss/widget/_list.scss
index a7b1eef918..89ecf32d50 100644
--- a/saleor/static/scss/widget/_list.scss
+++ b/saleor/static/scss/widget/_list.scss
@@ -47,6 +47,7 @@
&-name {
display: block;
overflow: hidden;
+ padding-right: 20px;
text-overflow: ellipsis;
white-space: nowrap;