From dfee02becb67aa32dac28cd7b572a80cfee483c1 Mon Sep 17 00:00:00 2001 From: Kurt Riddlesperger Date: Fri, 11 Oct 2019 14:23:39 -0500 Subject: [PATCH] viewjs consume: set specific_stock_entry based on location --- public/viewjs/consume.js | 77 +++++++++++++++++++++------------------- views/consume.blade.php | 2 +- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index e00ca4ef..c51fea58 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -5,11 +5,6 @@ var jsonForm = $('#consume-form').serializeJSON(); Grocy.FrontendHelpers.BeginUiBusy("consume-form"); - if ($("#use_specific_stock_entry").is(":checked")) - { - jsonForm.amount = 1; - } - var apiUrl = 'stock/products/' + jsonForm.product_id + '/consume'; var jsonData = {}; @@ -141,11 +136,6 @@ $('#save-mark-as-open-button').on('click', function(e) var jsonForm = $('#consume-form').serializeJSON(); Grocy.FrontendHelpers.BeginUiBusy("consume-form"); - if ($("#use_specific_stock_entry").is(":checked")) - { - jsonForm.amount = 1; - } - var apiUrl = 'stock/products/' + jsonForm.product_id + '/open'; jsonData = { }; @@ -191,6 +181,45 @@ $('#save-mark-as-open-button').on('click', function(e) ); }); +Grocy.Components.LocationPicker.GetPicker().on('change', function(e) +{ + var locationId = $(e.target).val(); + var sumValue = 0; + $("#specific_stock_entry").find("option").remove().end().append(""); + + if (locationId) + { + Grocy.Api.Get("stock/products/" + Grocy.Components.ProductPicker.GetValue() + '/entries', + function(stockEntries) + { + stockEntries.forEach(stockEntry => + { + if (stockEntry.location_id == locationId) + { + $("#specific_stock_entry").append($(""); @@ -210,10 +239,6 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) { $('#amount').attr('max', productDetails.stock_amount); $('#amount_qu_unit').text(productDetails.quantity_unit_stock.name); - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) - { - Grocy.Components.LocationPicker.SetId(productDetails.location.id); - } if (productDetails.product.allow_partial_units_in_stock == 1) { @@ -268,23 +293,6 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e) console.error(xhr); } ); - - Grocy.Api.Get("stock/products/" + productId + '/entries', - function(stockEntries) - { - stockEntries.forEach(stockEntry => - { - $("#specific_stock_entry").append($(""); $("#specific_stock_entry").attr("disabled", ""); - $("#amount").removeAttr("disabled"); - $("#amount").attr("required", ""); $("#specific_stock_entry").removeAttr("required"); } diff --git a/views/consume.blade.php b/views/consume.blade.php index f21013d4..0cb3ca71 100644 --- a/views/consume.blade.php +++ b/views/consume.blade.php @@ -22,7 +22,7 @@ 'label' => 'Amount', 'hintId' => 'amount_qu_unit', 'min' => 1, - 'value' => 1, + 'value' => 0, 'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'), 'additionalHtmlContextHelp' => '
' . $__t('Tare weight handling enabled - please weigh the whole container, the amount to be posted will be automatically calculcated') . '
' ))