www/js/recipes.js

changeset 61
3469979f83be
parent 60
dbbe408108ea
child 62
12c5eae75d1e
--- a/www/js/recipes.js	Sat Sep 22 15:02:43 2018 +0200
+++ b/www/js/recipes.js	Sat Sep 22 19:14:02 2018 +0200
@@ -593,8 +593,139 @@
                 })
         };
 
+	// Inline yeasts editor
+        var editYeast = function (data) {
+                var yeastSource = {
+                        localdata: data.yeasts,
+                        datatype: "local",
+                        cache: false,
+                        datafields: [
+                                { name: 'y_name', type: 'string' },
+				{ name: 'y_laboratory', type: 'string' },
+				{ name: 'y_product_id', type: 'string' },
+                                { name: 'y_amount', type: 'float' },
+                                { name: 'y_cost', type: 'float' },
+                                { name: 'y_type', type: 'string' },
+                                { name: 'y_form', type: 'string' },
+                                { name: 'y_time', type: 'float' },
+				{ name: 'y_min_temperature', type: 'float' },
+				{ name: 'y_max_temperature', type: 'float' },
+				{ name: 'y_attenuation', type: 'float' },
+                                { name: 'y_amount_is_weight', type: 'bool' },
+				{ name: 'y_use', type: 'string' }
+                        ],
+                        addrow: function (rowid, rowdata, position, commit) {
+                                commit(true);
+                        },
+                        deleterow: function (rowid, commit) {
+                                commit(true);
+                        }
+                };
+                var yeastAdapter = new $.jqx.dataAdapter(yeastSource);
+                // dropdownlist datasource from inventory_yeasts
+                var yeastUrl = "getyeastsources.php";
+                var yeastInvSource = {
+                        datatype: "json",
+                        datafields: [
+                                { name: 'record', type: 'number' },
+                                { name: 'name', type: 'string' },
+                                { name: 'type', type: 'string' },
+                                { name: 'form', type: 'string' },
+				{ name: 'laboratory', type: 'string' },
+				{ name: 'product_id', type: 'string' },
+				{ name: 'min_temperature', type: 'float' },
+				{ name: 'max_temperature', type: 'float' },
+				{ name: 'attenuation', type: 'float' },
+                                { name: 'cost', type: 'float' }
+                        ],
+                        url: yeastUrl,
+                        async: true
+                };
+                var yeastlist = new $.jqx.dataAdapter(yeastInvSource);
 
-	// Inline yeasts editor
+                $("#yeastGrid").jqxGrid({
+                        width: 1050,
+                        height: 300,
+                        source: yeastAdapter,
+                        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="yaddrowbutton"></div>');
+                                container.append('<input style="float: left; margin-left: 230px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
+                                // add yeast from dropdownlist.
+                                $("#yaddrowbutton").jqxDropDownList({
+                                        placeHolder: "Kies gist:",
+                                        theme: theme,
+                                        source: yeastlist,
+                                        displayMember: "name",
+                                        width: 150,
+                                        height: 27,
+                                        dropDownWidth: 300
+                                });
+                                $("#yaddrowbutton").on('select', function (event) {
+                                        if (event.args) {
+                                                var index = event.args.index;
+                                                var datarecord = yeastlist.records[index];
+                                                var row = {};
+                                                row["y_name"] = datarecord.name;
+						row["y_laboratory"] = datarecord.laboratory;
+						row["y_product_id"] = datarecord.product_id;
+						row["y_type"] = datarecord.type;
+						row["y_form"] = datarecord.form;
+                                                row["y_amount"] = 0;
+                                                row["y_cost"] = datarecord.cost;
+                                                row["y_use"] = "Primary";
+                                                row["y_time"] = 0;
+						if (datarecord.form == "Dry") {
+							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;
+                                                var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
+                                        }
+                                });
+                                // delete selected yeast.
+                                $("#ydeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+                                $("#ydeleterowbutton").on('click', function () {
+                                        var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
+                                        var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
+                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+                                                var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex);
+                                                var commit = $("#yeastGrid").jqxGrid('deleterow', id);
+                                        }
+                                });
+                        },
+                        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', editable: false, width: 80, align: 'center', cellsalign: 'center', datafield: 'y_use' },
+                                { text: 'Hoeveel', datafield: 'y_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f5',
+                                  columntype: 'numberinput',
+                                  validation: function (cell, value) {
+                                        if (value < 0 || value > 100000000000 ) {
+                                                return { result: false, message: "Volume moet  0-~ zijn" };
+                                        }
+                                        return true;
+                                  }
+                                }
+                        ]
+                })
+        };
 
 	// Inline waters editor
 	var editWater = function (data) {
@@ -793,6 +924,7 @@
 				editFermentable('');
 				editHop('');
 				editMisc('');
+				editYeast('');
 				editWater('');
 				$("#popupWindow").jqxWindow('open');
 			});
@@ -838,6 +970,7 @@
 					editFermentable(dataRecord);
 					editHop(dataRecord);
 					editMisc(dataRecord);
+					editYeast(dataRecord);
 					editWater(dataRecord);
 					// show the popup window.
 					$("#popupWindow").jqxWindow('open');
@@ -890,6 +1023,7 @@
 		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
 		var hoprow = $('#hopGrid').jqxGrid('getrows');
 		var miscrow = $('#miscGrid').jqxGrid('getrows');
+		var yeastrow = $('#yeastGrid').jqxGrid('getrows');
 		var waterrow = $('#waterGrid').jqxGrid('getrows');
 		if (editrow >= 0) {
 			var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
@@ -929,6 +1063,7 @@
 				fermentables: fermentablerow,
 				hops: hoprow,
 				miscs: miscrow,
+				yeasts: yeastrow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
@@ -969,6 +1104,7 @@
 				fermentables: fermentablerow,
 				hops: hoprow,
 				miscs: miscrow,
+				yeasts: yeastrow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('addrow', null, newrow);

mercurial