mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
javascript fixes
This commit is contained in:
parent
0581885ad5
commit
1cbce5dfbf
@ -192,30 +192,20 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
rows += renderSubstituteRow(sub);
|
rows += renderSubstituteRow(sub);
|
||||||
});
|
});
|
||||||
|
|
||||||
var html = ``;
|
var html = `
|
||||||
|
<table class='table table-striped table-condensed' id='substitute-table'>
|
||||||
if (substitutes.length > 0) {
|
<thead>
|
||||||
html += `
|
<tr>
|
||||||
<table class='table table-striped table-condensed' id='substitute-table'>
|
<th>{% trans "Part" %}</th>
|
||||||
<thead>
|
<th>{% trans "Description" %}</th>
|
||||||
<tr>
|
<th><!-- Actions --></th>
|
||||||
<th>{% trans "Part" %}</th>
|
</tr>
|
||||||
<th>{% trans "Description" %}</th>
|
</thead>
|
||||||
<th><!-- Actions --></th>
|
<tbody>
|
||||||
</tr>
|
${rows}
|
||||||
</thead>
|
</tbody>
|
||||||
<tbody>
|
</table>
|
||||||
${rows}
|
`;
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
`;
|
|
||||||
} else {
|
|
||||||
html += `
|
|
||||||
<div class='alert alert-block alert-info'>
|
|
||||||
<em>{% trans "There are no substitue parts specified for this BOM line item" %}</em>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
html += `
|
html += `
|
||||||
<div class='alert alert-success alert-block'>
|
<div class='alert alert-success alert-block'>
|
||||||
@ -223,6 +213,30 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// Add a callback to remove a row from the table
|
||||||
|
function addRemoveCallback(modal, element) {
|
||||||
|
$(modal).find(element).click(function() {
|
||||||
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
|
var pre = `
|
||||||
|
<div class='alert alert-block alert-warning'>
|
||||||
|
{% trans "Are you sure you wish to remove this substitute part link?" %}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
constructForm(`/api/bom/substitute/${pk}/`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
title: '{% trans "Remove Substitute Part" %}',
|
||||||
|
preFormContent: pre,
|
||||||
|
confirm: true,
|
||||||
|
onSuccess: function() {
|
||||||
|
$(modal).find(`#substitute-row-${pk}`).remove();
|
||||||
|
reloadParentTable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructForm('{% url "api-bom-substitute-list" %}', {
|
constructForm('{% url "api-bom-substitute-list" %}', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
fields: {
|
fields: {
|
||||||
@ -239,29 +253,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
submitText: '{% trans "Add Substitute" %}',
|
submitText: '{% trans "Add Substitute" %}',
|
||||||
title: '{% trans "Edit BOM Item Substitutes" %}',
|
title: '{% trans "Edit BOM Item Substitutes" %}',
|
||||||
afterRender: function(fields, opts) {
|
afterRender: function(fields, opts) {
|
||||||
|
addRemoveCallback(opts.modal, '.button-row-remove');
|
||||||
// Add a callback to remove individual rows
|
|
||||||
$(opts.modal).find('.button-row-remove').click(function() {
|
|
||||||
var pk = $(this).attr('pk');
|
|
||||||
|
|
||||||
var pre = `
|
|
||||||
<div class='alert alert-block alert-warning'>
|
|
||||||
{% trans "Are you sure you wish to remove this substitute part link?" %}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
constructForm(`/api/bom/substitute/${pk}/`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
title: '{% trans "Remove Substitute Part" %}',
|
|
||||||
preFormContent: pre,
|
|
||||||
confirm: true,
|
|
||||||
onSuccess: function() {
|
|
||||||
$(opts.modal).find(`#substitute-row-${pk}`).remove();
|
|
||||||
|
|
||||||
reloadParentTable();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
preventClose: true,
|
preventClose: true,
|
||||||
onSuccess: function(response, opts) {
|
onSuccess: function(response, opts) {
|
||||||
@ -277,6 +269,9 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
var row = renderSubstituteRow(response);
|
var row = renderSubstituteRow(response);
|
||||||
$(opts.modal).find('#substitute-table > tbody:last-child').append(row);
|
$(opts.modal).find('#substitute-table > tbody:last-child').append(row);
|
||||||
|
|
||||||
|
// Add a callback to the new button
|
||||||
|
addRemoveCallback(opts.modal, `#button-row-remove-${response.pk}`);
|
||||||
|
|
||||||
// Re-enable the "submit" button
|
// Re-enable the "submit" button
|
||||||
$(opts.modal).find('#modal-form-submit').prop('disabled', false);
|
$(opts.modal).find('#modal-form-submit').prop('disabled', false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user