www/js/profile_fermentation.js

changeset 487
06df1320327c
parent 286
124af734af68
child 494
af28ebe4a779
--- a/www/js/profile_fermentation.js	Fri Sep 13 16:15:51 2019 +0200
+++ b/www/js/profile_fermentation.js	Fri Sep 13 16:54:51 2019 +0200
@@ -44,14 +44,15 @@
 
 $(document).ready(function () {
 
-	var dataRecord = {};
-	var url = "includes/db_profile_fermentation.php";
 	// tooltips
 	$("#name").jqxTooltip({ content: 'De naam voor dit vergisting profiel.' });
 	$("#inittemp_lo").jqxTooltip({ content: 'De minimale begin temperatuur van dit profiel.' });
 	$("#inittemp_hi").jqxTooltip({ content: 'De maximale begin temperatuur van dit profiel.' });
+
+	var dataRecord = {},
+        url = 'includes/db_profile_fermentation.php',
 	// prepare the data
-	var source = {
+	source = {
 		datatype: "json",
 		cache: false,
 		datafields: [
@@ -77,8 +78,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);
@@ -95,6 +96,7 @@
 				type: "POST",
 				success: function (data, status, xhr) {
 					commit(true);
+					location.reload( true );
 				},
 				error: function(jqXHR, textStatus, errorThrown) {
                                         commit(false);
@@ -110,16 +112,16 @@
 				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);
 				}
 			});
 		}
-	};
-	var dataAdapter = new $.jqx.dataAdapter(source);
+	},
+	dataAdapter = new $.jqx.dataAdapter(source);
 
 	// Inline steps editor
 	var editsteps = function (data) {
@@ -150,8 +152,8 @@
 			deleterow: function (rowid, commit) {
 				commit(true);
 			}
-		};
-		var stepAdapter = new $.jqx.dataAdapter(stepSource);
+		},
+		stepAdapter = new $.jqx.dataAdapter(stepSource);
 		$("#grid").jqxGrid({
 			width: 800,
 			height: 330,
@@ -162,7 +164,6 @@
 			editable: true,
 			showtoolbar: true,
 			rendertoolbar: function (toolbar) {
-				var me = this;
 				var container = $("<div style='margin: 5px;'></div>");
 				toolbar.append(container);
 				container.append('<input style="margin-left: 100px;" id="addrowbutton" type="button" value="Nieuwe stap" />');
@@ -172,7 +173,7 @@
 				// create new row.
 				$("#addrowbutton").on('click', function () {
 					var datarow = generaterow();
-					var commit = $("#grid").jqxGrid('addrow', null, datarow);
+					$("#grid").jqxGrid('addrow', null, datarow);
 				});
 				// delete row.
 				$("#deleterowbutton").on('click', function () {
@@ -180,7 +181,7 @@
 					var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount;
 					if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
 						var id = $("#grid").jqxGrid('getrowid', selectedrowindex);
-						var commit = $("#grid").jqxGrid('deleterow', id);
+						$("#grid").jqxGrid('deleterow', id);
 					}
 				});
 			},
@@ -240,8 +241,8 @@
 		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 addButton, 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>");
 			container.append(addButton);
 			statusbar.append(container);
 			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
@@ -267,21 +268,23 @@
 			{ text: 'Stappen', datafield: 'totalsteps', width: 80, align: 'right', cellsalign: 'right' },
 			{ text: 'Tijdsduur', datafield: 'duration', width: 150, align: 'right',
 			  cellsrenderer:  function (row, columnfield, value, defaulthtml, column) {
+				var show, days, hours;
 				if (value < 24) {
-					var show = value+" uur";
+					show = value + ' uur';
 				} else {
-					var days = Math.floor(value / 24);
-					var hours = value % 24;
+					days = Math.floor(value / 24);
+					hours = value % 24;
 					if (days == 1)
-						var show = days+" dag, "+hours+" uur";
+						show = days + ' dag, ' + hours + ' uur';
 					else
-						var show = days+" dagen, "+hours+" uur";
+						show = days + ' dagen, ' + hours + ' uur';
 				}
-				return "<span style='margin: 3px; margin-top: 6px; float: right;'>"+show+"</span>";
+				return "<span style='margin: 3px; margin-top: 6px; float: right;'>" + show + "</span>";
 			  }
 		       	},
-			{ text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () {
-				return "Wijzig";
+			{ text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer:
+			 	function () {
+					return "Wijzig";
 				}, buttonclick: function (row) {
 					editrow = row;
 					// get the clicked row's data and initialize the input fields.
@@ -328,12 +331,11 @@
 	$("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
 	// update the edited row when the user clicks the 'Save' button.
 	$("#Save").click(function () {
-		var steprows = $('#grid').jqxGrid('getrows');
-		var rowID = -1;
+		var row, rowID = -1, steprows = $('#grid').jqxGrid('getrows');
 		if (editrow >= 0) {
-			var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
+			rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
 		}
-		var row = {
+		row = {
 			record: rowID,
 			uuid: dataRecord.uuid,
 			name: $("#name").val(),
@@ -348,7 +350,6 @@
 			$('#jqxgrid').jqxGrid('addrow', null, row);
 		}
 		$("#popupWindow").jqxWindow('hide');
-		location.reload( true );	// reload ourself.
 	});
 	createDelElements();
 });

mercurial