From 8030ca0bb9be0ce564d041b406f0024512f99000 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 22 Nov 2021 20:51:55 +1100 Subject: [PATCH] Allow user to select file format when downloadin BOM import template --- .../part/bom_upload/upload_file.html | 8 +++- InvenTree/templates/js/translated/bom.js | 43 ++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/InvenTree/part/templates/part/bom_upload/upload_file.html b/InvenTree/part/templates/part/bom_upload/upload_file.html index ab3b245010..061603efaf 100644 --- a/InvenTree/part/templates/part/bom_upload/upload_file.html +++ b/InvenTree/part/templates/part/bom_upload/upload_file.html @@ -31,7 +31,7 @@
{% trans "Requirements for BOM upload" %}:
@@ -59,4 +59,8 @@ enableSidebar('bom-upload'); -{% endblock js_ready %} +$('#bom-template-download').click(function() { + downloadBomTemplate(); +}); + +{% endblock js_ready %} \ No newline at end of file diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 1885624dd8..4f3dad2d20 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -2,6 +2,7 @@ /* globals constructForm, + exportFormatOptions, imageHoverIcon, inventreeGet, inventreePut, @@ -14,6 +15,7 @@ */ /* exported + downloadBomTemplate, newPartFromBomWizard, loadBomTable, loadUsedInTable, @@ -21,12 +23,41 @@ removeColFromBomWizard, */ -/* BOM management functions. - * Requires follwing files to be loaded first: - * - api.js - * - part.js - * - modals.js - */ +function downloadBomTemplate(options={}) { + + var format = options.format; + + if (!format) { + format = inventreeLoad('bom-export-format', 'csv'); + } + + constructFormBody({}, { + title: '{% trans "Download BOM Template" %}', + fields: { + format: { + label: '{% trans "Format" %}', + help_text: '{% trans "Select file format" %}', + required: true, + type: 'choice', + value: format, + choices: exportFormatOptions(), + } + }, + onSubmit: function(fields, opts) { + var format = getFormFieldValue('format', fields['format'], opts); + + // Save the format for next time + inventreeSave('bom-export-format', format); + + // Hide the modal + $(opts.modal).modal('hide'); + + // Download the file + location.href = `{% url "bom-upload-template" %}?format=${format}`; + + } + }); +} function bomItemFields() {