From f199feb8d90ad2aa2d3a426c5468f2c358ef78c7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 23 Jun 2021 08:34:45 +1000 Subject: [PATCH] Use the part detail API for uploading a new image --- InvenTree/InvenTree/static/script/inventree/api.js | 2 +- InvenTree/InvenTree/static/script/inventree/inventree.js | 4 +++- InvenTree/part/templates/part/part_base.html | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/api.js b/InvenTree/InvenTree/static/script/inventree/api.js index 52aba80ef5..b43bcc8419 100644 --- a/InvenTree/InvenTree/static/script/inventree/api.js +++ b/InvenTree/InvenTree/static/script/inventree/api.js @@ -58,7 +58,7 @@ function inventreeFormDataUpload(url, data, options={}) { xhr.setRequestHeader('X-CSRFToken', csrftoken); }, url: url, - method: 'POST', + method: options.method || 'POST', data: data, processData: false, contentType: false, diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 1a6fdec47a..79e02d7da5 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -219,6 +219,7 @@ function enableDragAndDrop(element, url, options) { data - Other form data to upload success - Callback function in case of success error - Callback function in case of error + method - HTTP method */ data = options.data || {}; @@ -254,7 +255,8 @@ function enableDragAndDrop(element, url, options) { if (options.error) { options.error(xhr, status, error); } - } + }, + method: options.method || 'POST', } ); } else { diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 7e1d33bdea..6bb1320e5a 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -239,9 +239,10 @@ enableDragAndDrop( '#part-thumb', - "{% url 'part-image-upload' part.id %}", + "{% url 'api-part-detail' part.id %}", { label: 'image', + method: 'PATCH', success: function(data, status, xhr) { location.reload(); }