www/js/rec_edit.js

changeset 73
454fc4558609
parent 72
93a0be4f5be3
child 79
f3adf543f698
--- a/www/js/rec_edit.js	Fri Sep 28 17:29:23 2018 +0200
+++ b/www/js/rec_edit.js	Sun Sep 30 21:42:14 2018 +0200
@@ -51,6 +51,108 @@
 //		icon: { width: 25, height: 25, url: '../../images/smiley.png', padding: 5 }
 //	});
 
+	function calcFermentables (resize) {
+		console.log("calcFermentables(" + resize + ")");
+		// recalc grid percentages.
+		var t_amount = 0;
+		var rows = $('#fermentableGrid').jqxGrid('getboundrows');
+		for (var i = 0; i < rows.length; i++) {
+			var row = rows[i];
+			t_amount += row.f_amount;
+			console.log ("loop: " + i + "  kg:" + row.f_amount + "  pct:" + row.f_percentage + "  adjust:" + row.f_adjust_to_total_100);
+		}
+		console.log("total:" + t_amount);
+		for (var i = 0; i < rows.length; i++) {
+			var row = rows[i];
+			row.f_percentage = (row.f_amount / t_amount) * 100.0;
+		}
+		// if resize == true resize the malts bill.
+		// if recalc grid malts
+		$('#est_og').val(0);
+	};
+
+	function calcInit () {
+		console.log("calc.init()");
+		$('#est_og').on('change', function (event) { calcFermentables(true); });
+		$('#efficiency').on('change', function (event) { calcFermentables(true); });
+		$('#batch_size').on('change', function (event) { calcFermentables(true); });
+		$('#boil_time').on('change', function (event) { calcFermentables(true); });
+		$('#fermentableGrid').on('change', function (event) { calcFermentables(false); });
+	};
+
+	// Styles dropdown list
+	var stylesUrl = "includes/db_profile_styles.php";
+	var stylesSource = {
+		datatype: "json",
+		datafields: [
+			{ name: 'record', type: 'number' },
+		        { name: 'name', type: 'string' },
+			{ name: 'category', type: 'string' },
+			{ name: 'category_number', type: 'number' },
+			{ name: 'style_letter', type: 'string' },
+			{ name: 'style_guide', type: 'string' },
+			{ name: 'type', type: 'string' },
+			{ name: 'og_min', type: 'float' },
+			{ name: 'og_max', type: 'float' },
+			{ name: 'fg_min', type: 'float' },
+			{ name: 'fg_max', type: 'float' },
+			{ name: 'ibu_min', type: 'float' },
+			{ name: 'ibu_max', type: 'float' },
+			{ name: 'color_min', type: 'float' },
+			{ name: 'color_max', type: 'float' },
+			{ name: 'carb_min', type: 'float' },
+			{ name: 'carb_max', type: 'float' },
+			{ name: 'abv_min', type: 'float' },
+			{ name: 'abv_max', type: 'float' },
+			{ name: 'notes', type: 'string' },
+			{ name: 'profile', type: 'string' },
+			{ name: 'ingredients', type: 'string' },
+			{ name: 'examples', type: 'string' }
+		],
+		url: stylesUrl,
+		async: true
+	};
+	var styleslist = new $.jqx.dataAdapter(stylesSource);
+	$("#styleSelect").jqxDropDownList({
+		placeHolder: "Kies bierstijl:",
+		theme: theme,
+		source: styleslist,
+		displayMember: "name",
+		width: 150,
+		height: 27,
+		dropDownVerticalAlignment: 'top',
+		dropDownWidth: 500,
+		dropDownHeight: 380,
+		renderer: function (index, label, value) {
+			var datarecord = styleslist.records[index];
+			return datarecord.style_guide + " " + datarecord.style_letter+ " " + datarecord.name;
+		}
+	});
+	$("#styleSelect").on('select', function (event) {
+		if (event.args) {
+			var index = event.args.index;
+			var datarecord = styleslist.records[index];
+			$("#st_name").val(datarecord.name);
+			$("#st_category").val(datarecord.category);
+			$("#st_category_number").val(datarecord.category_number);
+			$("#st_letter").val(datarecord.style_letter);
+			$("#st_guide").val(datarecord.style_guide);
+			$("#st_type").val(datarecord.type);
+			$("#st_og_min").val(datarecord.og_min);
+			$("#st_og_max").val(datarecord.og_max);
+			$("#st_fg_min").val(datarecord.fg_min);
+			$("#st_fg_max").val(datarecord.fg_max);
+			$("#st_ibu_min").val(datarecord.ibu_min);
+			$("#st_ibu_max").val(datarecord.ibu_max);
+			$("#st_color_min").val(datarecord.color_min);
+			$("#st_color_max").val(datarecord.color_max);
+			$("#st_carb_min").val(datarecord.carb_min);
+			$("#st_carb_max").val(datarecord.carb_max);
+			$("#st_abv_min").val(datarecord.abv_min);
+			$("#st_abv_max").val(datarecord.abv_max);
+		}
+	});
+
 	var dataReecord = {};
 	var url = "includes/db_recipes.php";
 	// tooltips
@@ -261,7 +363,7 @@
 		var fermentablelist = new $.jqx.dataAdapter(fermentableInvSource);
 
 		$("#fermentableGrid").jqxGrid({
-			width: 960,
+			width: 1050,
 			height: 400,
 			source: fermentableAdapter,
 			theme: theme,
@@ -311,7 +413,9 @@
 						row["f_protein"] = datarecord.protein;
 						row["f_max_in_batch"] = datarecord.max_in_batch;
 						row["f_graintype"] = datarecord.graintype;
-						if (datarecord.type == "Sugar") {
+						if (datarecord.add_after_boil) {
+							row["f_added"] = "Primary";
+						} else if ((datarecord.type == "Sugar") || (datarecord.type == "Adjunct")) {
 							row["f_added"] = "Boil";
 						} else {
 							row["f_added"] = "Mash";
@@ -348,10 +452,11 @@
 				{ text: 'Mout/suiker', editable: false, datafield: 'f_name', 
 				  cellsrenderer:  function (row, columnfield, value, defaulthtml, columnproperties) {
 					var rowData = $("#fermentableGrid").jqxGrid('getrowdata', row);
-					return rowData.f_name + " (" + rowData.f_color + " EBC)";
+					return "<span style='margin: 3px; margin-top: 6px; float: "+columnproperties.cellsalign+"'>" +rowData.f_name + " (" + rowData.f_color + " EBC)</span>";
 				  }
 			       	},
 				{ text: 'Type', editable: false, width: 100, datafield: 'f_type' },
+				{ text: 'Moment', editable: false, width: 100, datafield: 'f_added' },
 				{ text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
 				{ text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
 				  columntype: 'numberinput',
@@ -364,7 +469,7 @@
 				  	return true;
 				  },
 				  initeditor: function (row, cellvalue, editor) {
-					editor.jqxNumberInput({ decimalDigits: 3 });
+					editor.jqxNumberInput({ inputMode: 'simple', decimalDigits: 3 });
 				  }
 				},
 				{ text: 'Procent', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1',
@@ -383,6 +488,7 @@
 			]
 		});
 		$("#fermentableGrid").on('cellendedit', function (event) {
+			calcFermentables(false);
 			$('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');
 		});
 	};
@@ -1128,6 +1234,8 @@
 		position: 'top'
 	});
 
+	calcInit();
+
 	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
 	$("#Delete").click(function () {
 		// Open a popup to confirm this action.
@@ -1173,18 +1281,18 @@
 			st_type: $('#st_type').val(),
 			st_category: $('#st_category').val(),
 			st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
-			st_og_min: dataRecord.st_og_min,
-			st_og_max: dataRecord.st_og_max,
-			st_fg_min: dataRecord.st_fg_min,
-			st_fg_max: dataRecord.st_fg_max,
-			st_ibu_min: dataRecord.st_ibu_min,
-			st_ibu_max: dataRecord.st_ibu_max,
-			st_color_min: dataRecord.st_color_min,
-			st_color_max: dataRecord.st_color_max,
-			st_carb_min: dataRecord.st_carb_min,
-			st_carb_max: dataRecord.st_carb_max,
-			st_abv_min: dataRecord.st_abv_min,
-			st_abv_max: dataRecord.st_abv_max,
+			st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')),
+			st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')),
+			st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')),
+			st_fg_max: parseFloat($("#st_fg_max").jqxNumberInput('decimal')),
+			st_ibu_min: parseFloat($("#st_ibu_min").jqxNumberInput('decimal')),
+			st_ibu_max: parseFloat($("#st_ibu_max").jqxNumberInput('decimal')),
+			st_color_min: parseFloat($("#st_color_min").jqxNumberInput('decimal')),
+			st_color_max: parseFloat($("#st_color_max").jqxNumberInput('decimal')),
+			st_carb_min: parseFloat($("#st_carb_min").jqxNumberInput('decimal')),
+			st_carb_max: parseFloat($("#st_carb_max").jqxNumberInput('decimal')),
+			st_abv_min: parseFloat($("#st_abv_min").jqxNumberInput('decimal')),
+			st_abv_max: parseFloat($("#st_abv_max").jqxNumberInput('decimal')),
 			type: $("#type").val(),
 			batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')),
 			boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),

mercurial