www/js/inv_fermentables.js

changeset 488
77f1617b6994
parent 477
7952f9331fd1
child 514
3c680d1dea35
--- a/www/js/inv_fermentables.js	Fri Sep 13 16:54:51 2019 +0200
+++ b/www/js/inv_fermentables.js	Fri Sep 13 20:24:31 2019 +0200
@@ -44,16 +44,15 @@
 
 $(document).ready(function () {
 
-	var dataRecord = {};
-
 	function calcTotal(cost, inventory) {
 
 		$('#totval').val(cost * inventory);
 	}
 
-	var url = "includes/db_inventory_fermentables.php";
+	var dataRecord = {},
+	url = 'includes/db_inventory_fermentables.php',
 	// prepare the data
-	var source = {
+	source = {
 		datatype: "json",
 		cache: false,
 		datafields: [
@@ -95,8 +94,8 @@
 				data: data,
 				type: "POST",
 				success: function (data, status, xhr) {
-					// delete command is executed.
 					commit(true);
+					location.reload( true );
 				},
 				error: function (jqXHR, textStatus, errorThrown) {
 					commit(false);
@@ -113,6 +112,7 @@
 				type: "POST",
                                	success: function (data, status, xhr) {
                                        	commit(true);
+					location.reload( true );
                                	},
                                	error: function(jqXHR, textStatus, errorThrown) {
                                         commit(false);
@@ -128,15 +128,18 @@
 				data: data,
 				type: "POST",
 				success: function (data, status, xhr) {
-					// update command is executed.
 					commit(true);
+					location.reload( true );
 				},
 				error: function(jqXHR, textStatus, errorThrown) {
 					commit(false);
 				}
 			});
 		}
-	};
+	},
+	dataAdapter = new $.jqx.dataAdapter(source),
+        editrow = -1;
+
 	// initialize the input fields.
 	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
 	$("#type").jqxDropDownList({
@@ -188,8 +191,6 @@
 	$("#tht_date").jqxDateTimeInput( Dateopts );
 	$("#totval").jqxNumberInput( Show2dec );
 
-	var dataAdapter = new $.jqx.dataAdapter(source);
-	var editrow = -1;
 	// initialize jqxGrid
 	$("#jqxgrid").jqxGrid({
 		width: 1280,
@@ -198,9 +199,10 @@
 		theme: theme,
 		showstatusbar: true,
 		renderstatusbar: function (statusbar) {
-			var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
-			var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
-			var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
+			var container, addButton, impButton;
+			container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
+			addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
+			impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
 			container.append(addButton);
 			container.append(impButton);
 			statusbar.append(container);
@@ -237,8 +239,7 @@
 				$("#popupWindow").jqxWindow('open');
 			});
 			impButton.click(function (event) {
-				var url="import_ingredients.php?select=fermentables";
-				window.location.href = url;
+				window.location.href = 'import_ingredients.php?select=fermentables';
 			});
 		},
 		filterable: true,
@@ -271,8 +272,9 @@
 				return "<span style='margin: 3px; margin-top: 6px; float: right;'>" + amount + "</span>";
 			  }
 			},
-			{ text: '', datafield: 'Edit', width: 100, align: 'center', menu: false, columntype: 'button', cellsrenderer: function () {
-				return "Wijzig";
+			{ text: '', datafield: 'Edit', width: 100, align: 'center', menu: false, columntype: 'button',
+				cellsrenderer: function () {
+					return "Wijzig";
 				}, buttonclick: function (row) {
 					// open the popup window when the user clicks a button.
 					editrow = row;
@@ -375,20 +377,18 @@
                         cost: parseFloat($('#cost').jqxNumberInput('decimal')),
                         production_date: '',
                         tht_date: ''
-
                 };
                 $('#jqxgrid').jqxGrid('addrow', null, row);
                 $('#popupWindow').jqxWindow('hide');
-                location.reload( true );        // reload ourself.
         });
 	$("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
 	// update the edited row when the user clicks the 'Save' button.
 	$("#Save").click(function() {
-		var rowID = -1;
+		var row, rowID = -1;
 		if (editrow >= 0) {
 			rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
 		}
-		var row = {
+		row = {
 			record: rowID,
 			name: $("#name").val(),
 			type: $("#type").val(),
@@ -419,7 +419,6 @@
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
 		} else {
 			$('#jqxgrid').jqxGrid('addrow', null, row);
-			location.reload( true );	// reload ourself.
 		}
 		$("#popupWindow").jqxWindow('hide');
 	});

mercurial