Skip to content

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

Fix removing category in dashboard

Paweł Kowalewski4b3b5b95c935
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 9baa83a486..8b30c60dd4 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -1,4 +1,6 @@
from django.contrib import messages
+from django.core.urlresolvers import reverse
+from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.translation import ugettext_lazy as _
@@ -66,12 +68,19 @@ def category_delete(request, pk):
if category.parent:
root_pk = category.parent.pk
if root_pk:
+ if request.is_ajax():
+ response = {'redirectUrl': reverse(
+ 'dashboard:category-list', kwargs={'root_pk': root_pk})}
+ return JsonResponse(response)
return redirect('dashboard:category-list', root_pk=root_pk)
else:
+ if request.is_ajax():
+ response = {'redirectUrl': reverse('dashboard:category-list')}
+ return JsonResponse(response)
return redirect('dashboard:category-list')
ctx = {'category': category,
'descendants': list(category.get_descendants()),
'products_count': len(category.products.all())}
return TemplateResponse(request,
- 'dashboard/category/modal_category_confirm_delete.html',
+ 'dashboard/category/modal_delete.html',
ctx)
diff --git a/saleor/dashboard/templates/dashboard/category/modal_category_confirm_delete.html b/saleor/dashboard/templates/dashboard/category/modal_delete.html
similarity index 94%
rename from saleor/dashboard/templates/dashboard/category/modal_category_confirm_delete.html
rename to saleor/dashboard/templates/dashboard/category/modal_delete.html
index 13544e7708..9f5c5f620d 100644
--- a/saleor/dashboard/templates/dashboard/category/modal_category_confirm_delete.html
+++ b/saleor/dashboard/templates/dashboard/category/modal_delete.html
@@ -1,7 +1,7 @@
{% load i18n %}
{% load mptt_tags %}
-<form method="post" id="form-category" class="form-async" action="{% url 'dashboard:category-edit' root_pk=category.pk %}">
+<form method="post" id="form-category" class="form-async" action="{% url 'dashboard:category-delete' pk=category.pk %}">
{% csrf_token %}
<div class="modal-content">
<div class="row">
@@ -43,7 +43,7 @@
</div>
<div class="modal-footer">
- <button type="submit" class="modal-action btn-flat blue-text">{% trans "Update" %}</button>
+ <button type="submit" class="modal-action btn-flat blue-text">{% trans "Delete" %}</button>
<a href="#!" class="modal-action modal-close btn-flat blue-text">{% trans "Cancel" %}</a>
</div>
</form>
diff --git a/saleor/static/js_src/dashboard.js b/saleor/static/js_src/dashboard.js
index 422778d2fa..47901e963c 100644
--- a/saleor/static/js_src/dashboard.js
+++ b/saleor/static/js_src/dashboard.js
@@ -73,8 +73,12 @@ $(document).ready(function() {
$('.modal-close').click();
}
},
- success: function() {
- location.reload();
+ success: function(response) {
+ if (response.redirectUrl) {
+ window.location.href = response.redirectUrl;
+ } else {
+ location.reload();
+ }
}
});
e.preventDefault();