From 1cbce5dfbfd51cced8de0b76611a591aa34a9e3b Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 14 Oct 2021 09:14:31 +1100 Subject: [PATCH] javascript fixes --- InvenTree/templates/js/translated/bom.js | 89 +++++++++++------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 048747c6bb..7cab63153b 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -192,30 +192,20 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) { rows += renderSubstituteRow(sub); }); - var html = ``; - - if (substitutes.length > 0) { - html += ` - - - - - - - - - - ${rows} - -
{% trans "Part" %}{% trans "Description" %}
- `; - } else { - html += ` -
- {% trans "There are no substitue parts specified for this BOM line item" %} -
- `; - } + var html = ` + + + + + + + + + + ${rows} + +
{% trans "Part" %}{% trans "Description" %}
+ `; html += `
@@ -223,6 +213,30 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
`; + // 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 = ` +
+ {% trans "Are you sure you wish to remove this substitute part link?" %} +
+ `; + + 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" %}', { method: 'POST', fields: { @@ -239,29 +253,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) { submitText: '{% trans "Add Substitute" %}', title: '{% trans "Edit BOM Item Substitutes" %}', afterRender: function(fields, opts) { - - // Add a callback to remove individual rows - $(opts.modal).find('.button-row-remove').click(function() { - var pk = $(this).attr('pk'); - - var pre = ` -
- {% trans "Are you sure you wish to remove this substitute part link?" %} -
- `; - - 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(); - } - }); - }); + addRemoveCallback(opts.modal, '.button-row-remove'); }, preventClose: true, onSuccess: function(response, opts) { @@ -277,6 +269,9 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) { var row = renderSubstituteRow(response); $(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 $(opts.modal).find('#modal-form-submit').prop('disabled', false);