www/js/rec_edit.js

changeset 143
122f64716161
parent 142
793af7691a5e
child 144
ae15cfe5f008
--- a/www/js/rec_edit.js	Sat Dec 15 21:27:01 2018 +0100
+++ b/www/js/rec_edit.js	Sat Dec 15 23:22:11 2018 +0100
@@ -877,7 +877,7 @@
                 var hoplist = new $.jqx.dataAdapter(hopInvSource);
 
                 $("#hopGrid").jqxGrid({
-                        width: 1150,
+                        width: 1050,
                         height: 400,
                         source: hopAdapter,
                         theme: theme,
@@ -948,7 +948,13 @@
 				$('#jqxTabs').jqxTabs('next');
 			},
                         columns: [
-                                { text: 'Hop', editable: false, datafield: 'h_name' },
+                                { text: 'Hop', editable: false, datafield: 'h_name',
+				  cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
+					var rowData = $("#hopGrid").jqxGrid('getrowdata', row);
+					return "<span style='margin: 3px; margin-top: 6px; float: "+
+						columnproperties.cellsalign+"'>" +rowData.h_origin+" / "+rowData.h_name+"</span>";
+				  },
+			       	},
                                 { 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' },
@@ -1052,7 +1058,8 @@
                                 { name: 'm_type', type: 'string' },
                                 { name: 'm_use_use', type: 'string' },
                                 { name: 'm_time', type: 'float' },
-                                { name: 'm_amount_is_weight', type: 'bool' }
+                                { name: 'm_amount_is_weight', type: 'bool' },
+				{ name: 'm_weight', type: 'float' }
                         ],
                         addrow: function (rowid, rowdata, position, commit) {
                                 commit(true);
@@ -1061,7 +1068,20 @@
                                 commit(true);
                         }
                 };
-                var miscAdapter = new $.jqx.dataAdapter(miscSource);
+                var miscAdapter = new $.jqx.dataAdapter(miscSource, {
+			beforeLoadComplete: function (records) {
+				var data = new Array();
+				for (var i = 0; i < records.length; i++) {
+					var row = records[i];
+					row.m_weight = row.m_amount * 1000;
+					data.push(row);
+				}
+				return data;
+			},
+			loadError: function(jqXHR, status, error) {
+				$('#err').text(status + ' ' + error);
+			},
+		});
                 // dropdownlist datasource from inventory_miscs
                 var miscUrl = "getmiscsources.php";
                 var miscInvSource = {
@@ -1117,6 +1137,7 @@
                                                 row["m_type"] = datarecord.type;
                                                 row["m_use_use"] = datarecord.use_use;
                                                 row["m_time"] = 0;
+						row["m_weight"] = 0;
                                                 row["m_amount_is_weight"] = datarecord.amount_is_weight;
                                                 var commit = $("#miscGrid").jqxGrid('addrow', null, row);
                                         }
@@ -1146,12 +1167,11 @@
 			       	},
 				{ datafield: 'm_amount_is_weight', hidden: true },	// We need to declare this column
 				{ datafield: 'm_amount', hidden: true },		// We need to declare this column
-                                { text: 'Hoeveelheid', datafield: 'grammen', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f2',
+                                { text: 'Hoeveelheid', datafield: 'm_weight', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f2',
                                   columntype: 'numberinput',
 				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					var gram = rowdata.m_amount * 1000;
 					var vstr = rowdata.m_amount_is_weight ? "gr":"ml";
-					return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(gram,"f2")+" "+vstr+"</div>";
+					return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f2")+" "+vstr+"</div>";
 				  },
                                   validation: function (cell, value) {
 					var high = parseFloat(dataRecord.boil_size) * 1000;
@@ -1161,19 +1181,19 @@
                                         return true;
                                   },
 				  initeditor: function (row, cellvalue, editor) {
-					editor.jqxNumberInput({ inputMode: 'simple', min: 0, decimalDigits: 2, spinButtons: false });
+					editor.jqxNumberInput({
+						inputMode: 'simple', min: 0, max: parseFloat(dataRecord.boil_size) * 1000,
+						decimalDigits: 2, spinButtons: false
+					});
 				  }
                                 },
-				{ datafield: 'm_time' },
-                                { text: 'Tijd', datafield: 'time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
+                                { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
                                   columntype: 'numberinput',
 				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
 					if (rowdata.m_use_use == 'Boil') {
-						var tijd = rowdata.m_time;
-						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(tijd, "f0")+" m</div>";
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" m</div>";
 					} else if (rowdata.m_use_use == 'Secondary') {
-						var tijd = Math.round(rowdata.m_time / 1440);
-						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(tijd, "f0")+" d</div>";
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" d</div>";
 					} else {
 						var tijd = 0;
 						return "<div style='margin: 4px;' class='jqx-right-align'> </div>";
@@ -1184,7 +1204,7 @@
 				  },
 				  cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
 					var use = $("#miscGrid").jqxGrid('getcellvalue', row, "m_use_use");
-					if (use != "Boil")
+					if ((use != "Boil") && (use != "Secondary"))
 						return oldvalue;
 				  },
                                   validation: function (cell, value) {
@@ -1200,17 +1220,9 @@
 		$("#miscGrid").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 == 'grammen') {
-				$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_amount', parseFloat(args.value / 1000));
-			} else if (args.datafield == 'time') {
-				var use_use = $("#miscGrid").jqxGrid('getcellvalue', args.rowindex, 'm_use_use');
-				console.log("use: "+use_use);
-				if (use_use == 'Secondary')
-					$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_time', parseFloat(args.value * 1440));
-				else
-					$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_time', parseFloat(args.value));
-			} else {
-				$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
+			$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
+			if (args.datafield == 'm_weight') {
+				$("#miscGrid").jqxGrid('setcellvalue', args.rowindex, 'm_amount', parseFloat(args.value) / 1000);
 			}
 		});
         };

mercurial