www/js/prod_new.js

Thu, 22 Nov 2018 22:27:42 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 22 Nov 2018 22:27:42 +0100
changeset 111
8c4ba91adf58
child 166
635033a29c48
permissions
-rw-r--r--

Basic screens for brew products.

/*****************************************************************************
 * Copyright (C) 2018
 *
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of BMS
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * BrewCloud is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/


$(document).ready(function () {

	// tooltips
	$("#name").jqxTooltip({ content: 'De naam voor dit recept.' });
	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' });

	// editers
	var srcType = [ "All Grain", "Partial Mash", "Extract" ];
	$("#name").jqxInput({ theme: theme, width: 640, height: 23 });
	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });

	//Creating wizard module
	var wizard = (function () {

		//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(),
				};
				var data = "insert=true&return=" + my_return + "&" + $.param(newrow);
				$.ajax({
					dataType: 'json',
					url: "includes/db_product.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);
				}
				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(),
				    message = '';
				if (name.length < 3) {
					message += 'Je moet een recept naam invullen. <br />';
				}
				// Check if name already exists.
				//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;
			},

			//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();
});

mercurial