2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 11:40:58 +00:00

Set part category (#3134)

* Refactor function to enable / disable submit button on modal forms

* Category selection now just uses the AP

* Remove unused forms / views

* JS linting fixes

* remove outdated unit test
This commit is contained in:
Oliver
2022-06-06 13:00:30 +10:00
committed by GitHub
parent fe8f111a63
commit 2b1d8f5b79
10 changed files with 91 additions and 185 deletions

View File

@ -8,7 +8,6 @@
imageHoverIcon,
inventreeGet,
inventreePut,
launchModalForm,
linkButtonsToSelection,
loadTableFilters,
makeIconBadge,
@ -1604,6 +1603,7 @@ function loadPartTable(table, url, options={}) {
/* Button callbacks for part table buttons */
// Callback function for the "order parts" button
$('#multi-part-order').click(function() {
var selections = getTableData(table);
@ -1613,31 +1613,82 @@ function loadPartTable(table, url, options={}) {
parts.push(part);
});
orderParts(
parts,
{
}
);
orderParts(parts, {});
});
// Callback function for the "set category" button
$('#multi-part-category').click(function() {
var selections = $(table).bootstrapTable('getSelections');
var selections = getTableData(table);
var parts = [];
selections.forEach(function(item) {
parts.push(item.pk);
});
launchModalForm('/part/set-category/', {
data: {
parts: parts,
var html = `
<div class='alert alert-block alert-info'>
{% trans "Set the part category for the selected parts" %}
</div>
`;
constructFormBody({}, {
title: '{% trans "Set Part Category" %}',
preFormContent: html,
fields: {
category: {
label: '{% trans "Category" %}',
help_text: '{% trans "Select Part Category" %}',
required: true,
type: 'related field',
model: 'partcategory',
api_url: '{% url "api-part-category-list" %}',
}
},
onSubmit: function(fields, opts) {
var category = getFormFieldValue('category', fields['category'], opts);
if (category == null) {
handleFormErrors(
{
'category': ['{% trans "Category is required" %}']
},
opts.fields,
opts
);
return;
}
// Set the category for each part in sequence
function setCategory() {
if (parts.length > 0) {
var part = parts.shift();
inventreePut(
`/api/part/${part}/`,
{
category: category,
},
{
method: 'PATCH',
complete: setCategory,
}
);
} else {
// We are done!
$(opts.modal).modal('hide');
$(table).bootstrapTable('refresh');
}
};
// Start the ball rolling
showModalSpinner(opts.modal);
setCategory();
},
reload: true,
});
});
// Callback function for the "print label" button
$('#multi-part-print-label').click(function() {
var selections = getTableData(table);