diff -r aaefac2d08a3 -r 22d28dd9c041 www/js/rec_edit.js --- a/www/js/rec_edit.js Sat Dec 08 17:30:09 2018 +0100 +++ b/www/js/rec_edit.js Sun Dec 09 17:29:51 2018 +0100 @@ -107,9 +107,42 @@ $('#est_ibu').val(total_ibus); }; + function calcFermentablesFromOG(OG) { + + console.log("calcFermentablesFromOG("+OG+")"); + var i; + var efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal')); + var rows = $('#fermentableGrid').jqxGrid('getrows'); + var sug = sg_to_plato(OG) * parseFloat($("#batch_size").jqxNumberInput('decimal')) * OG / 100; //total amount of sugars in kg + var tot = 0; + var d; + for (i = 0; i < rows.length; i++) { + row = rows[i]; + d = row.f_percentage / 100 * (row.f_yield / 100) * (1 - row.f_moisture / 100); + if (row.f_added == "Mash") + d = efficiency / 100 * d; + tot += d; + } + + var totmass = 0; + if (tot) + totmass = sug / tot; + + if (totmass) { + for (i = 0; i < rows.length; i++) { + row = rows[i]; + $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", row.f_percentage / 100 * totmass); + } + } + //CalcWaterBalance; + }; + + function calcABV() { + $("#est_abv").val(abvol(parseFloat($("#est_og").jqxNumberInput('decimal')), parseFloat($("#est_fg").jqxNumberInput('decimal')))); + }; + function calcInit () { console.log("calc.init()"); -// $('#est_og').on('change', function (event) { calcFermentables(); }); $('#color_method').on('change', function (event) { calcFermentables(); }); $('#ibu_method').on('change', function (event) { calcFermentables(); @@ -477,7 +510,6 @@ }); // delete selected fermentable. - // Precentage aanpassen basis mout. $("#fdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 }); $("#fdeleterowbutton").on('click', function () { var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex'); @@ -514,6 +546,7 @@ $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100); } calcFermentables(); + calcABV(); calcIBUs(); }); }, @@ -649,6 +682,7 @@ }; $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc'); // TODO: not reliable calcFermentables(); + calcABV(); calcIBUs(); // Depends on gravity, so recalculate. }); }; @@ -1402,7 +1436,14 @@ $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true }); $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' }); - $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1, max: 1.9, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 }); + $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1.000, max: 1.200, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 }); + $('#est_og').on('change', function (event) { + console.log("est_og change:"+event.args.value+" by:"+event.args.type); + calcFermentablesFromOG(event.args.value); // Adjust fermentables amounts + calcFermentables(); // Update the recipe details + calcABV(); // and ABV + calcIBUs(); // and the IBU's. + }); $("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); $("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });