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 () {
|
$("#manufacturer-part-create").click(function () {
|
||||||
|
|
||||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
createManufacturerPart({
|
||||||
fields: {
|
manufacturer: {{ company.pk }},
|
||||||
part: {},
|
|
||||||
manufacturer: {
|
|
||||||
value: {{ company.pk }},
|
|
||||||
},
|
|
||||||
MPN: {
|
|
||||||
icon: 'fa-hashtag',
|
|
||||||
},
|
|
||||||
description: {},
|
|
||||||
link: {
|
|
||||||
icon: 'fa-link',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
method: 'POST',
|
|
||||||
title: '{% trans "Add Manufacturer Part" %}',
|
|
||||||
onSuccess: function() {
|
onSuccess: function() {
|
||||||
$("#part-table").bootstrapTable("refresh");
|
$("#part-table").bootstrapTable("refresh");
|
||||||
}
|
}
|
||||||
|
@ -297,29 +297,19 @@ $('#order-part, #order-part2').click(function() {
|
|||||||
|
|
||||||
$('#edit-part').click(function () {
|
$('#edit-part').click(function () {
|
||||||
|
|
||||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
editManufacturerPart({{ part.pk }}, {
|
||||||
fields: {
|
onSuccess: function() {
|
||||||
part: {},
|
location.reload();
|
||||||
manufacturer: {},
|
}
|
||||||
MPN: {
|
|
||||||
icon: 'fa-hashtag',
|
|
||||||
},
|
|
||||||
description: {},
|
|
||||||
link: {
|
|
||||||
icon: 'fa-link',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
title: '{% trans "Edit Manufacturer Part" %}',
|
|
||||||
reload: true,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#delete-part').click(function() {
|
$('#delete-part').click(function() {
|
||||||
|
|
||||||
constructForm('{% url "api-manufacturer-part-detail" part.pk %}', {
|
deleteManufacturerPart({{ part.pk }}, {
|
||||||
method: 'DELETE',
|
onSuccess: function() {
|
||||||
title: '{% trans "Delete Manufacturer Part" %}',
|
window.location.href = "{% url 'company-detail' part.manufacturer.id %}";
|
||||||
redirect: "{% url 'company-detail' part.manufacturer.id %}",
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -880,19 +880,8 @@
|
|||||||
|
|
||||||
$('#manufacturer-create').click(function () {
|
$('#manufacturer-create').click(function () {
|
||||||
|
|
||||||
constructForm('{% url "api-manufacturer-part-list" %}', {
|
createManufacturerPart({
|
||||||
fields: {
|
part: {{ part.pk }},
|
||||||
part: {
|
|
||||||
value: {{ part.pk }},
|
|
||||||
hidden: true,
|
|
||||||
},
|
|
||||||
manufacturer: {},
|
|
||||||
MPN: {},
|
|
||||||
description: {},
|
|
||||||
link: {},
|
|
||||||
},
|
|
||||||
method: 'POST',
|
|
||||||
title: '{% trans "Add Manufacturer Part" %}',
|
|
||||||
onSuccess: function() {
|
onSuccess: function() {
|
||||||
$("#manufacturer-part-table").bootstrapTable("refresh");
|
$("#manufacturer-part-table").bootstrapTable("refresh");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,65 @@
|
|||||||
{% load i18n %}
|
{% 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() {
|
function supplierPartFields() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -400,8 +459,52 @@ function loadManufacturerPartTable(table, url, options) {
|
|||||||
title: '{% trans "Description" %}',
|
title: '{% trans "Description" %}',
|
||||||
sortable: false,
|
sortable: false,
|
||||||
switchable: true,
|
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'>`;
|
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-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>';
|
html += '</div>';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user