First step to make profile mash work with indexes and make the edit screen universal.

Sat, 26 Jan 2019 22:01:11 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 26 Jan 2019 22:01:11 +0100
changeset 213
b0d484a5525e
parent 212
adda48f710cd
child 214
3e240fd7ef13

First step to make profile mash work with indexes and make the edit screen universal.

www/import/from_brouwhulp.php file | annotate | diff | comparison | revisions
www/includes/db_profile_mash.php file | annotate | diff | comparison | revisions
www/js/profile_mash.js file | annotate | diff | comparison | revisions
www/profile_mash.php file | annotate | diff | comparison | revisions
--- a/www/import/from_brouwhulp.php	Sat Jan 26 19:25:10 2019 +0100
+++ b/www/import/from_brouwhulp.php	Sat Jan 26 22:01:11 2019 +0100
@@ -573,9 +573,14 @@
 					$steps .= ',';
 				$comma = TRUE;
 				$steps .= '{"step_name":"' . mysqli_real_escape_string($db, $step->NAME) . '"';
-				if ($step->TYPE) {
-					$steps .= ',"step_type":"' . $step->TYPE . '"';
-				}
+				if ($step->TYPE == 'Infusion')
+					$steps .= ',"step_type":"0"';
+				else if ($step->TYPE == 'Temperature')
+					$steps .= ',"step_type":"1"';
+				else if ($step->TYPE == 'Decoction')
+					$steps .= ',"step_type":"2"';
+				else
+					echo "Unknown step TYPE " . $step->TYPE . PHP_EOL;
 				if ($step->STEP_TEMP) {
 					$steps .= ',"step_temp":"' . floatval($step->STEP_TEMP) . '"';
 				}
--- a/www/includes/db_profile_mash.php	Sat Jan 26 19:25:10 2019 +0100
+++ b/www/includes/db_profile_mash.php	Sat Jan 26 22:01:11 2019 +0100
@@ -16,36 +16,34 @@
 $rreplacements = array("\\'");
 $disallowed = array('visibleindex','uniqueid','boundindex','uid');
 
-// get data and store in a json array
-$query = "SELECT * FROM profile_mash ORDER BY name";
-if (isset($_GET['insert']) || isset($_GET['update'])) {
-	if (isset($_GET['insert'])) {
+if (isset($_POST['insert']) || isset($_POST['update'])) {
+	if (isset($_POST['insert'])) {
 		$sql  = "INSERT INTO";
 	}
-	if (isset($_GET['update'])) {
+	if (isset($_POST['update'])) {
 		$sql  = "UPDATE";
 	}
-	$sql .= " `profile_mash` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
-	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
-	$array = $_GET['steps'];
+	$sql .= " `profile_mash` SET name='" . mysqli_real_escape_string($connect, $_POST['name']);
+	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
+	$array = $_POST['steps'];
 	foreach($array as $key => $item){
 		foreach ($disallowed as $disallowed_key) {
 			unset($array[$key]["$disallowed_key"]);
 		}
 	}
 	$sql .= "', steps='" . str_replace($rescapers,$rreplacements,json_encode($array));
-	if (isset($_GET['insert'])) {
+	if (isset($_POST['insert'])) {
 		$sql .= "';";
 	}
-	if (isset($_GET['update'])) {
-		$sql .= "' WHERE record='" . $_GET['record'] . "';";
+	if (isset($_POST['update'])) {
+		$sql .= "' WHERE record='" . $_POST['record'] . "';";
 	}
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		if (isset($_GET['update'])) {
-			syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_GET['record']);
+		if (isset($_POST['update'])) {
+			syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_POST['record']);
 		} else {
 			$lastid = mysqli_insert_id($connect);
 			syslog(LOG_NOTICE, "db_profile_mash: inserted record ".$lastid);
@@ -53,19 +51,20 @@
 	}
 	echo $result;
 
-} else if (isset($_GET['delete'])) {
+} else if (isset($_POST['delete'])) {
 	// DELETE COMMAND
-	$sql = "DELETE FROM `profile_mash` WHERE record='".$_GET['record']."';";
+	$sql = "DELETE FROM `profile_mash` WHERE record='".$_POST['record']."';";
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		syslog(LOG_NOTICE, "db_profile_mash: deleted record ".$_GET['record']);
+		syslog(LOG_NOTICE, "db_profile_mash: deleted record ".$_POST['record']);
 	}
 	echo $result;
 
 } else {
 	// SELECT COMMAND
+	$query = "SELECT * FROM profile_mash ORDER BY name";
 	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
 	$mashprofiles = '[';
 	$comma = FALSE;
--- a/www/js/profile_mash.js	Sat Jan 26 19:25:10 2019 +0100
+++ b/www/js/profile_mash.js	Sat Jan 26 22:01:11 2019 +0100
@@ -46,8 +46,7 @@
 	var url = "includes/db_profile_mash.php";
 	// tooltips
 	$("#name").jqxTooltip({ content: 'De naam voor dit maisch profiel.' });
-	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit maich profiel.' });
-	$("#grid").jqxTooltip({ content: 'De maisch stappen in dit profiel.'});
+	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit maisch profiel.' });
 	// prepare the data
 	var source = {
 		datatype: "json",
@@ -68,6 +67,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// delete command is executed.
 					commit(true);
@@ -84,6 +84,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					commit(true);
 				},
@@ -99,6 +100,7 @@
 				url: url,
 				cache: false,
 				data: data,
+				type: "POST",
 				success: function (data, status, xhr) {
 					// update command is executed.
 					commit(true);
@@ -114,9 +116,9 @@
 	var editsteps = function (data) {
 		var generaterow = function () {
 			var row = {};
-			row["step_name"] = "Stap 1";
-			row["step_type"] = "Infusion";
-			row["step_temp"] = 62.0;
+			row['step_name'] = "Stap 1";
+			row['step_type'] = 0;
+			row['step_temp'] = 62.0;
 			row['step_time'] = 20.0;
 			row['ramp_time'] = 1.0;
 			row['end_temp'] = 62.0;
@@ -127,7 +129,7 @@
 			datatype: "local",
 			datafields: [
 				{ name: 'step_name', type: 'string' },
-				{ name: 'step_type', type: 'string' },
+				{ name: 'step_type', type: 'int' },
 				{ name: 'step_temp', type: 'float' },
 				{ name: 'step_time', type: 'float' },
 				{ name: 'ramp_time', type: 'float' },
@@ -147,8 +149,9 @@
 			source: stepAdapter,
 			theme: theme,
 			selectionmode: 'singlerow',
-			editmode: 'selectedrow',
+			editmode: 'selectedcell',
 			editable: true,
+			localization: getLocalization(),
 			showtoolbar: true,
 			rendertoolbar: function (toolbar) {
 				var me = this;
@@ -156,8 +159,8 @@
 				toolbar.append(container);
 				container.append('<input style="margin-left: 100px;" id="addrowbutton" type="button" value="Nieuwe stap" />');
 				container.append('<input style="margin-left: 290px;" id="deleterowbutton" type="button" value="Verwijder stap" />');
-				$("#addrowbutton").jqxButton({ theme: theme, width: 150 });
-				$("#deleterowbutton").jqxButton({ theme: theme, width: 150 });
+				$("#addrowbutton").jqxButton({ template: "primary", theme: theme, width: 150 });
+				$("#deleterowbutton").jqxButton({ template: "primary", theme: theme, width: 150 });
 				// create new row.
 				$("#addrowbutton").on('click', function () {
 					var datarow = generaterow();
@@ -175,9 +178,9 @@
 			},
 			columns: [
 				{ text: 'Stap naam', datafield: 'step_name' },
-				{ text: 'Stap type', datafield: 'step_type', width: 120, columntype: 'dropdownlist',
+				{ text: 'Stap type', datafield: 'step_type', width: 150, columntype: 'dropdownlist',
 				  createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
-				  	var dataSource = [ "Infusion", "Temperature", "Decoction" ];
+					var dataSource = [ "0", "1", "2" ];
 					editor.jqxDropDownList({
 						source: dataSource,
 						dropDownHeight: 95,
@@ -225,7 +228,7 @@
 	};
 
 	// initialize the input fields.
-	$("#name").jqxInput({ theme: theme, width: 250, height: 23 });
+	$("#name").jqxInput({ theme: theme, width: 480, height: 23 });
 	$("#notes").jqxInput({ theme: theme, width: 800, height: 100 });
 	var editrow = -1;
 	// initialize jqxGrid
@@ -241,12 +244,12 @@
 			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;'>Add</span></div>");
 			container.append(addButton);
 			statusbar.append(container);
-			addButton.jqxButton({ theme: theme, width: 120, height: 20 });
+			addButton.jqxButton({ theme: theme, width: 90, height: 20 });
 			// add new row.
 			addButton.click(function (event) {
 				editrow = -1;
-				$("#popupWindow").jqxWindow({ position: { x: 160, y: 30 } });
-				$("#name").val('');
+				$("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } });
+				$("#name").val('Nieuw maisch schema');
 				$("#notes").val('');
 				editsteps('');
 				$("#popupWindow").jqxWindow('open');
@@ -257,12 +260,12 @@
 		columns: [
 			{ text: 'Maish schema', datafield: 'name', width: 250 },
 			{ text: 'Opmerkingen', datafield: 'notes' },
-			{ text: 'Wijzig', datafield: 'Edit', width: 120, align: 'center', columntype: 'button', cellsrenderer: function () {
+			{ text: 'Wijzig', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () {
 				return "Wijzig";
 				}, buttonclick: function (row) {
 					// open the popup window when the user clicks a button.
 					editrow = row;
-					$("#popupWindow").jqxWindow({ position: { x: 160, y: 30 } });
+					$("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } });
 					// get the clicked row's data and initialize the input fields.
 					var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
 					$("#name").val(dataRecord.name);
@@ -276,8 +279,8 @@
 	});
 	// initialize the popup window and buttons.
 	$("#popupWindow").jqxWindow({
-		width: 960,
-		height: 550,
+		width: 1050,
+		height: 580,
 		resizable: false,
 		theme: theme,
 		isModal: true,
@@ -288,7 +291,7 @@
 	$("#popupWindow").on('open', function () {
 		$("#name").jqxInput('selectAll');
 	});
-	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
+	$("#Delete").jqxButton({ template: "danger", width: '90px', theme: theme });
 	$("#Delete").click(function () {
 		if (editrow >= 0) {
 			// Open a popup to confirm this action.
@@ -300,32 +303,28 @@
 		}
 		$("#popupWindow").jqxWindow('hide');
 	});
-	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
+	$("#Cancel").jqxButton({ template: "primary", width: '90px', theme: theme });
 	$("#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;
 		if (editrow >= 0) {
-			var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
-			var row = {
-				record: rowID,
-				name: $("#name").val(),
-				notes: $("#notes").val(),
-				steps: steprows
-			};
+			rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
+		}
+		var row = {
+			record: rowID,
+			name: $("#name").val(),
+			notes: $("#notes").val(),
+			steps: steprows
+		};
+		if (editrow >= 0) {
 			$('#jqxgrid').jqxGrid('updaterow', rowID, row);
-			$("#popupWindow").jqxWindow('hide');
 		} else {
-			// Insert a record
-			var newrow = {
-				record: -1,
-				name: $("#name").val(),
-				notes: $("#notes").val(),
-				steps: steprows
-			};
-			$('#jqxgrid').jqxGrid('addrow', null, newrow);
-			$("#popupWindow").jqxWindow('hide');
+			$('#jqxgrid').jqxGrid('addrow', null, row);
 		}
+		$("#popupWindow").jqxWindow('hide');
+		location.reload( true );        // reload ourself.
 	});
 	createDelElements();
 });
--- a/www/profile_mash.php	Sat Jan 26 19:25:10 2019 +0100
+++ b/www/profile_mash.php	Sat Jan 26 22:01:11 2019 +0100
@@ -13,10 +13,11 @@
    <div id="popupWindow">
     <div>Wijzig maisch schema.</div>
     <div style="overflow: hidden;">
-     <table>
+     <table style="width: 100%;">
       <tr>
        <td align="right" style="vertical-align: top;">Schema naam:</td>
-       <td align="left" colspan="3" style="vertical-align: top;"><input id="name" /></td>
+       <td align="left" colspan="2" style="vertical-align: top;"><input id="name" /></td>
+       <td style="width: 25%;"> </td>
       </tr>
       <tr>
        <td align="right" style="vertical-align: top;">Opmerkingen:</td>
@@ -27,12 +28,12 @@
        <td align="left" colspan="3"><div id="grid">Graat</div></td>
       </tr>
       <tr>
-       <td style="padding-top: 10px;" align="right"><input type="button" id="Delete" value="Delete" /></td>
+       <td style="padding-top: 10px;" align="right"><input type="button" id="Delete" value="Verwijder" /></td>
        <td align="right"></td>
        <td align="right"></td>
-       <td style="padding-top: 10px;" align="right">
-        <input style="margin-right: 5px;" type="button" id="Save" value="Save" />
-        <input id="Cancel" type="button" value="Cancel" />
+       <td style="padding-top: 10px;" align="left">
+        <input style="margin-right: 5px;" type="button" id="Save" value="Sla op" />
+        <input id="Cancel" type="button" value="Annuleer" />
        </td>
       </tr>
      </table>

mercurial