From 36ac268b9678fb2d7767df4535f136d258e735da Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 13 Sep 2020 00:13:53 +1000 Subject: [PATCH 1/7] BOM Display: Multiple fixes - Previous multi-level BOM display changes had broken the table in editing mode - Simplify code - Re-implement edit / delete / validate buttons - Re-enable checkboxes in edit mode --- InvenTree/templates/js/bom.html | 126 +++++++++++++++++--------------- 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/InvenTree/templates/js/bom.html b/InvenTree/templates/js/bom.html index cab2a08b13..db5eafa0c1 100644 --- a/InvenTree/templates/js/bom.html +++ b/InvenTree/templates/js/bom.html @@ -39,7 +39,6 @@ function removeRowFromBomWizard(e) { if (colNum >= 3) { var cell = $(this).find('td:eq(1)'); cell.text(rowNum++); - console.log("Row: " + rowNum); } }); } @@ -106,26 +105,16 @@ function loadBomTable(table, options) { // Construct the table columns - var cols = [ - { - field: 'pk', - title: 'ID', - visible: false, - switchable: false, - }, - ]; + var cols = []; if (options.editable) { - - /* - // TODO - Enable multi-select functionality cols.push({ + field: 'ID', + title: '', checkbox: true, - title: 'Select', - searchable: false, - sortable: false, + visible: true, + switchable: false, }); - */ } // Part column @@ -234,16 +223,23 @@ function loadBomTable(table, options) { ); if (options.editable) { + cols.push({ + title: '{% trans "Actions" %}', + switchable: false, + field: 'pk', + visible: true, formatter: function(value, row, index, field) { if (row.part == options.parent_id) { - var bValidate = ""; - var bValid = ""; + var bValidate = ``; + + var bValid = ``; - var bEdit = ""; - var bDelt = ""; + var bEdit = ``; + + var bDelt = ``; var html = "
"; @@ -314,10 +310,10 @@ function loadBomTable(table, options) { } table.inventreeTable({ - treeEnable: true, + treeEnable: !options.editable, rootParentId: options.parent_id, idField: 'pk', - uniqueId: 'pk', + //uniqueId: 'pk', parentIdField: 'parentId', treeShowField: 'sub_part', showColumns: true, @@ -333,37 +329,43 @@ function loadBomTable(table, options) { }, formatNoMatches: function() { return "{% trans "No BOM items found" %}"; }, clickToSelect: true, - queryParams: function(p) { - return params; - }, + queryParams: params, columns: cols, url: options.bom_url, onPostBody: function() { - table.treegrid({ - treeColumn: 0, - onExpand: function() { - } - }); + + if (!options.editable) { + table.treegrid({ + treeColumn: 0, + onExpand: function() { + } + }); + } }, onLoadSuccess: function() { - var data = table.bootstrapTable('getData'); + if (options.editable) { + table.bootstrapTable('uncheckAll'); + } else { - for (var idx = 0; idx < data.length; idx++) { - var row = data[idx]; + var data = table.bootstrapTable('getData'); - // If a row already has a parent ID set, it's already been updated! - if (row.parentId) { - continue; - } + for (var idx = 0; idx < data.length; idx++) { + var row = data[idx]; - // Set the parent ID of the top-level rows - row.parentId = options.parent_id; + // If a row already has a parent ID set, it's already been updated! + if (row.parentId) { + continue; + } - table.bootstrapTable('updateRow', idx, row, true); + // Set the parent ID of the top-level rows + row.parentId = options.parent_id; - if (row.sub_part_detail.assembly) { - requestSubItems(row.pk, row.sub_part); + table.bootstrapTable('updateRow', idx, row, true); + + if (row.sub_part_detail.assembly) { + requestSubItems(row.pk, row.sub_part); + } } } }, @@ -373,29 +375,39 @@ function loadBomTable(table, options) { if (options.editable) { table.on('click', '.bom-delete-button', function() { - var button = $(this); + + var pk = $(this).attr('pk'); + var url = `/part/bom/${pk}/delete/`; - launchModalForm(button.attr('url'), { - success: function() { - reloadBomTable(table); - } - }); + launchModalForm( + url, + { + success: function() { + reloadBomTable(table); + } + } + ); }); table.on('click', '.bom-edit-button', function() { - var button = $(this); + + var pk = $(this).attr('pk'); + var url = `/part/bom/${pk}/edit/`; - launchModalForm(button.attr('url'), { - success: function() { - reloadBomTable(table); - } - }); + launchModalForm( + url, + { + success: function() { + reloadBomTable(table); + } + } + ); }); table.on('click', '.bom-validate-button', function() { - var button = $(this); - - var url = '/api/bom/' + button.attr('pk') + '/validate/'; + + var pk = $(this).attr('pk'); + var url = `/api/bom/${pk}/validate/`; inventreePut( url, From 7a7db97914ba011f398704fc49891ccfd94e1d6d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 13 Sep 2020 00:39:25 +1000 Subject: [PATCH 2/7] add inventreeDelete ajax function --- .../InvenTree/static/script/inventree/api.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/InvenTree/InvenTree/static/script/inventree/api.js b/InvenTree/InvenTree/static/script/inventree/api.js index 0a3b8d9374..52aba80ef5 100644 --- a/InvenTree/InvenTree/static/script/inventree/api.js +++ b/InvenTree/InvenTree/static/script/inventree/api.js @@ -108,6 +108,25 @@ function inventreePut(url, data={}, options={}) { if (options.error) { options.error(xhr, ajaxOptions, thrownError); } + }, + complete: function(xhr, status) { + if (options.complete) { + options.complete(xhr, status); + } } }); } + + +function inventreeDelete(url, options={}) { + /* + * Delete a record + */ + + options = options || {}; + + options.method = 'DELETE'; + + inventreePut(url, {}, options); + +} \ No newline at end of file From 57e395de710226d1edcf99591ce6d5b7d770245e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 13 Sep 2020 00:40:06 +1000 Subject: [PATCH 3/7] BOM: Allow multiple BOM items to be selected and deleted (in editing mode) --- InvenTree/part/templates/part/bom.html | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index 21d01d7501..2653a42575 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -90,6 +90,48 @@ location.href = "{% url 'part-bom' part.id %}"; }); + $('#bom-item-delete').click(function() { + + // Get a list of the selected BOM items + var rows = $("#bom-table").bootstrapTable('getSelections'); + + // TODO - In the future, display (in the dialog) which items are going to be deleted + + showQuestionDialog( + '{% trans "Delete selected BOM items?" %}', + '{% trans "All selected BOM items will be deleted" %}', + { + accept: function() { + + // Delete each row one at a time! + function deleteRow(idx) { + + if (idx >= rows.length) { + // All selected rows deleted - reload the table + $("#bom-table").bootstrapTable('refresh'); + } + + var row = rows[idx]; + + var url = `/api/bom/${row.pk}/`; + + inventreeDelete( + url, + { + complete: function(xhr, status) { + deleteRow(idx + 1); + } + } + ) + } + + // Start the deletion! + deleteRow(0); + } + } + ); + }); + $('#bom-upload').click(function() { location.href = "{% url 'upload-bom' part.id %}"; }); From aa35c787b25795dcfee916e4d020d50257cca6bf Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 13 Sep 2020 17:47:40 +1000 Subject: [PATCH 4/7] Fix for weird button toggles (it was a doozy!) - Turning off autocomplete seems to have done the job - https://stackoverflow.com/questions/36546775/html-checkboxes-keep-checked-after-refresh#36547079 --- InvenTree/part/templates/part/detail.html | 48 +---------------------- InvenTree/templates/slide.html | 2 +- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index eee68c6d6d..2714347414 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -218,14 +218,13 @@ {{ block.super }} $(".slidey").change(function() { - var field = $(this).attr('field'); + var field = $(this).attr('fieldname'); var checked = $(this).prop('checked'); var data = {}; data[field] = checked; - // Update the particular field inventreePut("{% url 'api-part-detail' part.id %}", data, @@ -235,50 +234,5 @@ }, ); }); - - $('#activate-part').click(function() { - showQuestionDialog( - 'Activate Part?', - 'Are you sure you wish to reactivate {{ part.full_name }}?', - { - accept_text: 'Activate', - accept: function() { - inventreePut( - "{% url 'api-part-detail' part.id %}", - { - active: true, - }, - { - method: 'PATCH', - reloadOnSuccess: true, - } - ); - } - }, - ); - }); - - $('#deactivate-part').click(function() { - showQuestionDialog( - 'Deactivate Part?', - `Are you sure you wish to deactivate {{ part.full_name }}?
- `, - { - accept_text: 'Deactivate', - accept: function() { - inventreePut( - "{% url 'api-part-detail' part.id %}", - { - active: false, - }, - { - method: 'PATCH', - reloadOnSuccess: true, - } - ); - } - } - ); - }); {% endblock %} diff --git a/InvenTree/templates/slide.html b/InvenTree/templates/slide.html index 14afc4aa04..e2fe2e932f 100644 --- a/InvenTree/templates/slide.html +++ b/InvenTree/templates/slide.html @@ -1,3 +1,3 @@
- +
\ No newline at end of file From 04c702e1b8f96d5734f976c6b0f6f7d8883d3021 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 13 Sep 2020 20:42:59 +1000 Subject: [PATCH 5/7] Improve action buttons for part display --- InvenTree/InvenTree/static/css/inventree.css | 5 +++++ InvenTree/part/templates/part/part_base.html | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index ccf0671d56..964be5c359 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -413,6 +413,10 @@ font-size: 125%; } +.btn-group { + padding-bottom: 5px; +} + .action-buttons .btn { font-size: 175%; align-content: center; @@ -474,6 +478,7 @@ .media { padding-top: 15px; + overflow: visible; } .media-body { diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index bef5a52896..74f9e1383f 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -35,16 +35,18 @@ {% endif %}

{{ part.description }}

+
+ -