Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Toggle publish product by post request
Anna Siwik455a5db45d9d
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 0c985c8829..d62c99e302 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -178,6 +178,7 @@ def product_detail(request, pk):return TemplateResponse(request, 'dashboard/product/detail.html', ctx)+@require_POST@staff_member_required@permission_required('product.edit_product')def product_toggle_is_published(request, pk):diff --git a/saleor/static/dashboard/js/components/misc.js b/saleor/static/dashboard/js/components/misc.jsindex 8b9a379cc9..f42a241cf6 100644--- a/saleor/static/dashboard/js/components/misc.js+++ b/saleor/static/dashboard/js/components/misc.js@@ -20,11 +20,16 @@ export default $(document).ready((e) => {});$('#product-is-published').on('click', (e) => {- const input = $(e.currentTarget).find('input')[0];+ const form = $(e.currentTarget).closest('form');+ const input = form.find('input')[0];if (e.target === input) {- const url = $(e.currentTarget).attr('data-url');+ const url = form.attr('action');fetch(url, {- credentials: 'same-origin'+ method: 'POST',+ credentials: 'same-origin',+ headers: {+ 'X-CSRFToken': $('[name=csrfmiddlewaretoken]').val()+ }}).then((r) => {return r.json();}).then((r) => {diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.htmlindex 4a65eeecb6..761083f285 100644--- a/templates/dashboard/product/detail.html+++ b/templates/dashboard/product/detail.html@@ -162,19 +162,22 @@<div class="col s12"><div class="card"><div class="card-content">- <div class="switch" id="product-is-published" data-url="{% url 'dashboard:product-publish' product.pk %}">- <label>- <input type="checkbox" {% if product.is_published %} checked {% endif %}>- <span class="lever"></span>- <span class="label">- {% if product.is_published %}- {% trans "Published" context "Product field" %}- {% else %}- {% trans "Draft" context "Product field" %}- {% endif %}- </span>- </label>- </div>+ <form action="{% url 'dashboard:product-publish' product.pk %}">+ <div class="switch" id="product-is-published">+ <label>+ <input type="checkbox" {% if product.is_published %} checked {% endif %}>+ <span class="lever"></span>+ <span class="label">+ {% if product.is_published %}+ {% trans "Published" context "Product field" %}+ {% else %}+ {% trans "Draft" context "Product field" %}+ {% endif %}+ </span>+ </label>+ </div>+ {% csrf_token %}+ </form><h5>{% render_availability_status product %}</h5></div></div>