{% load i18n %} function loadBuildTable(table, options) { // Display a table of Build objects var params = options.params || {}; var filters = loadTableFilters("build"); for (var key in params) { filters[key] = params[key]; } setupFilterList("build", table); $(table).inventreeTable({ method: 'get', formatNoMatches: function() { return "{% trans "No builds matching query" %}"; }, url: options.url, queryParams: filters, groupBy: false, name: 'builds', original: params, columns: [ { field: 'pk', title: 'ID', visible: false, switchable: false, }, { field: 'title', title: '{% trans "Build" %}', sortable: true, formatter: function(value, row, index, field) { return renderLink(value, '/build/' + row.pk + '/'); } }, { field: 'part', title: '{% trans "Part" %}', sortable: true, formatter: function(value, row, index, field) { var name = row.part_detail.full_name; return imageHoverIcon(row.part_detail.thumbnail) + renderLink(name, '/part/' + row.part + '/'); } }, { field: 'quantity', title: '{% trans "Quantity" %}', sortable: true, }, { field: 'status', title: '{% trans "Status" %}', sortable: true, formatter: function(value, row, index, field) { return buildStatusDisplay(value); }, }, { field: 'creation_date', title: '{% trans "Created" %}', sortable: true, }, { field: 'completion_date', title: '{% trans "Completed" %}', sortable: true, }, ], }); } function updateAllocationTotal(id, count, required) { count = parseFloat(count); $('#allocation-total-'+id).html(count); var el = $("#allocation-panel-" + id); el.removeClass('part-allocation-pass part-allocation-underallocated part-allocation-overallocated'); if (count < required) { el.addClass('part-allocation-underallocated'); } else if (count > required) { el.addClass('part-allocation-overallocated'); } else { el.addClass('part-allocation-pass'); } } function loadAllocationTable(table, part_id, part, url, required, button) { // Load the allocation table table.bootstrapTable({ url: url, sortable: false, formatNoMatches: function() { return '{% trans "No parts allocated for" %} ' + part; }, columns: [ { field: 'stock_item_detail', title: '{% trans "Stock Item" %}', formatter: function(value, row, index, field) { return '' + parseFloat(value.quantity) + ' x ' + value.part_name + ' @ ' + value.location_name; } }, { field: 'stock_item_detail.quantity', title: '{% trans "Available" %}', formatter: function(value, row, index, field) { return parseFloat(value); } }, { field: 'quantity', title: '{% trans "Allocated" %}', formatter: function(value, row, index, field) { var html = parseFloat(value); var bEdit = ""; var bDel = ""; html += "
" + bEdit + bDel + "
"; return html; } } ], }); // Callback for 'new-item' button button.click(function() { launchModalForm(button.attr('url'), { success: function() { table.bootstrapTable('refresh'); }, }); }); table.on('load-success.bs.table', function(data) { // Extract table data var results = table.bootstrapTable('getData'); var count = 0; for (var i = 0; i < results.length; i++) { count += parseFloat(results[i].quantity); } updateAllocationTotal(part_id, count, required); }); // Button callbacks for editing and deleting the allocations table.on('click', '.item-edit-button', function() { var button = $(this); launchModalForm(button.attr('url'), { success: function() { table.bootstrapTable('refresh'); } }); }); table.on('click', '.item-del-button', function() { var button = $(this); launchModalForm(button.attr('url'), { success: function() { table.bootstrapTable('refresh'); } }); }); }