diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index c8130055b7..e5c23b730a 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -53,6 +53,7 @@ class PartSerializer(serializers.ModelSerializer): class Meta: model = Part + partial = True fields = [ 'pk', 'url', # Link to the part detail page diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 2a8db4421a..7b148318c9 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -146,6 +146,33 @@ }); }); + $('#activate-part').click(function() { + inventreeUpdate( + "{% url 'api-part-detail' part.id %}", + { + active: true, + }, + { + method: 'PATCH', + reloadOnSuccess: true, + } + ); + }); + + $('#deactivate-part').click(function() { + inventreeUpdate( + "{% url 'api-part-detail' part.id %}", + { + active: false, + }, + { + method: 'PATCH', + reloadOnSuccess: true, + } + ); + }); + + $('#delete-part').click(function() { launchDeleteForm( "{% url 'part-delete' part.id %}", diff --git a/InvenTree/static/script/inventree/api.js b/InvenTree/static/script/inventree/api.js index fab1450a00..530e816f68 100644 --- a/InvenTree/static/script/inventree/api.js +++ b/InvenTree/static/script/inventree/api.js @@ -47,11 +47,7 @@ function inventreeUpdate(url, data={}, options={}) { data["_is_final"] = true; } - var method = 'put'; - - if ('method' in options) { - method = options.method; - } + var method = options.method || 'PUT'; // Middleware token required for data update //var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val(); @@ -69,12 +65,21 @@ function inventreeUpdate(url, data={}, options={}) { success: function(response, status) { response['_status_code'] = status; console.log('UPDATE object to ' + url + ' - result = ' + status); + if (options.success) { + options.success(response, status); + } + if (options.reloadOnSuccess) { + location.reload(); + } }, error: function(xhr, ajaxOptions, thrownError) { console.error('Error on UPDATE to ' + url); console.error(thrownError); + if (options.error) { + options.error(xhr, ajaxOptions, thrownError); } - }); + } + }); } // Return list of parts with optional filters