mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor edit and delete views for ManufacturerPart
This commit is contained in:
parent
0c91691ed2
commit
0288a1acbf
@ -284,22 +284,8 @@
|
||||
|
||||
$("#manufacturer-part-create").click(function () {
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
||||
fields: {
|
||||
part: {},
|
||||
manufacturer: {
|
||||
value: {{ company.pk }},
|
||||
},
|
||||
MPN: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
description: {},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
},
|
||||
method: 'POST',
|
||||
title: '{% trans "Add Manufacturer Part" %}',
|
||||
createManufacturerPart({
|
||||
manufacturer: {{ company.pk }},
|
||||
onSuccess: function() {
|
||||
$("#part-table").bootstrapTable("refresh");
|
||||
}
|
||||
|
@ -297,29 +297,19 @@ $('#order-part, #order-part2').click(function() {
|
||||
|
||||
$('#edit-part').click(function () {
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
||||
fields: {
|
||||
part: {},
|
||||
manufacturer: {},
|
||||
MPN: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
description: {},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
},
|
||||
title: '{% trans "Edit Manufacturer Part" %}',
|
||||
reload: true,
|
||||
editManufacturerPart({{ part.pk }}, {
|
||||
onSuccess: function() {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#delete-part').click(function() {
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Manufacturer Part" %}',
|
||||
redirect: "{% url 'company-detail' part.manufacturer.id %}",
|
||||
deleteManufacturerPart({{ part.pk }}, {
|
||||
onSuccess: function() {
|
||||
window.location.href = "{% url 'company-detail' part.manufacturer.id %}";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -880,19 +880,8 @@
|
||||
|
||||
$('#manufacturer-create').click(function () {
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
||||
fields: {
|
||||
part: {
|
||||
value: {{ part.pk }},
|
||||
hidden: true,
|
||||
},
|
||||
manufacturer: {},
|
||||
MPN: {},
|
||||
description: {},
|
||||
link: {},
|
||||
},
|
||||
method: 'POST',
|
||||
title: '{% trans "Add Manufacturer Part" %}',
|
||||
createManufacturerPart({
|
||||
part: {{ part.pk }},
|
||||
onSuccess: function() {
|
||||
$("#manufacturer-part-table").bootstrapTable("refresh");
|
||||
}
|
||||
|
@ -1,6 +1,65 @@
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
function manufacturerPartFields() {
|
||||
|
||||
return {
|
||||
part: {},
|
||||
manufacturer: {},
|
||||
MPN: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
description: {},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function createManufacturerPart(options={}) {
|
||||
|
||||
var fields = manufacturerPartFields();
|
||||
|
||||
if (options.part) {
|
||||
fields.part.value = options.part;
|
||||
fields.part.hidden = true;
|
||||
}
|
||||
|
||||
if (options.manufacturer) {
|
||||
fields.manufacturer.value = options.manufacturer;
|
||||
}
|
||||
|
||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
||||
fields: fields,
|
||||
method: 'POST',
|
||||
title: '{% trans "Add Manufacturer Part" %}',
|
||||
onSuccess: options.onSuccess
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function editManufacturerPart(part, options={}) {
|
||||
|
||||
var url = `/api/company/part/manufacturer/${part}/`;
|
||||
|
||||
constructForm(url, {
|
||||
fields: manufacturerPartFields(),
|
||||
title: '{% trans "Edit Manufacturer Part" %}',
|
||||
onSuccess: options.onSuccess
|
||||
});
|
||||
}
|
||||
|
||||
function deleteManufacturerPart(part, options={}) {
|
||||
|
||||
constructForm(`/api/company/part/manufacturer/${part}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Manufacturer Part" %}',
|
||||
onSuccess: options.onSuccess,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function supplierPartFields() {
|
||||
|
||||
return {
|
||||
@ -400,8 +459,52 @@ function loadManufacturerPartTable(table, url, options) {
|
||||
title: '{% trans "Description" %}',
|
||||
sortable: false,
|
||||
switchable: true,
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
title: '',
|
||||
sortable: false,
|
||||
switchable: false,
|
||||
formatter: function(value, row) {
|
||||
var pk = row.pk;
|
||||
|
||||
var html = `<div class='btn-group float-right' role='group'>`;
|
||||
|
||||
html += makeIconButton('fa-edit icon-blue', 'button-manufacturer-part-edit', pk, '{% trans "Edit manufacturer part" %}');
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-manufacturer-part-delete', pk, '{% trans "Delete manufacturer part" %}');
|
||||
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
||||
],
|
||||
onPostBody: function() {
|
||||
// Callbacks
|
||||
$(table).find('.button-manufacturer-part-edit').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
editManufacturerPart(
|
||||
pk,
|
||||
{
|
||||
onSuccess: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(table).find('.button-manufacturer-part-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
deleteManufacturerPart(
|
||||
pk,
|
||||
{
|
||||
onSuccess: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -659,7 +762,7 @@ function loadSupplierPartTable(table, url, options) {
|
||||
var html = `<div class='btn-group float-right' role='group'>`;
|
||||
|
||||
html += makeIconButton('fa-edit icon-blue', 'button-supplier-part-edit', pk, '{% trans "Edit supplier part" %}');
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-supplier-part-delete', pk, '{% trans "Delete manufacturer part" %}');
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-supplier-part-delete', pk, '{% trans "Delete supplier part" %}');
|
||||
|
||||
html += '</div>';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user