Added change batch size and efficiency.

Sun, 09 Dec 2018 20:55:40 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 09 Dec 2018 20:55:40 +0100
changeset 134
be59b9127978
parent 133
22d28dd9c041
child 135
cd1403633e96

Added change batch size and efficiency.

www/js/rec_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/rec_edit.js	Sun Dec 09 17:29:51 2018 +0100
+++ b/www/js/rec_edit.js	Sun Dec 09 20:55:40 2018 +0100
@@ -46,6 +46,7 @@
 
 	var	dataRecord = {};
 	var	to_100 = false;	// Fermentables adjust to 100%
+	var	g_batch_size = 20;
 	var	preboil_sg = 0;
 	var	sugarsm = 0;	// Sugars after mash
 	var	sugarsf = 0;	// Sugars after boil
@@ -70,6 +71,7 @@
 		var colorw = 0;	// Colors working
 		var my_100 = false;
 
+		g_batch_size = parseFloat($("#batch_size").jqxNumberInput('decimal'));
 		var rows = $('#fermentableGrid').jqxGrid('getrows');
 		for (var i = 0; i < rows.length; i++) {
 			var row = rows[i];
@@ -85,12 +87,12 @@
 				sugarsm += d;
 			}
 			sugarsf += d;
-			colorw += row.f_amount * ebc_to_srm(row.f_color) / parseFloat($("#batch_size").jqxNumberInput('decimal')) * 8.34436;
+			colorw += row.f_amount * ebc_to_srm(row.f_color) / g_batch_size * 8.34436;
 		}
 		if (to_100 != my_100)
 			console.log("change to_100 to:"+my_100);
 		to_100 = my_100;
-		$('#est_og').val(estimate_sg(sugarsf, parseFloat($("#batch_size").jqxNumberInput('decimal'))));
+		$('#est_og').val(estimate_sg(sugarsf, g_batch_size));
 		preboil_sg = estimate_sg(sugarsm, parseFloat($("#boil_size").jqxNumberInput('decimal')));
 		$('#est_color').val(kw_to_ebc($("#color_method").val(), colorw));
 	};
@@ -148,9 +150,32 @@
 			calcFermentables();
 			calcIBUs(); 
 		});
-//		$('#efficiency').on('change', function (event) { calcFermentables(); });
-//		$('#batch_size').on('change', function (event) { calcFermentables(); });
-//		$('#boil_time').on('change', function (event) { calcFermentables(); });
+		$('#batch_size').on('change', function (event) {
+			console.log("batch_size change:"+event.args.value+" old:"+g_batch_size);
+			var new_boil = Math.round((parseFloat(event.args.value) + parseFloat($("#boil_size").jqxNumberInput('decimal')) - g_batch_size) * 10) / 10;
+			$("#boil_size").val(new_boil);
+			calcFermentablesFromOG(parseFloat($("#est_og").jqxNumberInput('decimal')));     // Keep the OG
+			calcFermentables();
+			calcABV();
+			// TODO: adjust the hops, miscs, yeast, water.
+			calcIBUs();
+		});
+		$('#boil_time').on('change', function (event) {
+			console.log("boil_time change:"+event.args.value);
+		});
+		$('#efficiency').on('change', function (event) {
+			console.log("efficiency change:"+event.args.value);
+			calcFermentables();
+			calcABV();
+			calcIBUs();
+		});
+		$('#est_og').on('change', function (event) {
+			console.log("est_og change:"+event.args.value);
+			calcFermentablesFromOG(event.args.value);       // Adjust fermentables amounts
+			calcFermentables();                             // Update the recipe details
+			calcABV();                                      // and ABV
+			calcIBUs();                                     // and the IBU's.
+		});
 	};
 
 	// Styles dropdown list
@@ -1435,15 +1460,7 @@
 	$("#boil_size").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, readOnly: true, symbol: 'L', symbolPosition: 'right' });
 	$("#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.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 });
 

mercurial