mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Use API to mark part as active/inactive
This commit is contained in:
parent
492d705b39
commit
73f672495d
@ -53,6 +53,7 @@ class PartSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
|
partial = True
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
'url', # Link to the part detail page
|
'url', # Link to the part detail page
|
||||||
|
@ -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() {
|
$('#delete-part').click(function() {
|
||||||
launchDeleteForm(
|
launchDeleteForm(
|
||||||
"{% url 'part-delete' part.id %}",
|
"{% url 'part-delete' part.id %}",
|
||||||
|
@ -47,11 +47,7 @@ function inventreeUpdate(url, data={}, options={}) {
|
|||||||
data["_is_final"] = true;
|
data["_is_final"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var method = 'put';
|
var method = options.method || 'PUT';
|
||||||
|
|
||||||
if ('method' in options) {
|
|
||||||
method = options.method;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Middleware token required for data update
|
// Middleware token required for data update
|
||||||
//var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
//var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||||
@ -69,12 +65,21 @@ function inventreeUpdate(url, data={}, options={}) {
|
|||||||
success: function(response, status) {
|
success: function(response, status) {
|
||||||
response['_status_code'] = status;
|
response['_status_code'] = status;
|
||||||
console.log('UPDATE object to ' + url + ' - result = ' + 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) {
|
error: function(xhr, ajaxOptions, thrownError) {
|
||||||
console.error('Error on UPDATE to ' + url);
|
console.error('Error on UPDATE to ' + url);
|
||||||
console.error(thrownError);
|
console.error(thrownError);
|
||||||
|
if (options.error) {
|
||||||
|
options.error(xhr, ajaxOptions, thrownError);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return list of parts with optional filters
|
// Return list of parts with optional filters
|
||||||
|
Loading…
x
Reference in New Issue
Block a user