www/js/recipes.js

changeset 60
dbbe408108ea
parent 59
ad28e09e3abd
child 61
3469979f83be
--- a/www/js/recipes.js	Fri Sep 21 17:10:41 2018 +0200
+++ b/www/js/recipes.js	Sat Sep 22 15:02:43 2018 +0200
@@ -102,6 +102,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// delete command is executed.
 					commit(true);
@@ -118,6 +119,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					commit(true);
 				},
@@ -133,6 +135,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// update command is executed.
 					commit(true);
@@ -471,8 +474,125 @@
                 })
         };
 
+	// Inline miscs editor
+        var editMisc = function (data) {
+                var miscSource = {
+                        localdata: data.miscs,
+                        datatype: "local",
+                        cache: false,
+                        datafields: [
+                                { name: 'm_name', type: 'string' },
+                                { name: 'm_amount', type: 'float' },
+                                { name: 'm_cost', type: 'float' },
+                                { name: 'm_type', type: 'string' },
+                                { name: 'm_use_use', type: 'string' },
+                                { name: 'm_time', type: 'float' },
+                                { name: 'm_amount_is_weight', type: 'bool' }
+                        ],
+                        addrow: function (rowid, rowdata, position, commit) {
+                                commit(true);
+                        },
+                        deleterow: function (rowid, commit) {
+                                commit(true);
+                        }
+                };
+                var miscAdapter = new $.jqx.dataAdapter(miscSource);
+                // dropdownlist datasource from inventory_miscs
+                var miscUrl = "getmiscsources.php";
+                var miscInvSource = {
+                        datatype: "json",
+                        datafields: [
+                                { name: 'record', type: 'number' },
+                                { name: 'name', type: 'string' },
+                                { name: 'type', type: 'string' },
+                                { name: 'use_use', type: 'string' },
+                                { name: 'amount_is_weight', type: 'bool' },
+                                { name: 'time', type: 'float' },
+                                { name: 'cost', type: 'float' }
+                        ],
+                        url: miscUrl,
+                        async: true
+                };
+                var misclist = new $.jqx.dataAdapter(miscInvSource);
 
-	// Inline miscs editor
+                $("#miscGrid").jqxGrid({
+                        width: 960,
+                        height: 400,
+                        source: miscAdapter,
+                        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="maddrowbutton"></div>');
+                                container.append('<input style="float: left; margin-left: 230px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');
+                                // add misc from dropdownlist.
+                                $("#maddrowbutton").jqxDropDownList({
+                                        placeHolder: "Kies ingredient:",
+                                        theme: theme,
+                                        source: misclist,
+                                        displayMember: "name",
+                                        width: 150,
+                                        height: 27,
+                                        dropDownWidth: 300
+                                });
+                                $("#maddrowbutton").on('select', function (event) {
+                                        if (event.args) {
+                                                var index = event.args.index;
+                                                var datarecord = misclist.records[index];
+                                                var row = {};
+                                                row["m_name"] = datarecord.name;
+                                                row["m_amount"] = 0;
+                                                row["m_cost"] = datarecord.cost;
+                                                row["m_type"] = datarecord.type;
+                                                row["m_use_use"] = datarecord.use_use;
+                                                row["m_time"] = 0;
+                                                row["m_amount_is_weight"] = datarecord.amount_is_weight;
+                                                var commit = $("#miscGrid").jqxGrid('addrow', null, row);
+                                        }
+                                });
+                                // delete selected misc.
+                                $("#mdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
+                                $("#mdeleterowbutton").on('click', function () {
+                                        var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex');
+                                        var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
+                                        if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
+                                                var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex);
+                                                var commit = $("#miscGrid").jqxGrid('deleterow', id);
+                                        }
+                                });
+                        },
+			columns: [
+                                { text: 'Ingredient', editable: false, datafield: 'm_name' },
+                                { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' },
+                                { text: 'Gebruik', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'm_use_use' },
+                                { text: 'Gewicht', datafield: 'm_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;
+                                  }
+                                },
+                                { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
+                                  columntype: 'numberinput',
+                                  validation: function (cell, value) {
+                                        if (value < 0 || value > 100000000000 ) {
+                                                return { result: false, message: "De tijd moet  0-~ zijn" };
+                                        }
+                                        return true;
+                                  }
+                                }
+                        ]
+                })
+        };
+
 
 	// Inline yeasts editor
 
@@ -672,6 +792,7 @@
 				$("#mash_name").val('');
 				editFermentable('');
 				editHop('');
+				editMisc('');
 				editWater('');
 				$("#popupWindow").jqxWindow('open');
 			});
@@ -716,6 +837,7 @@
 					$("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
 					editFermentable(dataRecord);
 					editHop(dataRecord);
+					editMisc(dataRecord);
 					editWater(dataRecord);
 					// show the popup window.
 					$("#popupWindow").jqxWindow('open');
@@ -767,6 +889,7 @@
 	$("#Save").click(function () {
 		var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
 		var hoprow = $('#hopGrid').jqxGrid('getrows');
+		var miscrow = $('#miscGrid').jqxGrid('getrows');
 		var waterrow = $('#waterGrid').jqxGrid('getrows');
 		if (editrow >= 0) {
 			var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
@@ -805,10 +928,10 @@
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
 				fermentables: fermentablerow,
 				hops: hoprow,
+				miscs: miscrow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
-			$("#popupWindow").jqxWindow('hide');
 		} else {
 			// Insert a record
 			var newrow = {
@@ -845,11 +968,12 @@
 				mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
 				fermentables: fermentablerow,
 				hops: hoprow,
+				miscs: miscrow,
 				waters: waterrow
 			};
 			$('#jqxgrid').jqxGrid('addrow', null, newrow);
-			$("#popupWindow").jqxWindow('hide');
 		}
+		$("#popupWindow").jqxWindow('hide');
 	});
 	createDelElements();
 });

mercurial