here we go js

This commit is contained in:
Matthias 2021-05-06 14:35:23 +02:00
parent a77d9d9de7
commit 8c63b53c16
11 changed files with 112 additions and 112 deletions

View File

@ -75,7 +75,7 @@ function postBarcodeData(barcode_data, options={}) {
enableBarcodeInput(modal, true); enableBarcodeInput(modal, true);
if (status == 'success') { if (status == 'success') {
if ('success' in response) { if ('success' in response) {
if (options.onScan) { if (options.onScan) {
options.onScan(response); options.onScan(response);
@ -125,7 +125,7 @@ function enableBarcodeInput(modal, enabled=true) {
var barcode = $(modal + ' #barcode'); var barcode = $(modal + ' #barcode');
barcode.prop('disabled', !enabled); barcode.prop('disabled', !enabled);
modalEnable(modal, enabled); modalEnable(modal, enabled);
barcode.focus(); barcode.focus();
@ -157,14 +157,14 @@ function barcodeDialog(title, options={}) {
var barcode = getBarcodeData(modal); var barcode = getBarcodeData(modal);
if (barcode && barcode.length > 0) { if (barcode && barcode.length > 0) {
postBarcodeData(barcode, options); postBarcodeData(barcode, options);
} }
} }
$(modal).on('shown.bs.modal', function() { $(modal).on('shown.bs.modal', function() {
$(modal + ' .modal-form-content').scrollTop(0); $(modal + ' .modal-form-content').scrollTop(0);
var barcode = $(modal + ' #barcode'); var barcode = $(modal + ' #barcode');
// Handle 'enter' key on barcode // Handle 'enter' key on barcode
@ -210,10 +210,10 @@ function barcodeDialog(title, options={}) {
var content = ''; var content = '';
content += `<div class='alert alert-info alert-block'>{% trans "Scan barcode data below" %}</div>`; content += `<div class='alert alert-info alert-block'>{% trans "Scan barcode data below" %}</div>`;
content += `<div id='barcode-error-message'></div>`; content += `<div id='barcode-error-message'></div>`;
content += `<form class='js-modal-form' method='post'>`; content += `<form class='js-modal-form' method='post'>`;
// Optional content before barcode input // Optional content before barcode input
content += `<div class='container' id='barcode-header'>`; content += `<div class='container' id='barcode-header'>`;
content += options.headerContent || ''; content += options.headerContent || '';
@ -254,14 +254,14 @@ function barcodeScanDialog() {
*/ */
var modal = '#modal-form'; var modal = '#modal-form';
barcodeDialog( barcodeDialog(
"Scan Barcode", "Scan Barcode",
{ {
onScan: function(response) { onScan: function(response) {
if ('url' in response) { if ('url' in response) {
$(modal).modal('hide'); $(modal).modal('hide');
// Redirect to the URL! // Redirect to the URL!
window.location.href = response.url; window.location.href = response.url;
} else { } else {
@ -399,7 +399,7 @@ function barcodeCheckIn(location_id, options={}) {
break; break;
} }
} }
if (match) { if (match) {
reloadTable(); reloadTable();
} }
@ -429,9 +429,9 @@ function barcodeCheckIn(location_id, options={}) {
onSubmit: function() { onSubmit: function() {
// Called when the 'check-in' button is pressed // Called when the 'check-in' button is pressed
var data = {location: location_id}; var data = {location: location_id};
// Extract 'notes' field // Extract 'notes' field
data.notes = $(modal + ' #notes').val(); data.notes = $(modal + ' #notes').val();

View File

@ -33,7 +33,7 @@ function removeRowFromBomWizard(e) {
var colNum = 0; var colNum = 0;
table.find('tr').each(function() { table.find('tr').each(function() {
colNum++; colNum++;
if (colNum >= 3) { if (colNum >= 3) {
@ -111,9 +111,9 @@ function loadBomTable(table, options) {
if (options.part_detail) { if (options.part_detail) {
params.part_detail = true; params.part_detail = true;
} }
params.sub_part_detail = true; params.sub_part_detail = true;
var filters = {}; var filters = {};
if (!options.disableFilters) { if (!options.disableFilters) {
@ -173,7 +173,7 @@ function loadBomTable(table, options) {
// Display an extra icon if this part is an assembly // Display an extra icon if this part is an assembly
if (sub_part.assembly) { if (sub_part.assembly) {
var text = `<span title='{% trans "Open subassembly" %}' class='fas fa-stream label-right'></span>`; var text = `<span title='{% trans "Open subassembly" %}' class='fas fa-stream label-right'></span>`;
html += renderLink(text, `/part/${row.sub_part}/bom/`); html += renderLink(text, `/part/${row.sub_part}/bom/`);
} }
@ -182,7 +182,7 @@ function loadBomTable(table, options) {
} }
); );
// Part description // Part description
cols.push( cols.push(
{ {
@ -325,7 +325,7 @@ function loadBomTable(table, options) {
sortable: true, sortable: true,
} }
) )
// Part notes // Part notes
cols.push( cols.push(
{ {
@ -348,18 +348,18 @@ function loadBomTable(table, options) {
if (row.part == options.parent_id) { if (row.part == options.parent_id) {
var bValidate = `<button title='{% trans "Validate BOM Item" %}' class='bom-validate-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-check-circle icon-blue'/></button>`; var bValidate = `<button title='{% trans "Validate BOM Item" %}' class='bom-validate-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-check-circle icon-blue'/></button>`;
var bValid = `<span title='{% trans "This line has been validated" %}' class='fas fa-check-double icon-green'/>`; var bValid = `<span title='{% trans "This line has been validated" %}' class='fas fa-check-double icon-green'/>`;
var bEdit = `<button title='{% trans "Edit BOM Item" %}' class='bom-edit-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-edit'></span></button>`; var bEdit = `<button title='{% trans "Edit BOM Item" %}' class='bom-edit-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-edit'></span></button>`;
var bDelt = `<button title='{% trans "Delete BOM Item" %}' class='bom-delete-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-trash-alt icon-red'></span></button>`; var bDelt = `<button title='{% trans "Delete BOM Item" %}' class='bom-delete-button btn btn-default btn-glyph' type='button' pk='${row.pk}'><span class='fas fa-trash-alt icon-red'></span></button>`;
var html = "<div class='btn-group' role='group'>"; var html = "<div class='btn-group' role='group'>";
html += bEdit; html += bEdit;
html += bDelt; html += bDelt;
if (!row.validated) { if (!row.validated) {
html += bValidate; html += bValidate;
} else { } else {
@ -394,7 +394,7 @@ function loadBomTable(table, options) {
{ {
success: function(response) { success: function(response) {
for (var idx = 0; idx < response.length; idx++) { for (var idx = 0; idx < response.length; idx++) {
response[idx].parentId = bom_pk; response[idx].parentId = bom_pk;
if (response[idx].sub_part_detail.assembly) { if (response[idx].sub_part_detail.assembly) {
@ -412,7 +412,7 @@ function loadBomTable(table, options) {
} }
) )
} }
table.inventreeTable({ table.inventreeTable({
treeEnable: !options.editable, treeEnable: !options.editable,
rootParentId: parent_id, rootParentId: parent_id,
@ -497,7 +497,7 @@ function loadBomTable(table, options) {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var url = `/part/bom/${pk}/delete/`; var url = `/part/bom/${pk}/delete/`;
launchModalForm( launchModalForm(
url, url,
{ {
@ -509,7 +509,7 @@ function loadBomTable(table, options) {
}); });
table.on('click', '.bom-edit-button', function() { table.on('click', '.bom-edit-button', function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var url = `/part/bom/${pk}/edit/`; var url = `/part/bom/${pk}/edit/`;
@ -524,7 +524,7 @@ function loadBomTable(table, options) {
}); });
table.on('click', '.bom-validate-button', function() { table.on('click', '.bom-validate-button', function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var url = `/api/bom/${pk}/validate/`; var url = `/api/bom/${pk}/validate/`;

View File

@ -49,7 +49,7 @@ function makeBuildOutputActionButtons(output, buildInfo, lines) {
function reloadTable() { function reloadTable() {
$(panel).find(`#allocation-table-${outputId}`).bootstrapTable('refresh'); $(panel).find(`#allocation-table-${outputId}`).bootstrapTable('refresh');
} }
// Find the div where the buttons will be displayed // Find the div where the buttons will be displayed
var buildActions = $(panel).find(`#output-actions-${outputId}`); var buildActions = $(panel).find(`#output-actions-${outputId}`);
@ -82,7 +82,7 @@ function makeBuildOutputActionButtons(output, buildInfo, lines) {
//disabled: true //disabled: true
} }
); );
// Add a button to "delete" the particular build output // Add a button to "delete" the particular build output
html += makeIconButton( html += makeIconButton(
'fa-trash-alt icon-red', 'button-output-delete', outputId, 'fa-trash-alt icon-red', 'button-output-delete', outputId,
@ -171,7 +171,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
var partId = buildInfo.part; var partId = buildInfo.part;
var outputId = null; var outputId = null;
if (output) { if (output) {
outputId = output.pk; outputId = output.pk;
} else { } else {
@ -179,7 +179,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
} }
var table = options.table; var table = options.table;
if (options.table == null) { if (options.table == null) {
table = `#allocation-table-${outputId}`; table = `#allocation-table-${outputId}`;
} }
@ -187,7 +187,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
// If an "output" is specified, then only "trackable" parts are allocated // If an "output" is specified, then only "trackable" parts are allocated
// Otherwise, only "untrackable" parts are allowed // Otherwise, only "untrackable" parts are allowed
var trackable = ! !output; var trackable = ! !output;
function reloadTable() { function reloadTable() {
// Reload the entire build allocation table // Reload the entire build allocation table
$(table).bootstrapTable('refresh'); $(table).bootstrapTable('refresh');
@ -492,7 +492,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
if (row.stock_item_detail.location) { if (row.stock_item_detail.location) {
var text = row.stock_item_detail.location_name; var text = row.stock_item_detail.location_name;
var url = `/stock/location/${row.stock_item_detail.location}/`; var url = `/stock/location/${row.stock_item_detail.location}/`;
return renderLink(text, url); return renderLink(text, url);
} else { } else {
return '<i>{% trans "No location set" %}</i>'; return '<i>{% trans "No location set" %}</i>';
@ -600,7 +600,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
qA *= output.quantity; qA *= output.quantity;
qB *= output.quantity; qB *= output.quantity;
// Handle the case where both numerators are zero // Handle the case where both numerators are zero
if ((aA == 0) && (aB == 0)) { if ((aA == 0) && (aB == 0)) {
return (qA > qB) ? 1 : -1; return (qA > qB) ? 1 : -1;
@ -610,7 +610,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
if ((qA == 0) || (qB == 0)) { if ((qA == 0) || (qB == 0)) {
return 1; return 1;
} }
var progressA = parseFloat(aA) / qA; var progressA = parseFloat(aA) / qA;
var progressB = parseFloat(aB) / qB; var progressB = parseFloat(aB) / qB;
@ -618,7 +618,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
if (progressA == progressB) { if (progressA == progressB) {
return (qA < qB) ? 1 : -1; return (qA < qB) ? 1 : -1;
} }
return (progressA < progressB) ? 1 : -1; return (progressA < progressB) ? 1 : -1;
} }
}, },
@ -670,7 +670,7 @@ function loadBuildTable(table, options) {
var filters = {}; var filters = {};
params['part_detail'] = true; params['part_detail'] = true;
if (!options.disableFilters) { if (!options.disableFilters) {
filters = loadTableFilters("build"); filters = loadTableFilters("build");
} }
@ -801,11 +801,11 @@ function loadBuildTable(table, options) {
function updateAllocationTotal(id, count, required) { function updateAllocationTotal(id, count, required) {
count = parseFloat(count); count = parseFloat(count);
$('#allocation-total-'+id).html(count); $('#allocation-total-'+id).html(count);
var el = $("#allocation-panel-" + id); var el = $("#allocation-panel-" + id);
el.removeClass('part-allocation-pass part-allocation-underallocated part-allocation-overallocated'); el.removeClass('part-allocation-pass part-allocation-underallocated part-allocation-overallocated');
@ -819,7 +819,7 @@ function updateAllocationTotal(id, count, required) {
} }
function loadAllocationTable(table, part_id, part, url, required, button) { function loadAllocationTable(table, part_id, part, url, required, button) {
// Load the allocation table // Load the allocation table
table.bootstrapTable({ table.bootstrapTable({
url: url, url: url,
@ -848,9 +848,9 @@ function loadAllocationTable(table, part_id, part, url, required, button) {
var bEdit = "<button class='btn item-edit-button btn-sm' type='button' title='{% trans "Edit stock allocation" %}' url='/build/item/" + row.pk + "/edit/'><span class='fas fa-edit'></span></button>"; var bEdit = "<button class='btn item-edit-button btn-sm' type='button' title='{% trans "Edit stock allocation" %}' url='/build/item/" + row.pk + "/edit/'><span class='fas fa-edit'></span></button>";
var bDel = "<button class='btn item-del-button btn-sm' type='button' title='{% trans "Delete stock allocation" %}' url='/build/item/" + row.pk + "/delete/'><span class='fas fa-trash-alt icon-red'></span></button>"; var bDel = "<button class='btn item-del-button btn-sm' type='button' title='{% trans "Delete stock allocation" %}' url='/build/item/" + row.pk + "/delete/'><span class='fas fa-trash-alt icon-red'></span></button>";
html += "<div class='btn-group' style='float: right;'>" + bEdit + bDel + "</div>"; html += "<div class='btn-group' style='float: right;'>" + bEdit + bDel + "</div>";
return html; return html;
} }
} }
@ -992,7 +992,7 @@ function loadBuildPartsTable(table, options={}) {
// Display an extra icon if this part is an assembly // Display an extra icon if this part is an assembly
if (sub_part.assembly) { if (sub_part.assembly) {
var text = `<span title='{% trans "Open subassembly" %}' class='fas fa-stream label-right'></span>`; var text = `<span title='{% trans "Open subassembly" %}' class='fas fa-stream label-right'></span>`;
html += renderLink(text, `/part/${row.sub_part}/bom/`); html += renderLink(text, `/part/${row.sub_part}/bom/`);
} }

View File

@ -39,11 +39,11 @@ function loadCompanyTable(table, url, options={}) {
if (row.is_customer) { if (row.is_customer) {
html += `<span title='{% trans "Customer" %}' class='fas fa-user-tie label-right'></span>`; html += `<span title='{% trans "Customer" %}' class='fas fa-user-tie label-right'></span>`;
} }
if (row.is_manufacturer) { if (row.is_manufacturer) {
html += `<span title='{% trans "Manufacturer" %}' class='fas fa-industry label-right'></span>`; html += `<span title='{% trans "Manufacturer" %}' class='fas fa-industry label-right'></span>`;
} }
if (row.is_supplier) { if (row.is_supplier) {
html += `<span title='{% trans "Supplier" %}' class='fas fa-building label-right'></span>`; html += `<span title='{% trans "Supplier" %}' class='fas fa-building label-right'></span>`;
} }

View File

@ -185,11 +185,11 @@ function getFilterOptionList(tableKey, filterKey) {
function generateAvailableFilterList(tableKey) { function generateAvailableFilterList(tableKey) {
var remaining = getRemainingTableFilters(tableKey); var remaining = getRemainingTableFilters(tableKey);
var id = 'filter-tag-' + tableKey.toLowerCase(); var id = 'filter-tag-' + tableKey.toLowerCase();
var html = `<select class='form-control filter-input' id='${id}' name='tag'>`; var html = `<select class='form-control filter-input' id='${id}' name='tag'>`;
html += "<option value=''>{% trans 'Select filter' %}</option>"; html += "<option value=''>{% trans 'Select filter' %}</option>";
for (var opt in remaining) { for (var opt in remaining) {
@ -275,7 +275,7 @@ function setupFilterList(tableKey, table, target) {
var value = getFilterOptionValue(tableKey, key, filters[key]); var value = getFilterOptionValue(tableKey, key, filters[key]);
var title = getFilterTitle(tableKey, key); var title = getFilterTitle(tableKey, key);
var description = getFilterDescription(tableKey, key); var description = getFilterDescription(tableKey, key);
element.append(`<div title='${description}' class='filter-tag'>${title} = ${value}<span ${tag}='${key}' class='close'>x</span></div>`); element.append(`<div title='${description}' class='filter-tag'>${title} = ${value}<span ${tag}='${key}' class='close'>x</span></div>`);
} }
@ -287,7 +287,7 @@ function setupFilterList(tableKey, table, target) {
addClicked = true; addClicked = true;
var html = ''; var html = '';
//`<div class='filter-input'>`; //`<div class='filter-input'>`;
html += generateAvailableFilterList(tableKey); html += generateAvailableFilterList(tableKey);
@ -315,7 +315,7 @@ function setupFilterList(tableKey, table, target) {
if (tag && tag.length > 0) { if (tag && tag.length > 0) {
var filters = addTableFilter(tableKey, tag, val); var filters = addTableFilter(tableKey, tag, val);
reloadTable(table, filters); reloadTable(table, filters);
// Run this function again // Run this function again
setupFilterList(tableKey, table, target); setupFilterList(tableKey, table, target);
} }
@ -332,7 +332,7 @@ function setupFilterList(tableKey, table, target) {
// Add a callback for clearing all the filters // Add a callback for clearing all the filters
element.find(`#${clear}`).click(function() { element.find(`#${clear}`).click(function() {
var filters = clearTableFilters(tableKey); var filters = clearTableFilters(tableKey);
reloadTable(table, filters); reloadTable(table, filters);
setupFilterList(tableKey, table, target); setupFilterList(tableKey, table, target);

View File

@ -40,11 +40,11 @@ function printStockItemLabels(items, options={}) {
{ {
success: function(pk) { success: function(pk) {
var href = `/api/label/stock/${pk}/print/?`; var href = `/api/label/stock/${pk}/print/?`;
items.forEach(function(item) { items.forEach(function(item) {
href += `items[]=${item}&`; href += `items[]=${item}&`;
}); });
window.location.href = href; window.location.href = href;
} }
} }
@ -136,7 +136,7 @@ function selectLabel(labels, items, options={}) {
if (item.description) { if (item.description) {
text += ` - ${item.description}`; text += ` - ${item.description}`;
} }
return text; return text;
}, },
function(item) { function(item) {
@ -146,7 +146,7 @@ function selectLabel(labels, items, options={}) {
// Construct form // Construct form
var html = ''; var html = '';
if (items.length > 0) { if (items.length > 0) {
html += ` html += `
@ -172,7 +172,7 @@ function selectLabel(labels, items, options={}) {
openModal({ openModal({
modal: modal, modal: modal,
}); });
modalEnable(modal, true); modalEnable(modal, true);
modalSetTitle(modal, '{% trans "Select Label Template" %}'); modalSetTitle(modal, '{% trans "Select Label Template" %}');
modalSetContent(modal, html); modalSetContent(modal, html);

View File

@ -28,11 +28,11 @@ function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
* - valueFunc: optional function which takes an element and generates the value * - valueFunc: optional function which takes an element and generates the value
* - titleFunc: optional function which takes an element and generates a title * - titleFunc: optional function which takes an element and generates a title
*/ */
var options = []; var options = [];
elements.forEach(function(element) { elements.forEach(function(element) {
var text = textFunc(element); var text = textFunc(element);
var value = null; var value = null;
var title = null; var title = null;
@ -63,9 +63,9 @@ function setFieldOptions(fieldName, optionList, options={}) {
* - append: If true, options will be appended, otherwise will replace existing options. * - append: If true, options will be appended, otherwise will replace existing options.
*/ */
var append = options.append || false; var append = options.append || false;
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
var field = getFieldByName(modal, fieldName); var field = getFieldByName(modal, fieldName);
@ -153,7 +153,7 @@ function enableField(fieldName, enabled, options={}) {
} }
function clearField(fieldName, options={}) { function clearField(fieldName, options={}) {
setFieldValue(fieldName, '', options); setFieldValue(fieldName, '', options);
} }
@ -267,7 +267,7 @@ function afterForm(response, options) {
* - Redirect the browser to a different URL * - Redirect the browser to a different URL
* - Reload the page * - Reload the page
*/ */
// Should we show alerts immediately or cache them? // Should we show alerts immediately or cache them?
var cache = (options.follow && response.url) || var cache = (options.follow && response.url) ||
options.redirect || options.redirect ||
@ -393,11 +393,11 @@ function removeRowFromModalForm(e) {
function renderErrorMessage(xhr) { function renderErrorMessage(xhr) {
var html = '<b>' + xhr.statusText + '</b><br>'; var html = '<b>' + xhr.statusText + '</b><br>';
html += '<b>Error Code - ' + xhr.status + '</b><br><hr>'; html += '<b>Error Code - ' + xhr.status + '</b><br><hr>';
html += ` html += `
<div class='panel-group'> <div class='panel-group'>
<div class='panel panel-default'> <div class='panel panel-default'>
@ -410,7 +410,7 @@ function renderErrorMessage(xhr) {
<div class='panel-body'>`; <div class='panel-body'>`;
html += xhr.responseText; html += xhr.responseText;
html += ` html += `
</div> </div>
</div> </div>
@ -590,7 +590,7 @@ function insertNewItemButton(modal, options) {
var html = "<span style='float: right;'>"; var html = "<span style='float: right;'>";
html += "<div type='button' class='btn btn-primary btn-secondary'"; html += "<div type='button' class='btn btn-primary btn-secondary'";
if (options.title) { if (options.title) {
html += " title='" + options.title + "'"; html += " title='" + options.title + "'";
} }
@ -640,9 +640,9 @@ function attachSecondaryModal(modal, options) {
*/ */
var select = '#id_' + options.field; var select = '#id_' + options.field;
var option = new Option(response.text, response.pk, true, true); var option = new Option(response.text, response.pk, true, true);
$(modal).find(select).append(option).trigger('change'); $(modal).find(select).append(option).trigger('change');
} }
} }
@ -768,7 +768,7 @@ function handleModalForm(url, options) {
}, },
error: function(xhr, ajaxOptions, thrownError) { error: function(xhr, ajaxOptions, thrownError) {
// There was an error submitting form data via POST // There was an error submitting form data via POST
$(modal).modal('hide'); $(modal).modal('hide');
showAlertDialog('{% trans "Error posting form data" %}', renderErrorMessage(xhr)); showAlertDialog('{% trans "Error posting form data" %}', renderErrorMessage(xhr));
}, },

View File

@ -59,7 +59,7 @@ function makePartIcons(part, options={}) {
if (part.is_template) { if (part.is_template) {
html += makeIconBadge('fa-clone', '{% trans "Template part" %}'); html += makeIconBadge('fa-clone', '{% trans "Template part" %}');
} }
if (part.assembly) { if (part.assembly) {
html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}'); html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}');
} }
@ -71,13 +71,13 @@ function makePartIcons(part, options={}) {
if (part.salable) { if (part.salable) {
html += makeIconBadge('fa-dollar-sign', title='{% trans "Salable part" %}'); html += makeIconBadge('fa-dollar-sign', title='{% trans "Salable part" %}');
} }
if (!part.active) { if (!part.active) {
html += `<span class='label label-warning label-right'>{% trans "Inactive" %}</span>`; html += `<span class='label label-warning label-right'>{% trans "Inactive" %}</span>`;
} }
return html; return html;
} }
@ -118,14 +118,14 @@ function loadPartVariantTable(table, partId, options={}) {
name += row.IPN; name += row.IPN;
name += ' | '; name += ' | ';
} }
name += value; name += value;
if (row.revision) { if (row.revision) {
name += ' | '; name += ' | ';
name += row.revision; name += row.revision;
} }
if (row.is_template) { if (row.is_template) {
name = '<i>' + name + '</i>'; name = '<i>' + name + '</i>';
} }
@ -144,7 +144,7 @@ function loadPartVariantTable(table, partId, options={}) {
if (row.is_template) { if (row.is_template) {
html += makeIconBadge('fa-clone', '{% trans "Template part" %}'); html += makeIconBadge('fa-clone', '{% trans "Template part" %}');
} }
if (row.assembly) { if (row.assembly) {
html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}'); html += makeIconBadge('fa-tools', '{% trans "Assembled part" %}');
} }
@ -242,7 +242,7 @@ function loadParametricPartTable(table, options={}) {
} else { } else {
name += row.name; name += row.name;
} }
return renderLink(name, '/part/' + row.pk + '/'); return renderLink(name, '/part/' + row.pk + '/');
} }
}); });
@ -297,7 +297,7 @@ function loadPartTable(table, url, options={}) {
var params = options.params || {}; var params = options.params || {};
var filters = {}; var filters = {};
if (!options.disableFilters) { if (!options.disableFilters) {
filters = loadTableFilters("parts"); filters = loadTableFilters("parts");
} }
@ -359,7 +359,7 @@ function loadPartTable(table, url, options={}) {
} }
var display = imageHoverIcon(row.thumbnail) + renderLink(name, '/part/' + row.pk + '/'); var display = imageHoverIcon(row.thumbnail) + renderLink(name, '/part/' + row.pk + '/');
display += makePartIcons(row); display += makePartIcons(row);
return display; return display;
@ -378,7 +378,7 @@ function loadPartTable(table, url, options={}) {
return value; return value;
} }
}); });
columns.push({ columns.push({
sortable: true, sortable: true,
field: 'category_detail', field: 'category_detail',
@ -400,7 +400,7 @@ function loadPartTable(table, url, options={}) {
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var link = "stock"; var link = "stock";
if (value) { if (value) {
// There IS stock available for this part // There IS stock available for this part
@ -421,7 +421,7 @@ function loadPartTable(table, url, options={}) {
// There is no stock available // There is no stock available
value = "0<span class='label label-right label-danger'>{% trans "No Stock" %}</span>"; value = "0<span class='label label-right label-danger'>{% trans "No Stock" %}</span>";
} }
return renderLink(value, '/part/' + row.pk + "/" + link + "/"); return renderLink(value, '/part/' + row.pk + "/" + link + "/");
} }
}); });
@ -596,7 +596,7 @@ function loadPartTestTemplateTable(table, options) {
/* /*
* Load PartTestTemplate table. * Load PartTestTemplate table.
*/ */
var params = options.params || {}; var params = options.params || {};
var part = options.part || null; var part = options.part || null;
@ -671,7 +671,7 @@ function loadPartTestTemplateTable(table, options) {
if (row.part == part) { if (row.part == part) {
var html = `<div class='btn-group float-right' role='group'>`; var html = `<div class='btn-group float-right' role='group'>`;
html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}'); html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}');
html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}'); html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}');

View File

@ -65,7 +65,7 @@ function selectReport(reports, items, options={}) {
openModal({ openModal({
modal: modal, modal: modal,
}); });
modalEnable(modal, true); modalEnable(modal, true);
modalSetTitle(modal, '{% trans "Select Test Report Template" %}'); modalSetTitle(modal, '{% trans "Select Test Report Template" %}');
modalSetContent(modal, html); modalSetContent(modal, html);

View File

@ -75,7 +75,7 @@ function loadStockTestResultsTable(table, options) {
html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}'); html += makeIconButton('fa-edit icon-blue', 'button-test-edit', pk, '{% trans "Edit test result" %}');
html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}'); html += makeIconButton('fa-trash-alt icon-red', 'button-test-delete', pk, '{% trans "Delete test result" %}');
} }
html += "</div>"; html += "</div>";
return html; return html;
@ -185,11 +185,11 @@ function loadStockTestResultsTable(table, options) {
// Try to associate this result with a test row // Try to associate this result with a test row
tableData.forEach(function(row, index) { tableData.forEach(function(row, index) {
// The result matches the test template row // The result matches the test template row
if (key == row.key) { if (key == row.key) {
// Force the names to be the same! // Force the names to be the same!
item.test_name = row.test_name; item.test_name = row.test_name;
item.required = row.required; item.required = row.required;
@ -250,7 +250,7 @@ function loadStockTable(table, options) {
var filters = {}; var filters = {};
var filterKey = options.filterKey || options.name || "stock"; var filterKey = options.filterKey || options.name || "stock";
if (!options.disableFilters) { if (!options.disableFilters) {
filters = loadTableFilters(filterKey); filters = loadTableFilters(filterKey);
} }
@ -286,7 +286,7 @@ function loadStockTable(table, options) {
// URL (optional) // URL (optional)
var url = ''; var url = '';
if (row.is_building && row.build) { if (row.is_building && row.build) {
// StockItem is currently being built! // StockItem is currently being built!
text = '{% trans "In production" %}'; text = '{% trans "In production" %}';
@ -532,7 +532,7 @@ function loadStockTable(table, options) {
var name = row.part_detail.full_name; var name = row.part_detail.full_name;
html = imageHoverIcon(thumb) + renderLink(name, url); html = imageHoverIcon(thumb) + renderLink(name, url);
html += makePartIcons(row.part_detail); html += makePartIcons(row.part_detail);
return html; return html;
@ -574,7 +574,7 @@ function loadStockTable(table, options) {
} }
var html = renderLink(val, `/stock/item/${row.pk}/`); var html = renderLink(val, `/stock/item/${row.pk}/`);
if (row.is_building) { if (row.is_building) {
html += makeIconBadge('fa-tools', '{% trans "Stock item is in production" %}'); html += makeIconBadge('fa-tools', '{% trans "Stock item is in production" %}');
} }
@ -848,7 +848,7 @@ function loadStockTable(table, options) {
var status_code = label.val(); var status_code = label.val();
closeModal(modal); closeModal(modal);
if (!status_code) { if (!status_code) {
showAlertDialog( showAlertDialog(
'{% trans "Select Status Code" %}', '{% trans "Select Status Code" %}',
@ -1130,7 +1130,7 @@ function createNewStockItem(options) {
`/api/part/${value}/`, {}, `/api/part/${value}/`, {},
{ {
success: function(response) { success: function(response) {
// Disable serial number field if the part is not trackable // Disable serial number field if the part is not trackable
enableField('serial_numbers', response.trackable); enableField('serial_numbers', response.trackable);
clearField('serial_numbers'); clearField('serial_numbers');
@ -1141,7 +1141,7 @@ function createNewStockItem(options) {
clearField('expiry_date'); clearField('expiry_date');
} else { } else {
var expiry = moment().add(response.default_expiry, 'days'); var expiry = moment().add(response.default_expiry, 'days');
setFieldValue('expiry_date', expiry.format("YYYY-MM-DD")); setFieldValue('expiry_date', expiry.format("YYYY-MM-DD"));
} }
} }
@ -1295,7 +1295,7 @@ function loadInstalledInTable(table, options) {
// Add some buttons yo! // Add some buttons yo!
html += `<div class='btn-group float-right' role='group'>`; html += `<div class='btn-group float-right' role='group'>`;
html += makeIconButton('fa-unlink', 'button-uninstall', pk, "{% trans 'Uninstall stock item' %}"); html += makeIconButton('fa-unlink', 'button-uninstall', pk, "{% trans 'Uninstall stock item' %}");
html += `</div>`; html += `</div>`;
@ -1343,17 +1343,17 @@ function loadInstalledInTable(table, options) {
title: '{% trans "Part" %}', title: '{% trans "Part" %}',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var url = `/part/${row.sub_part}/`; var url = `/part/${row.sub_part}/`;
var thumb = row.sub_part_detail.thumbnail; var thumb = row.sub_part_detail.thumbnail;
var name = row.sub_part_detail.full_name; var name = row.sub_part_detail.full_name;
html = imageHoverIcon(thumb) + renderLink(name, url); html = imageHoverIcon(thumb) + renderLink(name, url);
if (row.not_in_bom) { if (row.not_in_bom) {
html = `<i>${html}</i>` html = `<i>${html}</i>`
} }
return html; return html;
} }
}, },
@ -1403,13 +1403,13 @@ function loadInstalledInTable(table, options) {
}, },
{ {
success: function(stock_items) { success: function(stock_items) {
var table_data = table.bootstrapTable('getData'); var table_data = table.bootstrapTable('getData');
stock_items.forEach(function(item) { stock_items.forEach(function(item) {
var match = false; var match = false;
for (var idx = 0; idx < table_data.length; idx++) { for (var idx = 0; idx < table_data.length; idx++) {
var row = table_data[idx]; var row = table_data[idx];
@ -1419,16 +1419,16 @@ function loadInstalledInTable(table, options) {
// Match on "sub_part" // Match on "sub_part"
if (row.sub_part == item.part) { if (row.sub_part == item.part) {
// First time? // First time?
if (row.installed_count == null) { if (row.installed_count == null) {
row.installed_count = 0; row.installed_count = 0;
row.installed_items = []; row.installed_items = [];
} }
row.installed_count += item.quantity; row.installed_count += item.quantity;
row.installed_items.push(item); row.installed_items.push(item);
// Push the row back into the table // Push the row back into the table
table.bootstrapTable('updateRow', idx, row, true); table.bootstrapTable('updateRow', idx, row, true);
@ -1445,7 +1445,7 @@ function loadInstalledInTable(table, options) {
if (!match) { if (!match) {
// The stock item did *not* match any items in the BOM! // The stock item did *not* match any items in the BOM!
// Add a new row to the table... // Add a new row to the table...
// Contruct a new "row" to add to the table // Contruct a new "row" to add to the table
var new_row = { var new_row = {
sub_part: item.part, sub_part: item.part,

View File

@ -94,7 +94,7 @@ function reloadTable(table, filters) {
} }
options.queryParams = function(tableParams) { options.queryParams = function(tableParams) {
for (key in params) { for (key in params) {
tableParams[key] = params[key]; tableParams[key] = params[key];
} }
@ -145,7 +145,7 @@ $.fn.inventreeTable = function(options) {
var filters = options.queryParams || options.filters || {}; var filters = options.queryParams || options.filters || {};
options.queryParams = function(params) { options.queryParams = function(params) {
// Override the way that we ask the server to sort results // Override the way that we ask the server to sort results
// It seems bootstrap-table does not offer a "native" way to do this... // It seems bootstrap-table does not offer a "native" way to do this...
if ('sort' in params) { if ('sort' in params) {
@ -200,7 +200,7 @@ $.fn.inventreeTable = function(options) {
// Callback when a column is changed // Callback when a column is changed
options.onColumnSwitch = function(field, checked) { options.onColumnSwitch = function(field, checked) {
var columns = table.bootstrapTable('getVisibleColumns'); var columns = table.bootstrapTable('getVisibleColumns');
var text = visibleColumnString(columns); var text = visibleColumnString(columns);
@ -225,7 +225,7 @@ $.fn.inventreeTable = function(options) {
if (visible && Array.isArray(visible)) { if (visible && Array.isArray(visible)) {
visible.forEach(function(column) { visible.forEach(function(column) {
// Visible field should *not* be visible! (hide it!) // Visible field should *not* be visible! (hide it!)
if (column.switchable && !columns.includes(column.field)) { if (column.switchable && !columns.includes(column.field)) {
table.bootstrapTable('hideColumn', column.field); table.bootstrapTable('hideColumn', column.field);
@ -301,7 +301,7 @@ function customGroupSorter(sortName, sortOrder, sortData) {
bb = bb.toString(); bb = bb.toString();
var cmp = aa.localeCompare(bb); var cmp = aa.localeCompare(bb);
if (cmp === -1) { if (cmp === -1) {
return order * -1; return order * -1;
} else if (cmp === 1) { } else if (cmp === 1) {