www/js/rec_edit.js

changeset 142
793af7691a5e
parent 141
fe9e2a677611
child 143
122f64716161
--- a/www/js/rec_edit.js	Sat Dec 15 11:06:14 2018 +0100
+++ b/www/js/rec_edit.js	Sat Dec 15 21:27:01 2018 +0100
@@ -826,7 +826,8 @@
 				{ name: 'h_carophyllene', type: 'float' },
 				{ name: 'h_cohumulone', type: 'float' },
 				{ name: 'h_myrcene', type: 'float' },
-				{ name: 'h_total_oil', type: 'float' }
+				{ name: 'h_total_oil', type: 'float' },
+				{ name: 'h_weight', type: 'float' }
                         ],
                         addrow: function (rowid, rowdata, position, commit) {
                                 commit(true);
@@ -835,7 +836,20 @@
                                 commit(true);
                         }
                 };
-                var hopAdapter = new $.jqx.dataAdapter(hopSource);
+                var hopAdapter = new $.jqx.dataAdapter(hopSource, {
+			beforeLoadComplete: function (records) {
+				var data = new Array();
+				for (var i = 0; i < records.length; i++) {
+					var row = records[i];
+					row.h_weight = row.h_amount * 1000;
+					data.push(row);
+				}
+			        return data;
+			},
+			loadError: function(jqXHR, status, error) {
+				$('#err').text(status + ' ' + error);
+			},
+		});
                 // dropdownlist datasource from inventory_hops
                 var hopUrl = "gethopsources.php";
                 var hopInvSource = {
@@ -863,7 +877,7 @@
                 var hoplist = new $.jqx.dataAdapter(hopInvSource);
 
                 $("#hopGrid").jqxGrid({
-                        width: 960,
+                        width: 1150,
                         height: 400,
                         source: hopAdapter,
                         theme: theme,
@@ -914,6 +928,7 @@
 						row["h_cohumulone"] = datarecord.cohumulone;
 						row["h_myrcene"] = datarecord.myrcene;
 						row["h_total_oil"] = datarecord.total_oil;
+						row["h_weight"] = 0;
                                                 var commit = $("#hopGrid").jqxGrid('addrow', null, row);
                                         }
                                 });
@@ -937,21 +952,29 @@
                                 { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' },
 				{ text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' },
                                 { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
-				// Edit the amount in grams, shoukd be fine for batches < 10 hl.
-				{ text: 'Gewicht gr', datafield: 'grams', width: 120, align: 'right', columntype: 'numberinput', cellsformat: 'f1',
+				{ text: 'Amount', hidden: true, datafield: 'h_amount' },
+				{ text: 'Gewicht gr', datafield: 'h_weight', width: 120, align: 'right', cellsalign: 'right',
+				  columntype: 'numberinput',
 				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var gram = rowdata.h_amount * 1000;
-					return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(gram, "f1") + " gr</div>";
+					return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(value, "f1") + " gr</div>";
+				  },
+				  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
+					editor.jqxNumberInput({
+						inputMode: 'simple',
+						symbol: ' gr', symbolPosition: 'right',
+						decimalDigits: 1,
+						min: 0, max: parseFloat(dataRecord.batch_size * 200),
+						spinButtons: false
+					});
 				  },
 				  validation: function (cell, value) {
-					var maxhops = parseFloat($("#batch_size").jqxNumberInput('decimal')) * 200;
+					var maxhops = parseFloat(dataRecord.batch_size) * 200;
 					if (value < 0 || value > maxhops ) {
-						return { result: false, message: "Gewicht moet 0-"+maxhops+" gram zijn" };
+						return { result: false, message: "Gewicht moet tussen 0 en "+maxhops+" gram zijn" };
 					}
 					return true;
 				  }
 				},
-				{ datafield: 'h_amount', hidden: true },	// We need to declare this column
 				{ text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat', columntype: 'dropdownlist',
 				  createeditor: function (row, column, editor) {
 					  var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ];
@@ -959,7 +982,7 @@
 				  },
 				  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
 					if ((newvalue == "Mash") || (newvalue == "First Wort")) {
-						$("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat($("#boil_time").jqxNumberInput('decimal')));
+						$("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat(dataRecord.boil_time));
 					} else if (newvalue == "Aroma") {
 						$("#hopGrid").jqxGrid('setcellvalue', row, "h_time", 0);
 					}
@@ -967,12 +990,18 @@
 				},
 				{ text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
 				  columntype: 'numberinput',
+				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
+					if ((rowdata.h_useat == "Boil") || (rowdata.h_useat == "Dry Hop") || (rowdata.h_useat == "Dry hop"))
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+"</div>";
+					else
+						return "<div style='margin: 4px;' class='jqx-right-align'> </div>";
+				  },
 				  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
 					editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) });
 				  },
 				  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
 					var use = $("#hopGrid").jqxGrid('getcellvalue', row, "h_useat");
-					if (use != "Boil")
+					if ((use == "Mash") || (use == "First Wort") || (use == "First wort") || (use == "Aroma"))
 						return oldvalue;
 				  },
 				  validation: function (cell, value) {
@@ -985,7 +1014,7 @@
 				},
 				{ text: 'IBU', editable: false, datafield: 'ibu', width: 80, align: 'right',
 				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					  var ibu = toIBU(rowdata.h_useat,
+					var ibu = toIBU(rowdata.h_useat,
 							  rowdata.h_form,
 							  preboil_sg,
 							  parseFloat($("#batch_size").jqxNumberInput('decimal')),
@@ -994,8 +1023,8 @@
 							  parseFloat(rowdata.h_alpha),
 							  $("#ibu_method").val()
 							 );
-					  calcIBUs();
-					  return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>";
+					calcIBUs();
+					return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>";
 				  }
 				}
                         ]
@@ -1003,12 +1032,10 @@
 		$("#hopGrid").on('cellendedit', function (event) {
 			var args = event.args;
 			console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
-			if (args.datafield == 'grams') {
-				$("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', parseFloat(args.value / 1000));
-			} else {
-				$("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
-			}
-//			//$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc');
+			$("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
+			if (args.datafield == 'h_weight')
+				$("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', args.value / 1000);
+			//$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc');
 		});
         };
 

mercurial