mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Refactor SupplierPartCreate form
This commit is contained in:
@ -1,6 +1,63 @@
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
function supplierPartFields() {
|
||||
|
||||
return {
|
||||
part: {},
|
||||
supplier: {},
|
||||
SKU: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
manufacturer_part: {
|
||||
filters: {
|
||||
part_detail: true,
|
||||
manufacturer_detail: true,
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
note: {
|
||||
icon: 'fa-pencil-alt',
|
||||
},
|
||||
packaging: {
|
||||
icon: 'fa-box',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Launch a form to create a new ManufacturerPart
|
||||
*/
|
||||
function createSupplierPart(options={}) {
|
||||
|
||||
var fields = supplierPartFields();
|
||||
|
||||
if (options.part) {
|
||||
fields.manufacturer_part.filters.part = options.part;
|
||||
fields.part.hidden = true;
|
||||
fields.part.value = options.part;
|
||||
}
|
||||
|
||||
if (options.supplier) {
|
||||
fields.supplier.value = options.supplier;
|
||||
}
|
||||
|
||||
if (options.manufacturer_part) {
|
||||
fields.manufacturer_part.value = options.manufacturer_part;
|
||||
}
|
||||
|
||||
constructForm('{% url "api-supplier-part-list" %}', {
|
||||
fields: fields,
|
||||
method: 'POST',
|
||||
title: '{% trans "Add Supplier Part" %}',
|
||||
onSuccess: options.onSuccess,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Returns a default form-set for creating / editing a Company object
|
||||
function companyFormFields(options={}) {
|
||||
|
||||
|
@ -1113,7 +1113,7 @@ function initializeRelatedField(name, field, options) {
|
||||
var pk = field.value;
|
||||
var url = `${field.api_url}/${pk}/`.replace('//', '/');
|
||||
|
||||
inventreeGet(url, {}, {
|
||||
inventreeGet(url, field.filters || {}, {
|
||||
success: function(data) {
|
||||
setRelatedFieldData(name, data, options);
|
||||
}
|
||||
@ -1211,6 +1211,9 @@ function renderModelData(name, model, data, parameters, options) {
|
||||
case 'partparametertemplate':
|
||||
renderer = renderPartParameterTemplate;
|
||||
break;
|
||||
case 'manufacturerpart':
|
||||
renderer = renderManufacturerPart;
|
||||
break;
|
||||
case 'supplierpart':
|
||||
renderer = renderSupplierPart;
|
||||
break;
|
||||
|
@ -174,7 +174,35 @@ function renderPartParameterTemplate(name, data, parameters, options) {
|
||||
}
|
||||
|
||||
|
||||
// Rendered for "SupplierPart" model
|
||||
// Renderer for "ManufacturerPart" model
|
||||
function renderManufacturerPart(name, data, parameters, options) {
|
||||
|
||||
var manufacturer_image = null;
|
||||
var part_image = null;
|
||||
|
||||
if (data.manufacturer_detail) {
|
||||
manufacturer_image = data.manufacturer_detail.image;
|
||||
}
|
||||
|
||||
if (data.part_detail) {
|
||||
part_image = data.part_detail.thumbnail || data.part_detail.image;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
|
||||
html += select2Thumbnail(manufacturer_image);
|
||||
html += select2Thumbnail(part_image);
|
||||
|
||||
html += ` <span><b>${data.manufacturer_detail.name}</b> - ${data.MPN}</span>`;
|
||||
html += ` - <i>${data.part_detail.full_name}</i>`;
|
||||
|
||||
html += `<span class='float-right'>{% trans "Manufacturer Part ID" %}: ${data.pk}</span>`;
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
// Renderer for "SupplierPart" model
|
||||
function renderSupplierPart(name, data, parameters, options) {
|
||||
|
||||
var supplier_image = null;
|
||||
|
@ -1616,27 +1616,6 @@ function createNewStockItem(options) {
|
||||
},
|
||||
];
|
||||
|
||||
options.secondary = [
|
||||
{
|
||||
field: 'part',
|
||||
label: '{% trans "New Part" %}',
|
||||
title: '{% trans "Create New Part" %}',
|
||||
url: "{% url 'part-create' %}",
|
||||
},
|
||||
{
|
||||
field: 'supplier_part',
|
||||
label: '{% trans "New Supplier Part" %}',
|
||||
title: '{% trans "Create new Supplier Part" %}',
|
||||
url: "{% url 'supplier-part-create' %}"
|
||||
},
|
||||
{
|
||||
field: 'location',
|
||||
label: '{% trans "New Location" %}',
|
||||
title: '{% trans "Create New Location" %}',
|
||||
url: "{% url 'stock-location-create' %}",
|
||||
},
|
||||
];
|
||||
|
||||
launchModalForm("{% url 'stock-item-create' %}", options);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,11 @@
|
||||
{% load i18n %}
|
||||
|
||||
|
||||
function reloadtable(table) {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
|
||||
|
||||
function editButton(url, text='Edit') {
|
||||
return "<button class='btn btn-success edit-button btn-sm' type='button' url='" + url + "'>" + text + "</button>";
|
||||
}
|
||||
|
Reference in New Issue
Block a user