Start inline fermentables editor

Tue, 18 Sep 2018 23:16:14 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 18 Sep 2018 23:16:14 +0200
changeset 56
d4f4762e59b3
parent 55
3e29755638b6
child 57
bb9a06aa9acd

Start inline fermentables editor

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/js/recipes.js file | annotate | diff | comparison | revisions
--- a/www/import/from_brouwhulp.php	Thu Sep 06 21:05:44 2018 +0200
+++ b/www/import/from_brouwhulp.php	Tue Sep 18 23:16:14 2018 +0200
@@ -531,6 +531,8 @@
 					$fermentables .= ',';
 				$comma = TRUE;
 				$fermentables .= '{"f_name":"' . mysqli_real_escape_string($db, $fermentable->NAME) . '"';
+				$fermentables .= ',"f_origin":"' . mysqli_real_escape_string($db, $fermentable->ORIGIN) . '"';
+				$fermentables .= ',"f_supplier":"' . mysqli_real_escape_string($db, $fermentable->SUPPLIER) . '"';
 				$fermentables .= ',"f_amount":' . floatval($fermentable->AMOUNT);
 				$fermentables .= ',"f_cost":' . floatval($fermentable->COST);
 				$fermentables .= ',"f_type":"' . mysqli_real_escape_string($db, $fermentable->TYPE) . '"';
@@ -561,6 +563,8 @@
 				if ($fermentable->ADDED) {
 					$fermentables .= ',"f_added":"' . mysqli_real_escape_string($db, $fermentable->ADDED) . '"';
 				}
+				($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":true' : $fermentables .= ',"f_add_after_boil":false';
+				($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":true' : $fermentables .= ',"f_recommend_mash":false';
 				if ($fermentable->DISSOLVED_PROTEIN) {
 					$fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN);
 				}
--- a/www/js/recipes.js	Thu Sep 06 21:05:44 2018 +0200
+++ b/www/js/recipes.js	Tue Sep 18 23:16:14 2018 +0200
@@ -145,6 +145,140 @@
 	};
 	var dataAdapter = new $.jqx.dataAdapter(source);
 
+	// Inline fermentables editor
+	var editFermentable = function (data) {
+		var fermentableSource = {
+			localdata: data.fermentables,
+			datatype: "local",
+			datafields: [
+				{ name: 'f_name', type: 'string' },
+				{ name: 'f_origin', type: 'string' },
+				{ name: 'f_supplier', type: 'string' },
+				{ name: 'f_amount', type: 'float' },
+				{ name: 'f_cost', type: 'float' },
+				{ name: 'f_type', type: 'string' },
+				{ name: 'f_yield', type: 'float' },
+				{ name: 'f_color', type: 'float' },
+				{ name: 'f_coarse_fine_diff', type: 'float' },
+				{ name: 'f_moisture', type: 'float' },
+				{ name: 'f_diastatic_power', type: 'float' },
+				{ name: 'f_protein', type: 'float' },
+				{ name: 'f_max_in_batch', type: 'float' },
+				{ name: 'f_graintype', type: 'string' },
+				{ name: 'f_added', type: 'string' },
+				{ name: 'f_dissolved_protein', type: 'float' },
+				{ name: 'f_recommend_mash', type: 'bool' },
+				{ name: 'f_add_after_boil', type: 'bool' },
+				{ name: 'f_adjust_to_total_100', type: 'bool' },
+				{ name: 'f_di_ph', type: 'float' }
+			],
+			addrow: function (rowid, rowdata, position, commit) {
+				commit(true);
+			},
+			deleterow: function (rowid, commit) {
+				commit(true);
+			}
+		};
+		var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
+		// dropdownlist datasource from inventory_fermentables
+		var fermentableUrl = "getfermentablesources.php";
+		var fermentableInvSource = {
+			datatype: "json",
+			datafields: [
+				{ name: 'record', type: 'number' },
+				{ name: 'name', type: 'string' },
+				{ name: 'cost', type: 'float' },
+				{ name: 'type', type: 'string' },
+				{ name: 'yield', type: 'float' },
+				{ name: 'color', type: 'float' },
+				{ name: 'coarse_fine_diff', type: 'float' },
+				{ name: 'moisture', type: 'float' },
+				{ name: 'diastatic_power', type: 'float' },
+				{ name: 'protein', type: 'float' },
+				{ name: 'max_in_batch', type: 'float' },
+				{ name: 'graintype', type: 'string' },
+				{ name: 'added', type: 'string' },
+				{ name: 'dissolved_protein', type: 'float' },
+				{ name: 'adjust_to_total_100', type: 'bool' },
+				{ name: 'di_ph', type: 'float' }
+			],
+			url: fermentableUrl,
+			async: true
+		};
+		var fermentablelist = new $.jqx.dataAdapter(fermentableInvSource);
+
+		$("#fermentableGrid").jqxGrid({
+			width: 960,
+			height: 400,
+			source: fermentableAdapter,
+			theme: theme,
+			selectionmode: 'singlerow',
+			editmode: 'selectedrow',
+			editable: true,
+			localization: getLocalization(),
+			showtoolbar: true,
+			rendertoolbar: function (toolbar) {
+				var me = this;
+				var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
+				toolbar.append(container);
+				container.append('<div style="float: left; margin-left: 165px;" id="addrowbutton"></div>');
+				container.append('<input style="float: left; margin-left: 230px;" id="deleterowbutton" type="button" value="Verwijder mout" />');
+				// add fermentable from dropdownlist.
+				$("#addrowbutton").jqxDropDownList({
+					placeHolder: "Kies mout:",
+					theme: theme,
+					source: fermentablelist,
+					displayMember: "name",
+					width: 150,
+					height: 27,
+					dropDownWidth: 300
+				});
+				$("#addrowbutton").on('select', function (event) {
+					if (event.args) {
+						var index = event.args.index;
+						var datarecord = fermentablelist.records[index];
+						var row = {};
+						row["f_name"] = datarecord.name;
+						row["f_amount"] = 0;
+						row["f_cost"] = datarecord.cost;
+						var commit = $("#fermentableGrid").jqxGrid('addrow', null, row);
+					}
+				});
+
+				// delete selected fermentable.
+				// Precentage aanpassen basis mout.
+				$("#deleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+				$("#deleterowbutton").on('click', function () {
+					var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
+					var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
+					if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+						var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex);
+						var commit = $("#fermentableGrid").jqxGrid('deleterow', id);
+					}
+				});
+			},
+			columns: [
+				{ text: 'Mout/suiker', editable: false, datafield: 'f_name' },
+				{ text: 'Type', editable: false, width: 100, datafield: 'f_type' },
+				{ text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
+				  columntype: 'numberinput',
+				  validation: function (cell, value) {
+				  	if (value < 0 || value > 100000000000 ) {
+						return { result: false, message: "Volume moet  0-~ zijn" };
+				  	}
+				  	return true;
+				  }
+				}
+			]
+		})
+	};
+
+	// Inline hops editor
+
+	// Inline miscs editor
+
+	// Inline yeasts editor
+
 	// Inline waters editor
 	var editWater = function (data) {
 		var waterSource = {
@@ -202,6 +336,7 @@
 			selectionmode: 'singlerow',
 			editmode: 'selectedrow',
 			editable: true,
+			localization: getLocalization(),
 			showtoolbar: true,
 			rendertoolbar: function (toolbar) {
 				var me = this;
@@ -274,6 +409,8 @@
 		});
 	}; // editWater = function (data) {
 
+	// inline mash editor
+
 	// initialize the input fields.
 	var srcType = [ "All Grain", "Partial Mash", "Extract" ];
 	var srcColor = [ "Morey", "Mosher", "Daniels" ];
@@ -336,6 +473,7 @@
 				$("#mash_sparge_temp").val(78);
 				$("#mash_ph").val(5.4);
 				$("#mash_name").val('');
+				editFermentable('');
 				editWater('');
 				$("#popupWindow").jqxWindow('open');
 			});
@@ -378,6 +516,7 @@
 					$("#mash_name").val(dataRecord.mash_name);
 					$("#mash_ph").val(dataRecord.mash_ph);
 					$("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
+					editFermentable(dataRecord);
 					editWater(dataRecord);
 					// show the popup window.
 					$("#popupWindow").jqxWindow('open');
@@ -427,6 +566,7 @@
 	$("#Save").jqxButton({ width: '90px', theme: theme });
 	// update the edited row when the user clicks the 'Save' button.
 	$("#Save").click(function () {
+		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
 		var waterrow = $('#waterGrid').jqxGrid('getrows');
 		if (editrow >= 0) {
 			var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
@@ -463,6 +603,7 @@
 				mash_name: $("#mash_name").val(),
 				mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
+				fermentables: fermentablerow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
@@ -501,6 +642,7 @@
 				mash_name: $("#mash_name").val(),
 				mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
+				fermentables: fermentablerow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('addrow', null, newrow);

mercurial