From 578c161d4fb93e8403570c6117bb20a4c34a6bbe Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Feb 2022 13:36:00 +1100 Subject: [PATCH 1/2] Adds information on test result being deleted --- InvenTree/stock/templates/stock/item.html | 80 ---------------- InvenTree/templates/js/translated/stock.js | 104 ++++++++++++++++++++- 2 files changed, 100 insertions(+), 84 deletions(-) diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 48fcfb8370..333360a95e 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -311,86 +311,6 @@ }); }); - $('#test-result-table').on('click', '.button-test-tick', function() { - var button = $(this); - - var test_name = button.attr('pk'); - - inventreePut( - '{% url "api-stock-test-result-list" %}', - { - test: test_name, - result: true, - stock_item: {{ item.pk }}, - }, - { - method: 'POST', - success: function(response) { - reloadTable(); - } - } - ); - }) - - $("#test-result-table").on('click', '.button-test-add', function() { - var button = $(this); - - var test_name = button.attr('pk'); - - constructForm('{% url "api-stock-test-result-list" %}', { - method: 'POST', - fields: { - test: { - value: test_name, - }, - result: {}, - value: {}, - attachment: {}, - notes: {}, - stock_item: { - value: {{ item.pk }}, - hidden: true, - } - }, - title: '{% trans "Add Test Result" %}', - onSuccess: reloadTable, - }); - }); - - $("#test-result-table").on('click', '.button-test-edit', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/stock/test/${pk}/`; - - constructForm(url, { - fields: { - test: {}, - result: {}, - value: {}, - attachment: {}, - notes: {}, - }, - title: '{% trans "Edit Test Result" %}', - onSuccess: reloadTable, - }); - }); - - $("#test-result-table").on('click', '.button-test-delete', function() { - var button = $(this); - - var pk = button.attr('pk'); - - var url = `/api/stock/test/${pk}/`; - - constructForm(url, { - method: 'DELETE', - title: '{% trans "Delete Test Result" %}', - onSuccess: reloadTable, - }); - }); - {% if item.child_count > 0 %} loadStockTable($("#childs-stock-table"), { params: { diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 6fb8c911c8..3c0511c0ae 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1227,10 +1227,10 @@ function formatDate(row) { return html; } +/* + * Load StockItemTestResult table + */ function loadStockTestResultsTable(table, options) { - /* - * Load StockItemTestResult table - */ function makeButtons(row, grouped) { var html = `
`; @@ -1263,7 +1263,7 @@ function loadStockTestResultsTable(table, options) { rootParentId: parent_node, parentIdField: 'parent', idField: 'pk', - uniqueId: 'key', + uniqueId: 'pk', treeShowField: 'test_name', formatNoMatches: function() { return '{% trans "No test results found" %}'; @@ -1406,6 +1406,102 @@ function loadStockTestResultsTable(table, options) { ); } }); + + /* Register button callbacks */ + + function reloadTestTable(response) { + $(table).bootstrapTable('refresh'); + } + + // "tick" a test result + $(table).on('click', '.button-test-tick', function() { + var button = $(this); + + var test_name = button.attr('pk'); + + inventreePut( + '{% url "api-stock-test-result-list" %}', + { + test: test_name, + result: true, + stock_item: options.stock_item, + }, + { + method: 'POST', + success: reloadTestTable, + } + ); + }); + + // Add a test result + $(table).on('click', '.button-test-add', function() { + var button = $(this); + + var test_name = button.attr('pk'); + + constructForm('{% url "api-stock-test-result-list" %}', { + method: 'POST', + fields: { + test: { + value: test_name, + }, + result: {}, + value: {}, + attachment: {}, + notes: {}, + stock_item: { + value: options.stock_item, + hidden: true, + } + }, + title: '{% trans "Add Test Result" %}', + onSuccess: reloadTestTable, + }); + }); + + // Edit a test result + $(table).on('click', '.button-test-edit', function() { + var button = $(this); + + var pk = button.attr('pk'); + + var url = `/api/stock/test/${pk}/`; + + constructForm(url, { + fields: { + test: {}, + result: {}, + value: {}, + attachment: {}, + notes: {}, + }, + title: '{% trans "Edit Test Result" %}', + onSuccess: reloadTestTable, + }); + }); + + // Delete a test result + $(table).on('click', '.button-test-delete', function() { + var button = $(this); + + var pk = button.attr('pk'); + + var url = `/api/stock/test/${pk}/`; + + var row = $(table).bootstrapTable('getRowByUniqueId', pk); + + var html = ` +
+ {% trans "Delete test result" %}: ${row.test_name || row.test || row.key} +
`; + + constructForm(url, { + method: 'DELETE', + title: '{% trans "Delete Test Result" %}', + onSuccess: reloadTestTable, + preFormContent: html, + }); + }); } From 6199223636a513de4d38b90d0a9908fb84110c6f Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Feb 2022 13:46:11 +1100 Subject: [PATCH 2/2] Adds "refresh" button for stock test table --- InvenTree/templates/js/translated/stock.js | 28 +++++++++++++++++-- .../templates/js/translated/table_filters.js | 7 +---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 3c0511c0ae..9be9d2afa1 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1232,7 +1232,30 @@ function formatDate(row) { */ function loadStockTestResultsTable(table, options) { + // Setup filters for the table + var filterTarget = options.filterTarget || '#filter-list-stocktests'; + + var filterKey = options.filterKey || options.name || 'stocktests'; + + var filters = loadTableFilters(filterKey); + + var params = { + part: options.part, + }; + + var original = {}; + + for (var k in params) { + original[k] = params[k]; + filters[k] = params[k]; + } + + setupFilterList(filterKey, table, filterTarget); + function makeButtons(row, grouped) { + + // Helper function for rendering buttons + var html = `
`; if (row.requires_attachment == false && row.requires_value == false && !row.result) { @@ -1268,9 +1291,8 @@ function loadStockTestResultsTable(table, options) { formatNoMatches: function() { return '{% trans "No test results found" %}'; }, - queryParams: { - part: options.part, - }, + queryParams: filters, + original: original, onPostBody: function() { table.treegrid({ treeColumn: 0, diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index d9f2014c14..a4c6a0bbac 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -265,12 +265,7 @@ function getAvailableTableFilters(tableKey) { // Filters for the 'stock test' table if (tableKey == 'stocktests') { - return { - result: { - type: 'bool', - title: '{% trans "Test result" %}', - }, - }; + return {}; } // Filters for the 'part test template' table