mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor 'DeleteManufacturerPart' form (#3067)
* Refactor 'DeleteManufacturerPart' form - Remove duplicated forms - Update style to match other forms - Block on each deletion before progressing to the next one * PEP fix * Adds deleteSupplierParts function * Refactor all instances of supplier part deletion * Refactor tractor : use convenience function for bootstraptable.getSelections * Add deleter for manufacturerpartparameter. Refactor existing code into a single function * Refactor deletion for stock items * JS linting
This commit is contained in:
parent
0e9ea1be0c
commit
2d1776a151
@ -527,11 +527,7 @@ $('#btn-unallocate').on('click', function() {
|
||||
|
||||
$('#allocate-selected-items').click(function() {
|
||||
|
||||
var bom_items = $("#allocation-table-untracked").bootstrapTable("getSelections");
|
||||
|
||||
if (bom_items.length == 0) {
|
||||
bom_items = $("#allocation-table-untracked").bootstrapTable('getData');
|
||||
}
|
||||
var bom_items = getTableData('#allocation-table-untracked');
|
||||
|
||||
allocateStockToBuild(
|
||||
{{ build.pk }},
|
||||
|
@ -185,8 +185,7 @@ loadBuildTable($("#build-table"), {
|
||||
|
||||
{% if report_enabled %}
|
||||
$('#multi-build-print').click(function() {
|
||||
var rows = $("#build-table").bootstrapTable('getSelections');
|
||||
|
||||
var rows = getTableData("#build-table");
|
||||
var build_ids = [];
|
||||
|
||||
rows.forEach(function(row) {
|
||||
|
@ -28,8 +28,8 @@
|
||||
<div class='button-toolbar container-fluid'>
|
||||
<div class='btn-group' role='group'>
|
||||
<div class='btn-group'>
|
||||
<button class="btn btn-primary dropdown-toggle" id='supplier-table-options' type="button" data-bs-toggle="dropdown">{% trans "Options" %}
|
||||
<span class="caret"></span>
|
||||
<button class="btn btn-primary dropdown-toggle" id='supplier-table-options' type="button" data-bs-toggle="dropdown">
|
||||
<span class='fas fa-tools'></span> <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{% if roles.purchase_order.add %}
|
||||
@ -75,7 +75,8 @@
|
||||
<div class='button-toolbar container-fluid'>
|
||||
<div class='btn-group' role='group'>
|
||||
<div class='btn-group' role='group'>
|
||||
<button class="btn btn-primary dropdown-toggle" id='manufacturer-table-options' type="button" data-bs-toggle="dropdown">{% trans "Options" %}
|
||||
<button class="btn btn-primary dropdown-toggle" id='manufacturer-table-options' type="button" data-bs-toggle="dropdown">
|
||||
<span class='fas fa-tools'></span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
@ -307,20 +308,18 @@
|
||||
}
|
||||
);
|
||||
|
||||
linkButtonsToSelection($("#manufacturer-part-table"), ['#manufacturer-table-options']);
|
||||
|
||||
$("#multi-manufacturer-part-delete").click(function() {
|
||||
var selections = $("#manufacturer-part-table").bootstrapTable("getSelections");
|
||||
var selections = getTableData('#manufacturer-part-table');
|
||||
|
||||
deleteManufacturerParts(selections, {
|
||||
onSuccess: function() {
|
||||
success: function() {
|
||||
$("#manufacturer-part-table").bootstrapTable("refresh");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#multi-manufacturer-part-order").click(function() {
|
||||
var selections = $("#manufacturer-part-table").bootstrapTable("getSelections");
|
||||
var selections = getTableData('#manufacturer-part-table');
|
||||
|
||||
var parts = [];
|
||||
|
||||
@ -364,34 +363,20 @@
|
||||
}
|
||||
);
|
||||
|
||||
linkButtonsToSelection($("#supplier-part-table"), ['#supplier-table-options']);
|
||||
|
||||
$("#multi-supplier-part-delete").click(function() {
|
||||
var selections = $("#supplier-part-table").bootstrapTable("getSelections");
|
||||
|
||||
var requests = [];
|
||||
var selections = getTableData("#supplier-part-table");
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Supplier Parts?" %}',
|
||||
'{% trans "All selected supplier parts will be deleted" %}',
|
||||
{
|
||||
accept: function() {
|
||||
selections.forEach(function(part) {
|
||||
var url = `/api/company/part/${part.pk}/`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
});
|
||||
|
||||
$.when.apply($, requests).done(function() {
|
||||
deleteSupplierParts(selections, {
|
||||
success: function() {
|
||||
$('#supplier-part-table').bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("#multi-supplier-part-order").click(function() {
|
||||
var selections = $("#supplier-part-table").bootstrapTable("getSelections");
|
||||
|
||||
var selections = getTableData('#supplier-part-table');
|
||||
|
||||
var parts = [];
|
||||
|
||||
|
@ -129,7 +129,9 @@ src="{% static 'img/blank_image.png' %}"
|
||||
<div id='supplier-button-toolbar'>
|
||||
<div class='btn-group'>
|
||||
<div id='opt-dropdown' class="btn-group">
|
||||
<button id='supplier-part-options' class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">{% trans "Options" %} <span class="caret"></span></button>
|
||||
<button id='supplier-part-options' class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<span class='fas fa-tools'></span> <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class='dropdown-item' href='#' id='supplier-part-delete' title='{% trans "Delete supplier parts" %}'><span class='fas fa-trash-alt icon-red'></span> {% trans "Delete" %}</a></li>
|
||||
</ul>
|
||||
@ -174,11 +176,14 @@ src="{% static 'img/blank_image.png' %}"
|
||||
<div id='parameter-toolbar'>
|
||||
<div class='btn-group'>
|
||||
<div id='opt-dropdown' class="btn-group">
|
||||
<button id='parameter-options' class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">{% trans "Options" %} <span class="caret"></span></button>
|
||||
<button id='parameter-options' class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<span class='fas fa-tools'></span> <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class='dropdown-item' href='#' id='multi-parameter-delete' title='{% trans "Delete parameters" %}'><span class='fas fa-trash-alt icon-red'></span> {% trans "Delete" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% include "filter_list.html" with id="manufacturer-part-parameters" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -256,67 +261,22 @@ $('#supplier-create').click(function () {
|
||||
|
||||
$("#supplier-part-delete").click(function() {
|
||||
|
||||
var selections = $("#supplier-table").bootstrapTable("getSelections");
|
||||
var selections = getTableData('#supplier-table');
|
||||
|
||||
var requests = [];
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Supplier Parts?" %}',
|
||||
'{% trans "All selected supplier parts will be deleted" %}',
|
||||
{
|
||||
accept: function() {
|
||||
selections.forEach(function(part) {
|
||||
var url = `/api/company/part/${part.pk}/`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
deleteSupplierParts(selections, {
|
||||
success: reloadSupplierPartTable,
|
||||
});
|
||||
|
||||
$.when.apply($, requests).done(function() {
|
||||
reloadSupplierPartTable();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("#multi-parameter-delete").click(function() {
|
||||
|
||||
var selections = $("#parameter-table").bootstrapTable("getSelections");
|
||||
var selections = getTableData('#parameter-table');
|
||||
|
||||
var text = `
|
||||
<div class ='alert alert-block alert-danger'>
|
||||
<p>{% trans "Selected parameters will be deleted" %}:</p>
|
||||
<ul>`;
|
||||
|
||||
selections.forEach(function(item) {
|
||||
text += `<li>${item.name} - <em>${item.value}</em></li>`;
|
||||
});
|
||||
|
||||
text += `
|
||||
</ul>
|
||||
</div>`;
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Parameters" %}',
|
||||
text,
|
||||
{
|
||||
accept_text: '{% trans "Delete" %}',
|
||||
accept: function() {
|
||||
// Delete each parameter via the API
|
||||
var requests = [];
|
||||
|
||||
selections.forEach(function(item) {
|
||||
var url = `/api/company/part/manufacturer/parameter/${item.pk}/`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
});
|
||||
|
||||
$.when.apply($, requests).done(function() {
|
||||
deleteManufacturerPartParameters(selections, {
|
||||
success: function() {
|
||||
$('#parameter-table').bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
loadSupplierPartTable(
|
||||
@ -326,9 +286,9 @@ loadSupplierPartTable(
|
||||
params: {
|
||||
part: {{ part.part.id }},
|
||||
manufacturer_part: {{ part.id }},
|
||||
part_detail: false,
|
||||
part_detail: true,
|
||||
supplier_detail: true,
|
||||
manufacturer_detail: false,
|
||||
manufacturer_detail: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
@ -343,10 +303,6 @@ loadManufacturerPartParameterTable(
|
||||
}
|
||||
);
|
||||
|
||||
linkButtonsToSelection($("#supplier-table"), ['#supplier-part-options']);
|
||||
|
||||
linkButtonsToSelection($("#parameter-table"), ['#parameter-options']);
|
||||
|
||||
$('#order-part, #order-part2').click(function() {
|
||||
|
||||
inventreeGet(
|
||||
@ -376,15 +332,26 @@ $('#edit-part').click(function () {
|
||||
|
||||
$('#delete-part').click(function() {
|
||||
|
||||
deleteManufacturerPart({{ part.pk }}, {
|
||||
onSuccess: function() {
|
||||
inventreeGet(
|
||||
'{% url "api-manufacturer-part-detail" part.pk %}',
|
||||
{},
|
||||
{
|
||||
success: function(data) {
|
||||
deleteManufacturerParts(
|
||||
[data],
|
||||
{
|
||||
success: function() {
|
||||
{% if part.manufacturer %}
|
||||
window.location.href = "{% url 'company-detail' part.manufacturer.id %}";
|
||||
{% else%}
|
||||
window.location.href = "{% url 'index' %}";
|
||||
{% endif %}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
enableSidebar('manufacturerpart');
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
{% trans "Parameters" as text %}
|
||||
{% include "sidebar_item.html" with label='parameters' text=text icon="fa-th-list" %}
|
||||
{% trans "Attachments" as text %}
|
||||
{% include "sidebar_item.html" with label='attachments' text=text icon="fa-paperclip" %}
|
||||
{% trans "Supplier Parts" as text %}
|
||||
{% include "sidebar_item.html" with label='supplier-parts' text=text icon="fa-building" %}
|
||||
{% trans "Attachments" as text %}
|
||||
{% include "sidebar_item.html" with label='attachments' text=text icon="fa-paperclip" %}
|
||||
|
@ -191,11 +191,7 @@ $('#new-po-line').click(function() {
|
||||
{% elif order.status == PurchaseOrderStatus.PLACED %}
|
||||
|
||||
$('#receive-selected-items').click(function() {
|
||||
var items = $("#po-line-table").bootstrapTable('getSelections');
|
||||
|
||||
if (items.length == 0) {
|
||||
items = $("#po-line-table").bootstrapTable('getData');
|
||||
}
|
||||
var items = getTableData('#po-line-table');
|
||||
|
||||
receivePurchaseOrderItems(
|
||||
{{ order.id }},
|
||||
|
@ -172,7 +172,7 @@ $("#view-list").click(function() {
|
||||
|
||||
{% if report_enabled %}
|
||||
$("#order-print").click(function() {
|
||||
var rows = $("#purchase-order-table").bootstrapTable('getSelections');
|
||||
var rows = getTableData('#purchase-order-table');
|
||||
|
||||
var orders = [];
|
||||
|
||||
|
@ -176,7 +176,7 @@ loadSalesOrderTable("#sales-order-table", {
|
||||
|
||||
{% if report_enabled %}
|
||||
$("#order-print").click(function() {
|
||||
var rows = $("#sales-order-table").bootstrapTable('getSelections');
|
||||
var rows = getTableData('#sales-order-table');
|
||||
|
||||
var orders = [];
|
||||
|
||||
|
@ -360,7 +360,9 @@
|
||||
<div id='opt-dropdown' class="btn-group">
|
||||
<button id='supplier-part-options' class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">{% trans "Options" %} <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class='dropdown-item' href='#' id='supplier-part-delete' title='{% trans "Delete supplier parts" %}'>{% trans "Delete" %}</a></li>
|
||||
<li><a class='dropdown-item' href='#' id='supplier-part-delete' title='{% trans "Delete supplier parts" %}'>
|
||||
<span class='fas fa-trash-alt icon-red'></span> {% trans "Delete" %}
|
||||
</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{% include "filter_list.html" with id="supplier-part" %}
|
||||
@ -443,27 +445,11 @@
|
||||
|
||||
$("#supplier-part-delete").click(function() {
|
||||
|
||||
var selections = $("#supplier-part-table").bootstrapTable("getSelections");
|
||||
var selections = getTableData('#supplier-part-table');
|
||||
|
||||
var requests = [];
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Supplier Parts?" %}',
|
||||
'{% trans "All selected supplier parts will be deleted" %}',
|
||||
{
|
||||
accept: function() {
|
||||
selections.forEach(function(part) {
|
||||
var url = `/api/company/part/${part.pk}/`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
deleteSupplierParts(selections, {
|
||||
success: reloadSupplierPartTable,
|
||||
});
|
||||
|
||||
$.when.apply($, requests).done(function() {
|
||||
reloadSupplierPartTable();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
loadSupplierPartTable(
|
||||
@ -472,7 +458,7 @@
|
||||
{
|
||||
params: {
|
||||
part: {{ part.id }},
|
||||
part_detail: false,
|
||||
part_detail: true,
|
||||
supplier_detail: true,
|
||||
manufacturer_detail: true,
|
||||
},
|
||||
@ -497,10 +483,10 @@
|
||||
|
||||
$("#manufacturer-part-delete").click(function() {
|
||||
|
||||
var selections = $("#manufacturer-part-table").bootstrapTable("getSelections");
|
||||
var selectionss = getTableData('#manufacturer-part-table');
|
||||
|
||||
deleteManufacturerParts(selections, {
|
||||
onSuccess: function() {
|
||||
success: function() {
|
||||
$("#manufacturer-part-table").bootstrapTable("refresh");
|
||||
}
|
||||
});
|
||||
@ -587,11 +573,7 @@
|
||||
$('#bom-item-delete').click(function() {
|
||||
|
||||
// Get a list of the selected BOM items
|
||||
var rows = $("#bom-table").bootstrapTable('getSelections');
|
||||
|
||||
if (rows.length == 0) {
|
||||
rows = $('#bom-table').bootstrapTable('getData');
|
||||
}
|
||||
var rows = getTableData('#bom-table');
|
||||
|
||||
deleteBomItems(rows, {
|
||||
success: function() {
|
||||
|
@ -254,7 +254,7 @@
|
||||
|
||||
$('#multi-location-print-label').click(function() {
|
||||
|
||||
var selections = $('#sublocation-table').bootstrapTable('getSelections');
|
||||
var selections = getTableData('#sublocation-table');
|
||||
|
||||
var locations = [];
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
/* exported
|
||||
inventreeGet,
|
||||
inventreeDelete,
|
||||
inventreeMultiDelete,
|
||||
inventreeFormDataUpload,
|
||||
showApiError,
|
||||
*/
|
||||
@ -171,6 +172,50 @@ function inventreeDelete(url, options={}) {
|
||||
return inventreePut(url, {}, options);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform a 'multi delete' operation:
|
||||
*
|
||||
* - Items are deleted sequentially from the database, rather than simultaneous requests
|
||||
* - This prevents potential overload / transaction issues in the DB backend
|
||||
*
|
||||
* Notes:
|
||||
* - Assumes that each item in the 'items' list has a parameter 'pk'
|
||||
*/
|
||||
function inventreeMultiDelete(url, items, options={}) {
|
||||
|
||||
if (!url.endsWith('/')) {
|
||||
url += '/';
|
||||
}
|
||||
|
||||
function doNextDelete() {
|
||||
if (items.length > 0) {
|
||||
var item = items.shift();
|
||||
|
||||
inventreeDelete(`${url}${item.pk}/`, {
|
||||
complete: doNextDelete
|
||||
});
|
||||
} else {
|
||||
if (options.modal) {
|
||||
$(options.modal).modal('hide');
|
||||
}
|
||||
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.modal) {
|
||||
showModalSpinner(options.modal);
|
||||
}
|
||||
|
||||
// Initiate the process
|
||||
doNextDelete();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display a notification with error information
|
||||
*/
|
||||
|
@ -693,41 +693,20 @@ function deleteBomItems(items, options={}) {
|
||||
`;
|
||||
|
||||
constructFormBody({}, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete selected BOM items?" %}',
|
||||
fields: {},
|
||||
preFormContent: html,
|
||||
submitText: '{% trans "Delete" %}',
|
||||
submitClass: 'danger',
|
||||
confirm: true,
|
||||
onSubmit: function(fields, opts) {
|
||||
// Individually send DELETE requests for each BOM item
|
||||
// We do *not* send these all at once, to prevent overloading the server
|
||||
|
||||
// Show the progress spinner
|
||||
$(opts.modal).find('#modal-progress-spinner').show();
|
||||
|
||||
function deleteNextBomItem() {
|
||||
|
||||
if (items.length > 0) {
|
||||
|
||||
var item = items.shift();
|
||||
|
||||
inventreeDelete(`/api/bom/${item.pk}/`,
|
||||
inventreeMultiDelete(
|
||||
'{% url "api-bom-list" %}',
|
||||
items,
|
||||
{
|
||||
complete: deleteNextBomItem,
|
||||
modal: opts.modal,
|
||||
success: options.success,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// Destroy this modal once all items are deleted
|
||||
$(opts.modal).modal('hide');
|
||||
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deleteNextBomItem();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -834,12 +834,7 @@ function loadBuildOutputTable(build_info, options={}) {
|
||||
var subtable = $(`#output-sub-table-${pk}`);
|
||||
|
||||
if (subtable.exists()) {
|
||||
var rows = subtable.bootstrapTable('getSelections');
|
||||
|
||||
// None selected? Use all!
|
||||
if (rows.length == 0) {
|
||||
rows = subtable.bootstrapTable('getData');
|
||||
}
|
||||
var rows = getTableData(`#output-sub-table-${pk}`);
|
||||
|
||||
allocateStockToBuild(
|
||||
build_info.pk,
|
||||
@ -1291,11 +1286,7 @@ function loadBuildOutputTable(build_info, options={}) {
|
||||
|
||||
// Complete multiple outputs
|
||||
$('#multi-output-complete').click(function() {
|
||||
var outputs = $(table).bootstrapTable('getSelections');
|
||||
|
||||
if (outputs.length == 0) {
|
||||
outputs = $(table).bootstrapTable('getData');
|
||||
}
|
||||
var outputs = getTableData(table);
|
||||
|
||||
completeBuildOutputs(
|
||||
build_info.pk,
|
||||
@ -1314,11 +1305,7 @@ function loadBuildOutputTable(build_info, options={}) {
|
||||
|
||||
// Delete multiple build outputs
|
||||
$('#multi-output-delete').click(function() {
|
||||
var outputs = $(table).bootstrapTable('getSelections');
|
||||
|
||||
if (outputs.length == 0) {
|
||||
outputs = $(table).bootstrapTable('getData');
|
||||
}
|
||||
var outputs = getTableData(table);
|
||||
|
||||
deleteBuildOutputs(
|
||||
build_info.pk,
|
||||
@ -1337,11 +1324,7 @@ function loadBuildOutputTable(build_info, options={}) {
|
||||
|
||||
// Print stock item labels
|
||||
$('#incomplete-output-print-label').click(function() {
|
||||
var outputs = $(table).bootstrapTable('getSelections');
|
||||
|
||||
if (outputs.length == 0) {
|
||||
outputs = $(table).bootstrapTable('getData');
|
||||
}
|
||||
var outputs = getTableData(table);
|
||||
|
||||
var stock_id_values = [];
|
||||
|
||||
|
@ -3,12 +3,11 @@
|
||||
/* globals
|
||||
constructForm,
|
||||
imageHoverIcon,
|
||||
inventreeDelete,
|
||||
inventreeMultiDelete,
|
||||
loadTableFilters,
|
||||
makeIconButton,
|
||||
renderLink,
|
||||
setupFilterList,
|
||||
showQuestionDialog,
|
||||
*/
|
||||
|
||||
/* exported
|
||||
@ -16,6 +15,8 @@
|
||||
createManufacturerPart,
|
||||
createSupplierPart,
|
||||
deleteManufacturerParts,
|
||||
deleteManufacturerPartParameters,
|
||||
deleteSupplierParts,
|
||||
editCompany,
|
||||
loadCompanyTable,
|
||||
loadManufacturerPartTable,
|
||||
@ -101,15 +102,6 @@ function editManufacturerPart(part, options={}) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteManufacturerPart(part, options={}) {
|
||||
|
||||
constructForm(`/api/company/part/manufacturer/${part}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Manufacturer Part" %}',
|
||||
onSuccess: options.onSuccess,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function supplierPartFields() {
|
||||
|
||||
@ -211,12 +203,76 @@ function editSupplierPart(part, options={}) {
|
||||
}
|
||||
|
||||
|
||||
function deleteSupplierPart(part, options={}) {
|
||||
/*
|
||||
* Delete one or more SupplierPart objects from the database.
|
||||
* - User will be provided with a modal form, showing all the parts to be deleted.
|
||||
* - Delete operations are performed sequentialy, not simultaneously
|
||||
*/
|
||||
function deleteSupplierParts(parts, options={}) {
|
||||
|
||||
constructForm(`/api/company/part/${part}/`, {
|
||||
if (parts.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
function renderPart(sup_part) {
|
||||
var part = sup_part.part_detail;
|
||||
var thumb = thumbnailImage(part.thumbnail || part.image);
|
||||
var supplier = '-';
|
||||
var MPN = '-';
|
||||
|
||||
if (sup_part.supplier_detail) {
|
||||
supplier = sup_part.supplier_detail.name;
|
||||
}
|
||||
|
||||
if (sup_part.manufacturer_part_detail) {
|
||||
MPN = sup_part.manufacturer_part_detail.MPN;
|
||||
}
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>${thumb} ${part.full_name}</td>
|
||||
<td>${sup_part.SKU}</td>
|
||||
<td>${supplier}</td>
|
||||
<td>${MPN}</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
var rows = '';
|
||||
|
||||
parts.forEach(function(sup_part) {
|
||||
rows += renderPart(sup_part);
|
||||
});
|
||||
|
||||
var html = `
|
||||
<div class='alert alert-block alert-danger'>
|
||||
{% trans "All selected supplier parts will be deleted" %}
|
||||
</div>
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tr>
|
||||
<th>{% trans "Part" %}</th>
|
||||
<th>{% trans "SKU" %}</th>
|
||||
<th>{% trans "Supplier" %}</th>
|
||||
<th>{% trans "MPN" %}</th>
|
||||
</tr>
|
||||
${rows}
|
||||
</table>
|
||||
`;
|
||||
|
||||
constructFormBody({}, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Supplier Part" %}',
|
||||
onSuccess: options.onSuccess,
|
||||
title: '{% trans "Delete Supplier Parts" %}',
|
||||
preFormContent: html,
|
||||
onSubmit: function(fields, opts) {
|
||||
|
||||
inventreeMultiDelete(
|
||||
'{% url "api-supplier-part-list" %}',
|
||||
parts,
|
||||
{
|
||||
modal: opts.modal,
|
||||
success: options.success
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -393,59 +449,117 @@ function loadCompanyTable(table, url, options={}) {
|
||||
}
|
||||
|
||||
|
||||
/* Delete one or more ManufacturerPart objects from the database.
|
||||
* - User will be provided with a modal form, showing all the parts to be deleted.
|
||||
* - Delete operations are performed sequentialy, not simultaneously
|
||||
*/
|
||||
function deleteManufacturerParts(selections, options={}) {
|
||||
|
||||
if (selections.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
function renderPart(man_part, opts={}) {
|
||||
var part = man_part.part_detail;
|
||||
var thumb = thumbnailImage(part.thumbnail || part.image);
|
||||
|
||||
var text = `
|
||||
return `
|
||||
<tr>
|
||||
<td>${thumb} ${part.full_name}</td>
|
||||
<td>${man_part.MPN}</td>
|
||||
<td>${man_part.manufacturer_detail.name}</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
var rows = '';
|
||||
|
||||
selections.forEach(function(man_part) {
|
||||
rows += renderPart(man_part);
|
||||
});
|
||||
|
||||
var html = `
|
||||
<div class='alert alert-block alert-danger'>
|
||||
<p>{% trans "The following manufacturer parts will be deleted" %}:</p>
|
||||
<ul>`;
|
||||
{% trans "All selected manufacturer parts will be deleted" %}
|
||||
</div>
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tr>
|
||||
<th>{% trans "Part" %}</th>
|
||||
<th>{% trans "MPN" %}</th>
|
||||
<th>{% trans "Manufacturer" %}</th>
|
||||
</tr>
|
||||
${rows}
|
||||
</table>
|
||||
`;
|
||||
|
||||
selections.forEach(function(item) {
|
||||
parts.push(item.pk);
|
||||
constructFormBody({}, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Manufacturer Parts" %}',
|
||||
preFormContent: html,
|
||||
onSubmit: function(fields, opts) {
|
||||
|
||||
text += `
|
||||
<li>
|
||||
<p>${item.MPN} - ${item.part_detail.full_name}</p>
|
||||
</li>`;
|
||||
});
|
||||
|
||||
text += `
|
||||
</ul>
|
||||
</div>`;
|
||||
|
||||
showQuestionDialog(
|
||||
'{% trans "Delete Manufacturer Parts" %}',
|
||||
text,
|
||||
inventreeMultiDelete(
|
||||
'{% url "api-manufacturer-part-list" %}',
|
||||
selections,
|
||||
{
|
||||
accept_text: '{% trans "Delete" %}',
|
||||
accept: function() {
|
||||
|
||||
// Delete each manufacturer part
|
||||
var requests = [];
|
||||
|
||||
parts.forEach(function(pk) {
|
||||
var url = `/api/company/part/manufacturer/${pk}`;
|
||||
|
||||
requests.push(inventreeDelete(url));
|
||||
});
|
||||
|
||||
// Wait for all the requests to complete
|
||||
$.when.apply($, requests).done(function() {
|
||||
|
||||
if (options.onSuccess) {
|
||||
options.onSuccess();
|
||||
}
|
||||
});
|
||||
}
|
||||
modal: opts.modal,
|
||||
success: options.success,
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function deleteManufacturerPartParameters(selections, options={}) {
|
||||
|
||||
if (selections.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
function renderParam(param) {
|
||||
return `
|
||||
<tr>
|
||||
<td>${param.name}</td>
|
||||
<td>${param.units}</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
var rows = '';
|
||||
|
||||
selections.forEach(function(param) {
|
||||
rows += renderParam(param);
|
||||
});
|
||||
|
||||
var html = `
|
||||
<div class='alert alert-block alert-danger'>
|
||||
{% trans "All selected parameters will be deleted" %}
|
||||
</div>
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tr>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Value" %}</th>
|
||||
</tr>
|
||||
${rows}
|
||||
</table>
|
||||
`;
|
||||
|
||||
constructFormBody({}, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Parameters" %}',
|
||||
preFormContent: html,
|
||||
onSubmit: function(fields, opts) {
|
||||
inventreeMultiDelete(
|
||||
'{% url "api-manufacturer-part-parameter-list" %}',
|
||||
selections,
|
||||
{
|
||||
modal: opts.modal,
|
||||
success: options.success,
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function loadManufacturerPartTable(table, url, options) {
|
||||
@ -473,6 +587,7 @@ function loadManufacturerPartTable(table, url, options) {
|
||||
method: 'get',
|
||||
original: params,
|
||||
queryParams: filters,
|
||||
uniqueId: 'pk',
|
||||
sidePagination: 'server',
|
||||
name: 'manufacturerparts',
|
||||
groupBy: false,
|
||||
@ -588,11 +703,12 @@ function loadManufacturerPartTable(table, url, options) {
|
||||
|
||||
$(table).find('.button-manufacturer-part-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
||||
|
||||
deleteManufacturerPart(
|
||||
pk,
|
||||
deleteManufacturerParts(
|
||||
[row],
|
||||
{
|
||||
onSuccess: function() {
|
||||
success: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
}
|
||||
@ -618,7 +734,7 @@ function loadManufacturerPartParameterTable(table, url, options) {
|
||||
filters[key] = params[key];
|
||||
}
|
||||
|
||||
// setupFilterList("manufacturer-part-parameters", $(table));
|
||||
setupFilterList('manufacturer-part-parameters', $(table));
|
||||
|
||||
$(table).inventreeTable({
|
||||
url: url,
|
||||
@ -730,6 +846,7 @@ function loadSupplierPartTable(table, url, options) {
|
||||
method: 'get',
|
||||
original: params,
|
||||
sidePagination: 'server',
|
||||
uniqueId: 'pk',
|
||||
queryParams: filters,
|
||||
name: 'supplierparts',
|
||||
groupBy: false,
|
||||
@ -886,11 +1003,12 @@ function loadSupplierPartTable(table, url, options) {
|
||||
|
||||
$(table).find('.button-supplier-part-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
||||
|
||||
deleteSupplierPart(
|
||||
pk,
|
||||
deleteSupplierParts(
|
||||
[row],
|
||||
{
|
||||
onSuccess: function() {
|
||||
success: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
}
|
||||
|
@ -247,11 +247,6 @@ function constructChangeForm(fields, options) {
|
||||
*/
|
||||
function constructDeleteForm(fields, options) {
|
||||
|
||||
// Force the "confirm" property if not set
|
||||
if (!('confirm' in options)) {
|
||||
options.confirm = true;
|
||||
}
|
||||
|
||||
// Request existing data from the API endpoint
|
||||
// This data can be used to render some information on the form
|
||||
$.ajax({
|
||||
@ -430,6 +425,21 @@ function constructFormBody(fields, options) {
|
||||
// otherwise *all* fields will be displayed
|
||||
var displayed_fields = options.fields || fields;
|
||||
|
||||
// Override default option values if a 'DELETE' form is specified
|
||||
if (options.method == 'DELETE') {
|
||||
if (!('confirm' in options)) {
|
||||
options.confirm = true;
|
||||
}
|
||||
|
||||
if (!('submitClass' in options)) {
|
||||
options.submitClass = 'danger';
|
||||
}
|
||||
|
||||
if (!('submitText' in options)) {
|
||||
options.submitText = '{% trans "Delete" %}';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle initial data overrides
|
||||
if (options.data) {
|
||||
for (const field in options.data) {
|
||||
@ -797,7 +807,7 @@ function submitFormData(fields, options) {
|
||||
}
|
||||
|
||||
// Show the progress spinner
|
||||
$(options.modal).find('#modal-progress-spinner').show();
|
||||
showModalSpinner(options.modal);
|
||||
|
||||
// Submit data
|
||||
upload_func(
|
||||
@ -2625,7 +2635,7 @@ function selectImportFields(url, data={}, options={}) {
|
||||
columns.push(getFormFieldValue(`column_${idx}`, {}, opts));
|
||||
}
|
||||
|
||||
$(opts.modal).find('#modal-progress-spinner').show();
|
||||
showModalSpinner(opts.modal);
|
||||
|
||||
inventreePut(
|
||||
opts.url,
|
||||
|
@ -16,6 +16,7 @@
|
||||
showModalImage,
|
||||
removeRowFromModalForm,
|
||||
showQuestionDialog,
|
||||
showModalSpinner,
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -1146,3 +1147,13 @@ function showModalImage(image_url) {
|
||||
hideModalImage();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* Show (or hide) a progress spinner icon in the dialog */
|
||||
function showModalSpinner(modal, show=true) {
|
||||
if (show) {
|
||||
$(modal).find('#modal-progress-spinner').show();
|
||||
} else {
|
||||
$(modal).find('#modal-progress-spinner').hide();
|
||||
}
|
||||
}
|
||||
|
@ -1560,7 +1560,7 @@ function loadPartTable(table, url, options={}) {
|
||||
/* Button callbacks for part table buttons */
|
||||
|
||||
$('#multi-part-order').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var parts = [];
|
||||
|
||||
@ -1594,7 +1594,7 @@ function loadPartTable(table, url, options={}) {
|
||||
});
|
||||
|
||||
$('#multi-part-print-label').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var items = [];
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
global_settings,
|
||||
handleFormErrors,
|
||||
imageHoverIcon,
|
||||
inventreeDelete,
|
||||
inventreeGet,
|
||||
inventreeMultiDelete,
|
||||
inventreePut,
|
||||
launchModalForm,
|
||||
linkButtonsToSelection,
|
||||
@ -1106,25 +1106,15 @@ function adjustStock(action, items, options={}) {
|
||||
|
||||
// Delete action is handled differently
|
||||
if (action == 'delete') {
|
||||
var requests = [];
|
||||
|
||||
item_pk_values.forEach(function(pk) {
|
||||
requests.push(
|
||||
inventreeDelete(
|
||||
`/api/stock/${pk}/`,
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
// Wait for *all* the requests to complete
|
||||
$.when.apply($, requests).done(function() {
|
||||
// Destroy the modal window
|
||||
$(opts.modal).modal('hide');
|
||||
|
||||
if (options.success) {
|
||||
options.success();
|
||||
inventreeMultiDelete(
|
||||
'{% url "api-stock-list" %}',
|
||||
items,
|
||||
{
|
||||
modal: opts.modal,
|
||||
success: options.success,
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1955,7 +1945,7 @@ function loadStockTable(table, options) {
|
||||
);
|
||||
|
||||
function stockAdjustment(action) {
|
||||
var items = $(table).bootstrapTable('getSelections');
|
||||
var items = getTableData(table);
|
||||
|
||||
adjustStock(action, items, {
|
||||
success: function() {
|
||||
@ -1967,7 +1957,7 @@ function loadStockTable(table, options) {
|
||||
// Automatically link button callbacks
|
||||
|
||||
$('#multi-item-print-label').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var items = [];
|
||||
|
||||
@ -1979,7 +1969,7 @@ function loadStockTable(table, options) {
|
||||
});
|
||||
|
||||
$('#multi-item-print-test-report').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var items = [];
|
||||
|
||||
@ -1992,7 +1982,7 @@ function loadStockTable(table, options) {
|
||||
|
||||
if (global_settings.BARCODE_ENABLE) {
|
||||
$('#multi-item-barcode-scan-into-location').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var items = [];
|
||||
|
||||
@ -2021,7 +2011,7 @@ function loadStockTable(table, options) {
|
||||
});
|
||||
|
||||
$('#multi-item-merge').click(function() {
|
||||
var items = $(table).bootstrapTable('getSelections');
|
||||
var items = getTableData(table);
|
||||
|
||||
mergeStockItems(items, {
|
||||
success: function(response) {
|
||||
@ -2036,7 +2026,7 @@ function loadStockTable(table, options) {
|
||||
|
||||
$('#multi-item-assign').click(function() {
|
||||
|
||||
var items = $(table).bootstrapTable('getSelections');
|
||||
var items = getTableData(table);
|
||||
|
||||
assignStockToCustomer(items, {
|
||||
success: function() {
|
||||
@ -2046,7 +2036,8 @@ function loadStockTable(table, options) {
|
||||
});
|
||||
|
||||
$('#multi-item-order').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
|
||||
var selections = getTableData(table);
|
||||
|
||||
var parts = [];
|
||||
|
||||
@ -2063,7 +2054,7 @@ function loadStockTable(table, options) {
|
||||
|
||||
$('#multi-item-set-status').click(function() {
|
||||
// Select and set the STATUS field for selected stock items
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
// Select stock status
|
||||
var modal = '#modal-form';
|
||||
@ -2149,7 +2140,7 @@ function loadStockTable(table, options) {
|
||||
});
|
||||
|
||||
$('#multi-item-delete').click(function() {
|
||||
var selections = $(table).bootstrapTable('getSelections');
|
||||
var selections = getTableData(table);
|
||||
|
||||
var stock = [];
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
/* exported
|
||||
customGroupSorter,
|
||||
downloadTableData,
|
||||
getTableData,
|
||||
reloadtable,
|
||||
renderLink,
|
||||
reloadTableFilters,
|
||||
@ -22,6 +23,23 @@ function reloadtable(table) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the 'selected' data rows from a bootstrap table.
|
||||
* If allowEmpty = false, and the returned dataset is empty,
|
||||
* then instead try to return *all* the data
|
||||
*/
|
||||
function getTableData(table, allowEmpty=false) {
|
||||
|
||||
var data = $(table).bootstrapTable('getSelections');
|
||||
|
||||
if (data.length == 0 && !allowEmpty) {
|
||||
data = $(table).bootstrapTable('getData');
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Download data from a table, via the API.
|
||||
* This requires a number of conditions to be met:
|
||||
|
Loading…
Reference in New Issue
Block a user