www/js/rec_edit.js

changeset 226
40e68b18b50d
parent 225
ad2e1e3ccaca
child 227
fd6d87d1c9ed
--- a/www/js/rec_edit.js	Thu Jan 31 17:16:51 2019 +0100
+++ b/www/js/rec_edit.js	Thu Jan 31 22:39:36 2019 +0100
@@ -2031,13 +2031,14 @@
                                 { name: 'y_cost', type: 'float' },
                                 { name: 'y_type', type: 'int' },
                                 { name: 'y_form', type: 'int' },
-                                { name: 'y_time', type: 'float' },
+				{ name: 'y_flocculation', type: 'int' },
 				{ name: 'y_min_temperature', type: 'float' },
 				{ name: 'y_max_temperature', type: 'float' },
 				{ name: 'y_attenuation', type: 'float' },
-                                { name: 'y_amount_is_weight', type: 'int' },
 				{ name: 'y_use', type: 'int' },
-				{ name: 'y_weight', type: 'float' }
+				{ name: 'y_cells', type: 'float' },
+				{ name: 'y_inventory', type: 'float' },
+				{ name: 'y_avail', type: 'int' }
                         ],
                         addrow: function (rowid, rowdata, position, commit) {
                                 commit(true);
@@ -2046,31 +2047,13 @@
                                 commit(true);
                         }
                 };
-                var yeastAdapter = new $.jqx.dataAdapter(yeastSource, {
-			 beforeLoadComplete: function (records) {
-				var data = new Array();
-				for (var i = 0; i < records.length; i++) {
-					var row = records[i];
-					if (row.y_form == 'Liquid')
-						row.y_weight = Math.round(row.y_amount * 17);
-					else
-						row.y_weight = row.y_amount * 1000;
-					data.push(row);
-				}
-				return data;
-			},
-			loadError: function(jqXHR, status, error) {
-				$('#err').text(status + ' ' + error);
-			},
-		});
+                var yeastAdapter = new $.jqx.dataAdapter(yeastSource);
                 $("#yeastGrid").jqxGrid({
-                        width: 1050,
-                        height: 300,
+                        width: 1240,
+                        height: 525,
                         source: yeastAdapter,
                         theme: theme,
                         selectionmode: 'singlerow',
-                        editmode: 'selectedcell',
-                        editable: true,
                         localization: getLocalization(),
                         showtoolbar: true,
                         rendertoolbar: function (toolbar) {
@@ -2080,11 +2063,12 @@
                                 container.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');
 				container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
 				container.append('<div style="float: left; margin-left: 10px;" id="yinstockbutton"></div>');
-                                container.append('<input style="float: left; margin-left: 230px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
+                                container.append('<input style="float: left; margin-left: 400px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
                                 // add yeast from dropdownlist.
                                 $("#yaddrowbutton").jqxDropDownList({
                                         placeHolder: "Kies gist:",
                                         theme: theme,
+					template: "primary",
                                         source: yeastlist,
                                         displayMember: "name",
                                         width: 150,
@@ -2109,16 +2093,12 @@
                                                 row["y_amount"] = 0;
                                                 row["y_cost"] = datarecord.cost;
                                                 row["y_use"] = 0;
-                                                row["y_time"] = 0;
-						if (datarecord.form == 1) {
-							row["y_amount_is_weight"] = 1;
-						} else {
-							row["y_amount_is_weight"] = 0;
-						}
 						row["y_min_temperature"] = datarecord.min_temperature;
 						row["y_max_temperature"] = datarecord.max_temperature;
 						row["y_attenuation"] = datarecord.attenuation;
-						row["y_weight"] = 0;
+						row["y_flocculation"] = datarecord.flocculation;
+						row["y_cells"] = datarecord.cells;
+						row["y_inventory"] = datarecord.inventory;
                                                 var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
                                         }
                                 });
@@ -2128,7 +2108,7 @@
 					yeastlist.dataBind();
 				});
                                 // delete selected yeast.
-                                $("#ydeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+                                $("#ydeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
                                 $("#ydeleterowbutton").on('click', function () {
                                         var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
                                         var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
@@ -2143,60 +2123,73 @@
 				$('#jqxTabs').jqxTabs('next');
 			},
                         columns: [
-                                { text: 'Gist', editable: false, datafield: 'y_name' },
-				{ text: 'Laboratorium', editable: false, width: 150, datafield: 'y_laboratory' },
-				{ text: 'Code', editable: false, width: 90, datafield: 'y_product_id' },
-                                { text: 'Soort', editable: false, width: 80, align: 'center', cellsalign: 'center', datafield: 'y_form' },
-				{ text: 'Min.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
-				{ text: 'Max.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
-				{ text: 'Attn.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
-				{ text: 'Voor', width: 100, align: 'center', cellsalign: 'center', datafield: 'y_use', columntype: 'dropdownlist', 
-				  createeditor: function (row, column, editor) {
-					var srcYUse = [ "Primary", "Secondary", "Bottle" ];
-					editor.jqxDropDownList({ autoDropDownHeight: true, source: srcYUse });
+                                { text: 'Gist', datafield: 'y_name' },
+				{ text: 'Laboratorium', width: 150, datafield: 'y_laboratory' },
+				{ text: 'Code', width: 90, datafield: 'y_product_id' },
+                                { text: 'Soort', width: 100, datafield: 'y_form',
+				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
+					return "<div style='margin: 4px;'>" + YeastFormData[value].nl + "</div>";
+				  }
+				},
+				{ text: 'Min. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
+				{ text: 'Max. &deg;C', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
+				{ text: 'Attn. %', width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
+				{ text: 'Voor', width: 120, datafield: 'y_use',
+				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
+					return "<div style='margin: 4px;'>" + YeastUseData[value].nl + "</div>";
 				  }
 				},
-				{ datafield: 'y_amount', width: 90 },
-                                { text: 'Hoeveel', datafield: 'y_weight', width: 110, align: 'right', cellsalign: 'right',
-				  cellsformat: 'f1', columntype: 'numberinput',
+				{ text: 'Hoeveel', datafield: 'y_amount', width: 100, align: 'right',
 				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
-					if (rowdata.y_form == 'Liquid') {
+					if (rowdata.y_form == 0) {	// Liquid
 						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" pk</div>";
-					} else if (rowdata.y_form == 'Dry') {
-						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f1")+" gr</div>";
+					} else if (rowdata.y_form == 1) {	// Dry
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value*1000, "f1")+" gr</div>";
 					} else {
-						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" ml</div>";
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value*1000, "f0")+" ml</div>";
+					}
+                                  }
+                                },
+				{ text: 'Voorraad', datafield: 'y_inventory', width: 100, align: 'right',
+				  cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
+					if (rowdata.y_form == 0) {      // Liquid
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+" pk</div>";
+					} else if (rowdata.y_form == 1) {       // Dry
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value*1000, "f1")+" gr</div>";
+					} else {
+						return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value*1000, "f0")+" ml</div>";
 					}
-				  },
-				  initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
-					var form = $("#yeastGrid").jqxGrid('getcellvalue', args.rowindex, 'y_form');
-					if (form == 'Dry') {
-						editor.jqxNumberInput({ decimalDigits: 1, min: 0, spinButtons: false });
-					} else {
-						editor.jqxNumberInput({ decimalDigits: 0, min: 0, spinButtons: false });
+				  }
+				},
+				{ text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
+					return "Wijzig";
+					}, buttonclick: function (row) {
+						yeastRow = row;
+						yeastData = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
+						if (yeastData.y_form == 0) {
+							$("#wy_pmpt_amount").html("Pak(ken):");
+							$("#wy_amount").val(yeastData.y_amount);
+							$("#wy_amount").jqxNumberInput({ decimalDigits: 0, spinButtonsStep: 1 });
+						} else if (yeastData.y_form == 1) {
+							$("#wy_pmpt_amount").html("Gewicht gram:");
+							$("#wy_amount").val(yeastData.y_amount * 1000);
+							$("#wy_amount").jqxNumberInput({ decimalDigits: 1, spinButtonsStep: 0.5 });
+						} else {
+							$("#wy_pmpt_amount").html("Volume ml:");
+							$("#wy_amount").val(yeastData.y_amount * 1000);
+							$("#wy_amount").jqxNumberInput({ decimalDigits: 0, spinButtonsStep: 1 });
+						}
+						$("#wy_name").val(yeastData.y_name);
+						$("#wy_laboratory").val(yeastData.y_laboratory);
+						$("#wy_product_id").val(yeastData.y_product_id);
+						$("#wy_use").val(yeastData.y_use);
+						// show the popup window.
+						$("#popupYeast").jqxWindow('open');
 					}
-				  },
-                                  validation: function (cell, value) {
-                                        if (value < 0 || value > 100000000000 ) {
-                                                return { result: false, message: "Hoeveelheid moet 0-~ zijn" };
-                                        }
-                                        return true;
-                                  }
-                                }
+				}
                         ]
                 });
-		$("#yeastGrid").on('cellendedit', function (event) {
-			var args = event.args;
-			console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
-			$("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
-			if (args.datafield == 'y_weight') {
-				var form = $("#yeastGrid").jqxGrid('getcellvalue', args.rowindex, 'y_form');
-				if (form == 'Liquid')
-					$("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, 'y_amount', parseFloat(args.value * 0.0588));
-				else
-					$("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, 'y_amount', parseFloat(args.value / 1000));
-			}
-		});
+//		$("#yeastGrid").jqxGrid('setcellvalue', args.rowindex, 'y_amount', parseFloat(args.value * 0.0588));
         };
 
 	// inline mash editor
@@ -2879,6 +2872,99 @@
 	});
 
 	// Tab 5, Gist
+	$("#popupYeast").jqxWindow({
+		width: 800,
+		height: 300,
+		position: { x: 230, y: 100 },
+		resizable: false,
+		theme: theme,
+		isModal: true,
+		autoOpen: false,
+		cancelButton: $("#YeastReady"),
+		modalOpacity: 0.40
+	});
+	$("#YeastReady").jqxButton({ template: "success", width: '90px', theme: theme });
+	$("#YeastReady").click(function () {
+		$("#yeastGrid").jqxGrid('sortby', 'y_use', 'asc');
+	});
+	$("#wy_name").jqxInput({ theme: theme, width: 320, height: 23 });
+	$("#wy_laboratory").jqxInput({ theme: theme, width: 320, height: 23 });
+	$("#wy_product_id").jqxInput({ theme: theme, width: 320, height: 23 });
+	$("#wy_instock").jqxCheckBox({ theme: theme, height: 23 });
+	$("#wy_instock").on('change', function (event) {
+		yeastinstock = event.args.checked;
+		yeastlist.dataBind();
+	});
+	$("#wy_select").jqxDropDownList({
+		placeHolder: "Kies gist:",
+		theme: theme,
+		source: yeastlist,
+		displayMember: "name",
+		width: 150,
+		height: 23,
+		dropDownWidth: 500,
+		dropDownHeight: 500,
+		renderer: function (index, label, value) {
+			var datarecord = yeastlist.records[index];
+			return datarecord.laboratory+" "+datarecord.product_id+" "+datarecord.name;
+		}
+	});
+	$("#wy_select").on('select', function (event) {
+		if (event.args) {
+			var index = event.args.index;
+			var datarecord = yeastlist.records[index];
+			var rowdata = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
+			$("#wy_name").val(datarecord.name);
+			$("#wy_laboratory").val(datarecord.laboratory);
+			$("#wy_product_id").val(datarecord.product_id);
+			rowdata.y_name = datarecord.name;
+			rowdata.y_cost = datarecord.cost;
+			rowdata.y_type = datarecord.type;
+			rowdata.y_form = datarecord.form;
+			rowdata.y_laboratory = datarecord.laboratory;
+			rowdata.y_product_id = datarecord.product_id;
+			rowdata.y_min_temperature = datarecord.min_temperature;
+			rowdata.y_max_temperature = datarecord.max_temperature;
+			rowdata.y_flocculation = datarecord.flocculation;
+			rowdata.y_attenuation = datarecord.attenuation;
+			rowdata.y_cells = datarecord.cells;
+			rowdata.y_inventory = datarecord.inventory;
+			if (rowdata.y_form == 0) {
+				$("#wy_pmpt_amount").html("Pak(ken):");
+			} else if (rowdata.y_form == 1) {
+				$("#wy_pmpt_amount").html("Gewicht gram:");
+			} else {
+				$("#wy_pmpt_amount").html("Volume ml:");
+			}
+		}
+	});
+	$("#wy_amount").jqxNumberInput( Spin1dec5 );
+	$('#wy_amount').on('change', function (event) {
+		console.log("amount changed: "+event.args.value);
+		var rowdata = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
+		if (rowdata.y_form == 0)	// Liquid
+			var amount = parseFloat(event.args.value);
+		else
+			var amount = parseFloat(event.args.value) / 1000;
+		rowdata.y_amount = amount;
+	});
+	$("#wy_use").jqxDropDownList({
+		theme: theme,
+		source: YeastUseAdapter,
+		valueMember: 'id',
+		displayMember: 'nl',
+		width: 180,
+		height: 23,
+		autoDropDownHeight: true,
+		dropDownVerticalAlignment: 'top'
+	});
+	$("#wy_use").on('select', function (event) {
+		if (event.args) {
+			var index = event.args.index;
+			var rowdata = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
+			rowdata.y_use = index;
+		}
+	});
 
 	// Tab 6, Maischen
 	$("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 });

mercurial