www/js/rec_edit.js

changeset 352
9d2a4703bdac
parent 350
c314277905e6
child 359
98354ef399cd
--- a/www/js/rec_edit.js	Wed May 08 22:23:52 2019 +0200
+++ b/www/js/rec_edit.js	Thu May 09 14:53:10 2019 +0200
@@ -311,6 +311,22 @@
 		return (result * amount * 1000) / vol;
 	}
 
+	function calcMash() {
+
+		if (!(rows = $('#mashGrid').jqxGrid('getrows')))
+                        return;
+		if (mashkg == 0)
+			return;
+
+		var infused = 0;
+		for (var i = 0; i < rows.length; i++) {
+			var row = $("#mashGrid").jqxGrid('getrowdata', i);
+			if (row.step_type == 0) // Infusion
+				infused += row.step_infuse_amount;
+                        $("#mashGrid").jqxGrid('setcellvalue', i, "step_thickness", infused / mashkg);
+		}
+	}
+
 	function calcIBUs() {
 		var total_ibus = 0;
 		hop_aroma = hop_flavour = 0;
@@ -1304,6 +1320,7 @@
 			calcIBUs();
 			calcWater();
 			calcSparge();
+			calcMash();
 		});
 		$('#boil_time').on('change', function (event) {
 			console.log("boil_time change:"+parseFloat(event.args.value)+" old:"+dataRecord.boil_time);
@@ -1332,6 +1349,7 @@
 			calcFermentablesFromOG(dataRecord.est_og);      // Adjust fermentables amounts
 			calcFermentables();                             // Update the recipe details
 			calcIBUs();                                     // and the IBU's.
+			calcMash();
 		});
 		$('#mash_ph').on('change', function (event) {
 			dataRecord.mash_ph = parseFloat(event.args.value);
@@ -2563,6 +2581,8 @@
 					var row = records[i];
 					if (row.step_type == 0)	// Infusion
 						mash_infuse += parseFloat(row.step_infuse_amount);
+					row.step_thickness = 0;	// Init this field.
+					data.push(row);
 				}
 			},	
 		});
@@ -2598,6 +2618,7 @@
 			ready: function() {
 				calcFermentables();
 				calcInit();
+				calcMash();
 				$('#jqxLoader').jqxLoader('close');
 				$('#jqxTabs').jqxTabs('first');
 			},
@@ -2799,6 +2820,7 @@
 		// Recalc percentages
 		calcFermentables();
 		calcIBUs();
+		calcMash();
 		// Waters: yes there is impact.
 	});
 	$("#wf_name").jqxInput({ theme: theme, width: 320, height: 23 });
@@ -2873,6 +2895,7 @@
 				$("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
 			}
 			calcFermentables();
+			calcMash();
 		};
 	});
 	$("#wf_percentage").jqxNumberInput( Perc1dec );
@@ -2909,6 +2932,7 @@
 						}
 					}
 					calcFermentables();
+					cacMash();
 				} else {
 					// Adjust all the rows.
 					var nw = tw * diff / 100;
@@ -2927,6 +2951,7 @@
 						}
 					}
 					calcFermentables();
+					calcMash();
 				}
 			}
 		}
@@ -2971,6 +2996,7 @@
 			$("#fermentableGrid").jqxGrid('setcellvalue', fermentableRow, 'f_added', index);
 			calcFermentables();
 			calcIBUs();
+			calcMash();
 		}
 	});
 
@@ -3410,18 +3436,7 @@
 	$("#MashReady").jqxButton({ template: "success", width: '90px', theme: theme });
 	$("#MashReady").click(function () {
 		$("#mashGrid").jqxGrid('sortby', 'step_temp', 'asc');
-		mash_infuse = 0;
-                var rows = $('#mashGrid').jqxGrid('getrows');
-                for (var i = 0; i < rows.length; i++) {
-                	var row = rows[i];
-                	if (row.step_type == 0) // Infusion
-                		mash_infuse += parseFloat(row.step_infuse_amount);
-			var rowdata = $("#mashGrid").jqxGrid('getrowdata', i);
-			if (mashkg > 0)
-				rowdata.step_thickness = parseFloat(mash_infuse / mashkg);
-			else
-				rowdata.step_thickness = 0;
-                }
+		calcMash();
 	});
 	$("#wstep_name").jqxInput({ theme: theme, width: 320, height: 23 });
 	$("#wstep_name").on('change', function (event) {

mercurial