From 2e4613e702b776209c559bc3474be3c00044743e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 20 Oct 2020 22:37:21 +1100 Subject: [PATCH] Updates to build forms / etc --- .../static/script/inventree/modals.js | 26 ++++++++++++++++ InvenTree/build/templates/build/index.html | 7 +---- InvenTree/part/templates/part/build.html | 13 +++----- InvenTree/templates/js/build.html | 31 +++++++++++++++++++ 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/modals.js b/InvenTree/InvenTree/static/script/inventree/modals.js index 49de96468f..d7d42ac941 100644 --- a/InvenTree/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/InvenTree/static/script/inventree/modals.js @@ -134,6 +134,32 @@ function reloadFieldOptions(fieldName, options) { } +function enableField(fieldName, enabled, options={}) { + /* Enable (or disable) a particular field in a modal. + * + * Args: + * - fieldName: The name of the field + * - enabled: boolean enabled / disabled status + * - options: + */ + + var modal = options.modal || '#modal-form'; + + var field = getFieldByName(modal, fieldName); + + field.prop("disabled", !enabled); +} + +function clearField(fieldName, options={}) { + + var modal = options.modal || '#modal-form'; + + var field = getFieldByName(modal, fieldName); + + field.val(""); +} + + function partialMatcher(params, data) { /* Replacement function for the 'matcher' parameter for a select2 dropdown. diff --git a/InvenTree/build/templates/build/index.html b/InvenTree/build/templates/build/index.html index c15b2c2d33..44fc8cfecd 100644 --- a/InvenTree/build/templates/build/index.html +++ b/InvenTree/build/templates/build/index.html @@ -40,12 +40,7 @@ InvenTree | {% trans "Build Orders" %} $("#collapse-item-active").collapse().show(); $("#new-build").click(function() { - launchModalForm( - "{% url 'build-create' %}", - { - follow: true, - } - ); + newBuildOrder(); }); loadBuildTable($("#build-table"), { diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html index bfd72a2f70..d7ca33c673 100644 --- a/InvenTree/part/templates/part/build.html +++ b/InvenTree/part/templates/part/build.html @@ -29,14 +29,11 @@ {% block js_ready %} {{ block.super }} $("#start-build").click(function() { - launchModalForm( - "{% url 'build-create' %}", - { - follow: true, - data: { - part: {{ part.id }} - } - }); + newBuildOrder({ + data: { + part: {{ part.id }}, + } + }); }); loadBuildTable($("#build-table"), { diff --git a/InvenTree/templates/js/build.html b/InvenTree/templates/js/build.html index 6a12b97bfd..b72d3d179a 100644 --- a/InvenTree/templates/js/build.html +++ b/InvenTree/templates/js/build.html @@ -1,6 +1,37 @@ {% load i18n %} {% load inventree_extras %} +function newBuildOrder(options={}) { + /* Launch modal form to create a new BuildOrder. + */ + + launchModalForm( + "{% url 'build-create' %}", + { + follow: true, + data: options.data || {}, + callback: [ + { + field: 'part', + action: function(value) { + inventreeGet( + `/api/part/${value}/`, {}, + { + success: function(response) { + + //enableField('serial_numbers', response.trackable); + //clearField('serial_numbers'); + } + } + ); + }, + } + ], + } + ) + +} + function loadBuildTable(table, options) { // Display a table of Build objects