www/js/prod_new.js

Thu, 03 Jan 2019 14:21:35 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 03 Jan 2019 14:21:35 +0100
changeset 166
635033a29c48
parent 111
8c4ba91adf58
child 167
dabcd35f8f92
permissions
-rw-r--r--

Fixed new recipes uuid generation and saving missing new fields.

/*****************************************************************************
 * 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(),
					code: $("#code").val(),
					birth: $("#birth").val(),
					stage: 'Plan',
					notes: $("#notes").val(),
					log_brew: false,
					log_fermentation: false,
					inventory_reduced: false,
					locked: false,
					eq_name: $("#eq_name").val(),
					eq_boil_size: parseFloat($("#eq_boil_size").jqxNumberInput('decimal')),
					eq_batch_size: parseFloat($("#eq_batch_size").jqxNumberInput('decimal')),
					eq_tun_volume: parseFloat($("#eq_tun_volume").jqxNumberInput('decimal')),
					eq_tun_weight: dataRecord.eq_tun_weight,
					eq_tun_specific_heat: dataRecord.eq_tun_specific_heat,
					eq_tun_material: dataRecord.eq_tun_material,
					eq_tun_height: dataRecord.eq_tun_height,
					eq_top_up_water: parseFloat($("#eq_top_up_water").jqxNumberInput('decimal')),
					eq_trub_chiller_loss: parseFloat($("#eq_trub_chiller_loss").jqxNumberInput('decimal')),
					eq_evap_rate: parseFloat($("#eq_evap_rate").jqxNumberInput('decimal')),
					eq_boil_time: parseFloat($("#eq_boil_time").jqxNumberInput('decimal')),
					eq_calc_boil_volume: dataRecord.eq_calc_boil_volume,
					eq_top_up_kettle: parseFloat($("#eq_top_up_kettle").jqxNumberInput('decimal')),
					eq_hop_utilization: parseFloat($("#eq_hop_utilization").jqxNumberInput('decimal')),
					eq_notes: $("#eq_notes").val(),
					eq_lauter_volume: parseFloat($("#eq_lauter_volume").jqxNumberInput('decimal')),
					eq_lauter_height: dataRecord.eq_lauter_height,
					eq_lauter_deadspace: parseFloat($("#eq_lauter_deadspace").jqxNumberInput('decimal')),
					eq_kettle_volume: parseFloat($("#eq_kettle_volume").jqxNumberInput('decimal')),
					eq_kettle_height: dataRecord.eq_kettle_height,
					eq_mash_volume: parseFloat($("#eq_mash_volume").jqxNumberInput('decimal')),
					eq_mash_max: parseFloat($("#eq_mash_max").jqxNumberInput('decimal')),
					eq_efficiency: parseFloat($("#eq_efficiency").jqxNumberInput('decimal')),
					brew_date_start: '',
					brew_mash_ph: 0.0,
					brew_mash_sg: 1.000,
					brew_sparge_temperature: 85,
					brew_sparge_volume: parseFloat($("#eq_mash_volume").jqxNumberInput('decimal')),
					brew_sparge_ph: 0.0,
					brew_preboil_volume: parseFloat($("#eq_boil_size").jqxNumberInput('decimal')),
					brew_preboil_sg: 1.000,
					brew_preboil_ph: 0.0,
					brew_aboil_volume: parseFloat($("#eq_boil_size").jqxNumberInput('decimal')) * 0.9,
					brew_aboil_sg: 1.000,
					brew_aboil_ph: 0.0,
					brew_aboil_efficiency: 0,
					brew_cooling_method: '-',
					brew_cooling_time: 0,
					brew_cooling_to: 0,
					brew_whirlpool9: 0,
					brew_whirlpool7: 0,
					brew_whirlpool6: 0,
					brew_whirlpool2: 0,
					brew_fermenter_volume: parseFloat($("#eq_batch_size").jqxNumberInput('decimal')),
					brew_fermenter_extrawater: 0,
					brew_aeration_time: 0,
					brew_aeration_speed: 0,
					brew_aeration_type: 'None',
					brew_fermenter_sg: 0,
					brew_fermenter_ibu: 0,
					brew_date_end: '',
					brew_log_available: false,
					og: 0,
					fg: 0,
					primary_start_temp: 0,
					primary_max_temp: 0,
					primary_end_temp: 0,
					primary_end_sg: 0,
					primary_end_date: '',
					secondary_temp: 0,
					secondary_end_date: '',
					tertiary_temp: 0,
					package_date: '',
					bottle_amount: 0,
					bottle_carbonation: 0,
					bottle_priming_sugar: 'Kristalsuiker',
					bottle_priming_amount: 0,
					bottle_carbonation_temp: 23,
					keg_amount: 0,
					keg_carbonation: 0,
					keg_priming_sugar: 'Kristalsuiker',
					keg_priming_amount: 0,
					keg_carbonation_temp: 23,
					keg_forced_carb: false,
					keg_pressure: 0,
					taste_notes: '',
					taste_rate: 0,
					taste_date: '',
					taste_color: '',
					taste_transparency: '',
					taste_head: '',
					taste_aroma: '',
					taste_taste: '',
					taste_mouthfeel: '',
					taste_aftertaste: '',
					st_name: $('#st_name').val(),
					st_letter: $('#st_letter').val(),
					st_guide: $('#st_guide').val(),
					st_type: $('#st_type').val(),
					st_category: $('#st_category').val(),
					st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
					st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')),
					st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')),
					st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')),
					st_fg_max: parseFloat($("#st_fg_max").jqxNumberInput('decimal')),
					st_ibu_min: parseFloat($("#st_ibu_min").jqxNumberInput('decimal')),
					st_ibu_max: parseFloat($("#st_ibu_max").jqxNumberInput('decimal')),
					st_color_min: parseFloat($("#st_color_min").jqxNumberInput('decimal')),
					st_color_max: parseFloat($("#st_color_max").jqxNumberInput('decimal')),
					st_carb_min: parseFloat($("#st_carb_min").jqxNumberInput('decimal')),
					st_carb_max: parseFloat($("#st_carb_max").jqxNumberInput('decimal')),
					st_abv_min: parseFloat($("#st_abv_min").jqxNumberInput('decimal')),
					st_abv_max: parseFloat($("#st_abv_max").jqxNumberInput('decimal')),
					type: $("#type").val(),
					batch_size: 20.0,
					boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),
					efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')),
					est_og: parseFloat($("#est_og").jqxNumberInput('decimal')),
					est_fg: 1.000,
					est_color: 0,
					est_abv: 0.0,
					est_carb: 0.0,
					color_method: "Morey",
					est_ibu: 0,
					ibu_method: "Tinseth",
					mash_name: "",
					mash_ph: 5.4,
					mash_sparge_temp: 78.0
				};
				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