diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 6bad2bbbdf..d240b53601 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -667,6 +667,8 @@ }); onPanelLoad("test-templates", function() { + + // Load test template table loadPartTestTemplateTable( $("#test-template-table"), { @@ -677,11 +679,8 @@ } ); + // Callback for "add test template" button $("#add-test-template").click(function() { - - function reloadTestTemplateTable() { - $("#test-template-table").bootstrapTable("refresh"); - } constructForm('{% url "api-part-test-template-list" %}', { method: 'POST', @@ -697,39 +696,10 @@ } }, title: '{% trans "Add Test Result Template" %}', - onSuccess: reloadTestTemplateTable + onSuccess: function() { + $("#test-template-table").bootstrapTable("refresh"); + } }); - - $("#test-template-table").on('click', '.button-test-edit', function() { - var pk = $(this).attr('pk'); - - var url = `/api/part/test-template/${pk}/`; - - constructForm(url, { - fields: { - test_name: {}, - description: {}, - required: {}, - requires_value: {}, - requires_attachment: {}, - }, - title: '{% trans "Edit Test Result Template" %}', - onSuccess: reloadTestTemplateTable, - }); - }); - - $("#test-template-table").on('click', '.button-test-delete', function() { - var pk = $(this).attr('pk'); - - var url = `/api/part/test-template/${pk}/`; - - constructForm(url, { - method: 'DELETE', - title: '{% trans "Delete Test Result Template" %}', - onSuccess: reloadTestTemplateTable, - }); - }); - }); }); diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 1ccf8157b6..8cae5d249b 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1252,7 +1252,43 @@ function loadPartTestTemplateTable(table, options) { } } } - ] + ], + onPostBody: function() { + + table.find('.button-test-edit').click(function() { + var pk = $(this).attr('pk'); + + var url = `/api/part/test-template/${pk}/`; + + constructForm(url, { + fields: { + test_name: {}, + description: {}, + required: {}, + requires_value: {}, + requires_attachment: {}, + }, + title: '{% trans "Edit Test Result Template" %}', + onSuccess: function() { + table.bootstrapTable('refresh'); + }, + }); + }); + + table.find('.button-test-delete').click(function() { + var pk = $(this).attr('pk'); + + var url = `/api/part/test-template/${pk}/`; + + constructForm(url, { + method: 'DELETE', + title: '{% trans "Delete Test Result Template" %}', + onSuccess: function() { + table.bootstrapTable('refresh'); + }, + }); + }); + } }); }