Added some buttons. Only allow product delete if it has no serious data.

Fri, 23 Nov 2018 14:54:07 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 23 Nov 2018 14:54:07 +0100
changeset 112
7ef48396f705
parent 111
8c4ba91adf58
child 113
982c9ae73e12

Added some buttons. Only allow product delete if it has no serious data.

www/includes/db_product.php file | annotate | diff | comparison | revisions
www/js/prod_edit.js file | annotate | diff | comparison | revisions
www/prod_edit.php file | annotate | diff | comparison | revisions
--- a/www/includes/db_product.php	Thu Nov 22 22:27:42 2018 +0100
+++ b/www/includes/db_product.php	Fri Nov 23 14:54:07 2018 +0100
@@ -86,14 +86,15 @@
 
 } else if (isset($_POST['delete'])) {
 	// DELETE COMMAND
-	$sql = "DELETE FROM `brews` WHERE record='".$_POST['record']."';";
-	$result = mysqli_query($connect, $sql);
-	if (! $result) {
-		syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect));
-	} else {
-		syslog(LOG_NOTICE, "db_product: deleted record ".$_POST['record']);
-	}
-	echo $result;
+	$sql = "DELETE FROM `prod_main` WHERE record='".$_POST['record']."';";
+	syslog(LOG_NOTICE, $sql);
+//	$result = mysqli_query($connect, $sql);
+//	if (! $result) {
+//		syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect));
+//	} else {
+//		syslog(LOG_NOTICE, "db_product: deleted record ".$_POST['record']);
+//	}
+//	echo $result;
 
 } else {
 //	syslog(LOG_NOTICE, "db_product: select");
--- a/www/js/prod_edit.js	Thu Nov 22 22:27:42 2018 +0100
+++ b/www/js/prod_edit.js	Fri Nov 23 14:54:07 2018 +0100
@@ -21,6 +21,29 @@
  *****************************************************************************/
 
 
+function createDelElements() {
+
+	$('#eventWindow').jqxWindow({
+		theme: theme,
+		position: { x: 490, y: 210 },
+		width: 300,
+		height: 175,
+		resizable: false,
+		isModal: true,
+		modalOpacity: 0.4,
+		okButton: $('#delOk'),
+		cancelButton: $('#delCancel'),
+		initContent: function () {
+			$('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme });
+			$('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme });
+			$('#delCancel').focus();
+		}
+	});
+	$('#eventWindow').jqxWindow('hide');
+}
+
+
+
 $(document).ready(function () {
 
 	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);
@@ -123,6 +146,10 @@
 			$("#eq_mash_volume").val(dataRecord.eq_mash_volume);
 			$("#eq_efficiency").val(dataRecord.eq_efficiency);
 
+			if (dataRecord.stage != "Plan") {
+				// Only allow Delete when in Plan stage.
+				$("#Delete").jqxButton({ disabled: true });
+			}
 		},
 		loadError: function (jqXHR, status, error) {
 		},
@@ -143,7 +170,7 @@
 	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
 	$("#code").jqxInput({ theme: theme, width: 100, height: 23 });
 	$("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' });
-	$("#stage").jqxInput({ theme: theme, width: 100, height: 23, disabled: true });
+	$("#stage").jqxInput({ theme: theme, width: 100, height: 23 });
 	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
 	$("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 });
 	$("#eq_boil_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
@@ -174,155 +201,37 @@
 		position: 'top'
 	});
 
-
-
-/*
-	//Creating wizard module
-	var wizard = (function () {
+	// Buttons sidebar
+	$("#rec_edit").jqxButton({ template: "primary", width: '110px', theme: theme });
 
-		//Adding event listeners
-		var _addHandlers = function () {
-			$('#name').on('change', function (event) { wizard.validate(true); });
-			$('#nextButtonCompleted').click(function () {
-				console.log("insert start");
-				var newrow = {
-					record: -1,
-					name: $("#name").val(),
-					notes: $("#notes").val(),
-					st_name: $('#st_name').val(),
-					st_letter: $('#st_style_letter').val(),
-					mash_ph: 5.4,
-					mash_sparge_temp: 78.0
-				};
-				var data = "insert=true&return=" + my_return + "&" + $.param(newrow);
-				$.ajax({
-					dataType: 'json',
-					url: "includes/db_recipes.php",
-					cache: false,
-					data: data,
-					type: "POST",
-					success: function (data, status, xhr) {
-						// update command is executed.
-						window.location.href = my_return;
-					},
-					error: function(jqXHR, textStatus, errorThrown) {
-					}
-				});
-			});
-			$('.nextButton').click(function () {
-				wizard.validate(true);
-				$('#jqxTabs').jqxTabs('next');
-			});
-			$('.backButton').click(function () {
-				wizard.validate(true);
-				$('#jqxTabs').jqxTabs('previous');
-			});
-		};
-
-		return {
-			//Initializing the wizzard - creating all elements, adding event handlers and starting the validation
-			init: function () {
-				$('#jqxTabs').jqxTabs({
-					theme: theme,
-					height: 630,
-					width: 1280,
-					autoHeight: false,
-					position: 'top',
-					keyboardNavigation: false
-				});
-				$('#nextButtonBase').jqxButton({ theme: theme, width: 150 });
-				$('#nextButtonStyle').jqxButton({ theme: theme, width: 150});
-				$('#backButtonStyle').jqxButton({ theme: theme, width: 150});
-				$('#nextButtonCompleted').jqxButton({ theme: theme, width: 150});
-				$('#backButtonCompleted').jqxButton({ theme: theme, width: 150});
-				_addHandlers();
-				this.validate();
-				this.showHint('Validation hints.');
-			},
-
-			//Validating all wizard tabs
-			validate: function (notify) {
-				if (!this.firstTab(notify)) {
-					$('#jqxTabs').jqxTabs('disableAt', 1);
-					$('#jqxTabs').jqxTabs('disableAt', 2);
-					return;
-				} else {
-					$('#jqxTabs').jqxTabs('enableAt', 1);
+	// Buttons below
+	$("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
+	$("#Delete").click(function () {
+		// Open a popup to confirm this action.
+		$('#eventWindow').jqxWindow('open');
+		$("#delOk").click(function () {
+			var data = "delete=true&" + $.param({ record: my_record });
+			$.ajax({
+				dataType: 'json',
+				url: url,
+				cache: false,
+				data: data,
+				type: "POST",
+				success: function (data, status, xhr) {
+					// delete command is executed.
+					window.location.href = my_return;
+				},
+				error: function (jqXHR, textStatus, errorThrown) {
 				}
-				if (!this.secondTab(notify)) {
-					$('#jqxTabs').jqxTabs('disableAt', 2);
-					return;
-				} else {
-					$('#jqxTabs').jqxTabs('enableAt', 2);
-				}
-			},
-
-			//Displaying message to the user
-			showHint: function (message, selector) {
-				if (typeof selector === 'undefined') {
-					selector = '.hint';
-				}
-				if (message === '') {
-					message = 'Ok, je mag doorgaan.';
-				}
-				$(selector).html('<strong>' + message + '</strong>');
-			},
+			});
+		});
+	});
 
-			//Validating the first tab
-			firstTab: function (notify) {
-				var name = $('#name').val(),
-				    type = $('#type').val(),
-				    boil_time = parseFloat($("#boil_time").jqxNumberInput('decimal')),
-				    est_og = parseFloat($("#est_og").jqxNumberInput('decimal')),
-				    efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal')),
-				    message = '';
-				if (name.length < 3) {
-					message += 'Je moet een recept naam invullen. <br />';
-				}
-				// Check if name already exists.
-				if (type.length < 1) {
-					message += 'Je moet een brouw type kiezen. <br />';
-				}
-				if ((boil_time < 4) || (boil_time > 360)) {
-					message += 'De kooktijd moet tussen 4 en 360 minuten zijn. <br />';
-				}
-				if ((est_og < 1.010) || (est_og > 1.200)) {
-					message += 'Het OG moet tussen 1.010 en 1.500 zijn. <br />';
-				}
-				if ((efficiency < 35) || (efficiency > 95)) {
-					message += 'Het brouwzaal rendement moet tussen 35 en 95 zijn. <br />';
-				}
-				if (message !== '') {
-					if (notify) {
-						this.showHint(message, '#hintBase');
-					}
-					return false;
-				}
-				this.showHint('Ok, je mag doorgaan.', '#hintBase');
-				return true;
-			},
+	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
+	$("#Cancel").click(function () {
+		window.location.href = my_return;
+	});
 
-			//Validating the second tab
-			secondTab: function (notify) {
-				var stylesel = $('#styleSelect').val(),
-				    message = '';
-				if (stylesel.length < 3) {
-					message += 'Je moet een bierstijl kiezen. <br />';
-				}
-				if (message !== '') {
-					if (notify) {
-						this.showHint(message, '#hintStyle');
-					}
-					return false;
-				}
-				this.showHint('Ok, je mag doorgaan.', '#hintStyle');
-				return true;
-			}
-		}
-	} ());
-*/
-	//Initializing the wizard
-//	wizard.init();
-
+	createDelElements();
 });
 
--- a/www/prod_edit.php	Thu Nov 22 22:27:42 2018 +0100
+++ b/www/prod_edit.php	Fri Nov 23 14:54:07 2018 +0100
@@ -10,7 +10,7 @@
      <li>Brouwdag</li>
     </ul>
 
-    <div class="section">
+    <div>
      <div style="overflow: hidden;">
       <table style="width: 100%;">
        <tr>
@@ -26,7 +26,7 @@
            <td style="vertical-align: top; float: right; padding: 3px;">Start planning:</td>
            <td align="left" style="vertical-align: top;"><div id="birth"></div></td>
            <td style="vertical-align: top; float: right; padding: 3px;">Brouw fase:</td>
-           <td align="left" style="vertical-align: top; padding: 3px;"><input id="stage" /></td>
+           <td align="left" style="vertical-align: top; padding: 3px;"><input id="stage" readonly /></td>
           <tr>
            <td style="vertical-align: top; float: right; padding: 3px;">Opmerkingen:</td>
            <td colspan="5" style="padding: 3px;"><textarea id="notes"></textarea></td>
@@ -35,19 +35,24 @@
         </td>
         <td style="vertical-align: top;">
          <table>
-	  <tr><td><input style="margin-right: 10px;" type="button" id="Klop1"  value="Knop 1" /></td></tr>
+	  <tr><td><input style="margin-right: 10px;" type="button" id="rec_edit" value="Recept" /></td></tr>
           <tr><td><input style="margin-right: 10px;" type="button" id="Knop2"  value="Knop 2" /></td></tr>
           <tr><td><input style="margin-right: 10px;" type="button" id="Knop3"  value="Knop 3" /></td></tr>
          </table>
         </td>
        </tr>
       </table>
+      <div style="float: right; margin-top: 30px; margin-bottom: 10px;">
+       <input style="margin-right: 100px;" type="button" id="Delete" value="Delete" />
+       <input style="margin-right: 100px;" type="button" id="Save"   value="Save" />
+       <input style="margin-right: 410px;" type="button" id="Cancel" value="Cancel" />
+      </div>
      </div>
      <div id="hintBase" class="hint">
      </div>
     </div>
 
-    <div class="section"> <!-- Tab 2 -->
+    <div> <!-- Tab 2 -->
      <div style="overflow: hidden;">
       <table>
        <tr>
@@ -130,7 +135,7 @@
      </div>
     </div>
 
-    <div class="section"> <!-- Tab 3 -->
+    <div> <!-- Tab 3 -->
      <div style="overflow: hidden; margin: 25px;"><br>
       <p>Alle nodige gegevens zijn compleet.</p>
       <p> Zodra je de "Volgende" toets gebruikt zal een nieuw recept aangemaakt worden en<br>
@@ -144,5 +149,6 @@
    </div>
 
 <?php
+confirm_delete();
 page_footer();
 ?>

mercurial