From f0e8e32c8a0ae4d1c605efcb2b1fca108f4adbc9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 3 May 2022 17:27:21 +1000 Subject: [PATCH] More refactoring --- InvenTree/part/templates/part/detail.html | 18 ++++++++++++------ InvenTree/part/templates/part/part_base.html | 9 --------- InvenTree/templates/js/translated/order.js | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 5ec1821b3d..aa3ad4963a 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -754,12 +754,18 @@ $("#part-order2").click(function() { - launchModalForm("{% url 'order-parts' %}", { - data: { - part: {{ part.id }}, - }, - reload: true, - }); + inventreeGet( + '{% url "api-part-detail" part.pk %}', + {}, + { + success: function(part) { + orderParts( + [part], + {} + ); + } + } + ); }); onPanelLoad("test-templates", function() { diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 649aaf6705..4e875c1f97 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -549,15 +549,6 @@ } } ); - - return; - - launchModalForm("{% url 'order-parts' %}", { - data: { - part: {{ part.id }}, - }, - reload: true, - }); }); {% if roles.part.add %} diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 9b8366a5aa..496ea6a61e 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -603,6 +603,17 @@ function orderParts(parts_list, options={}) { return html; } + // Remove a single row form this dialog + function removeRow(pk, opts) { + // Remove the row + $(opts.modal).find(`#order_row_${pk}`).remove(); + + // If the modal is now "empty", dismiss it + if (!($(opts.modal).find('.part-order-row').exists())) { + closeModal(opts.modal); + } + } + var table_entries = ''; parts.forEach(function(part) { @@ -727,8 +738,7 @@ function orderParts(parts_list, options={}) { { method: 'POST', success: function(response) { - // Remove the row - $(opts.modal).find(`#order_row_${pk}`).remove(); + removeRow(pk, opts); }, error: function(xhr) { switch (xhr.status) { @@ -749,7 +759,7 @@ function orderParts(parts_list, options={}) { $(opts.modal).find('.button-row-remove').click(function() { var pk = $(this).attr('pk'); - $(opts.modal).find(`#order_row_${pk}`).remove(); + removeRow(pk, opts); }); // Add callback for "new supplier part" button