www/js/prod_edit.js

Wed, 28 Nov 2018 21:57:06 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 28 Nov 2018 21:57:06 +0100
changeset 114
4935e86b2775
parent 112
7ef48396f705
child 115
ad31f4bd4036
permissions
-rw-r--r--

Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.

/*****************************************************************************
 * 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.
 *****************************************************************************/


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 () {

	var	brewstage = 0;	// Numeric value of stage

	console.log("record:" + my_record + "  return:" + my_return + "  theme:" + theme);

	// Equipemnt dropdown list
	var equipmentUrl = "includes/db_inventory_equipments.php";
	var equipmentSource = {
		datatype: "json",
		datafields: [
			{ name: 'name', type: 'string' },
			{ name: 'boil_size', type: 'float' },
			{ name: 'batch_size', type: 'float' },
			{ name: 'tun_volume', type: 'float' },
			{ name: 'tun_weight', type: 'float' },
			{ name: 'trub_chiller_loss', type: 'float' },
			{ name: 'evap_rate', type: 'float' },
			{ name: 'boil_time', type: 'float' },
			{ name: 'lauter_deadspace', type: 'float' },
			{ name: 'top_up_kettle', type: 'float' },
			{ name: 'hop_utilization', type: 'float' },
			{ name: 'notes', type: 'string' },
			{ name: 'lauter_volume', type: 'float' },
			{ name: 'kettle_volume', type: 'float' },
			{ name: 'tun_material', type: 'string' },
			{ name: 'tun_height', type: 'float' },
			{ name: 'kettle_height', type: 'float' },
			{ name: 'lauter_height', type: 'float' },
			{ name: 'mash_volume', type: 'float' },
			{ name: 'efficiency', type: 'float' }
		],
		url: equipmentUrl,
		async: true
	};
	var equipmentlist = new $.jqx.dataAdapter(equipmentSource);
	$("#equipmentSelect").jqxDropDownList({
		placeHolder: "Kies apparatuur:",
		theme: theme,
		source: equipmentlist,
		displayMember: "name",
		width: 150,
		height: 27,
		dropDownWidth: 300,
		renderer: function (index, label, value) {
			var datarecord = equipmentlist.records[index];
			return datarecord.batch_size + " liter " + datarecord.name;
		}
	});
	$("#equipmentSelect").on('select', function (event) {
		if (event.args) {
			var index = event.args.index;
			var datarecord = equipmentlist.records[index];
			$("#eq_name").val(datarecord.name);
			$("#eq_boil_size").val(datarecord.boil_size);
			$("#eq_batch_size").val(datarecord.batch_size);
			$("#eq_tun_volume").val(datarecord.tun_volume);
			$("#eq_tun_weight").val(datarecord.tun_weight);
			$("#eq_trub_chiller_loss").val(datarecord.trub_chiller_loss);
			$("#eq_evap_rate").val(datarecord.evap_rate);
			$("#eq_boil_time").val(datarecord.boil_time);
			$("#eq_lauter_deadspace").val(datarecord.lauter_deadspace);
			$("#eq_top_up_kettle").val(datarecord.top_up_kettle);
			$("#eq_hop_utilization").val(datarecord.hop_utilization);
			$("#eq_notes").val(datarecord.notes);
			$("#eq_lauter_volume").val(datarecord.lauter_volume);
			$("#eq_kettle_volume").val(datarecord.kettle_volume);
			$("#eq_tun_material").val(datarecord.tun_material);
			$("#eq_tun_height").val(datarecord.tun_height);
			$("#eq_kettle_height").val(datarecord.kettle_height);
			$("#eq_lauter_height").val(datarecord.lauter_height);
			$("#eq_mash_volume").val(datarecord.mash_volume);
			$("#eq_efficiency").val(datarecord.efficiency);
		}
	});

	var dataReecord = {};
	var url = "includes/db_product.php";
	// tooltips
	$("#name").jqxTooltip({ content: 'De naam voor dit product.' });
	$("#code").jqxTooltip({ content: 'Product code nummer.' });
	$("#birth").jqxTooltip({ content: 'De ontwerp datum van dit product.' });
	$("#stage").jqxTooltip({ content: 'De productie fase van dit product.' });
	$("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit product.' });
	$("#eq_name").jqxTooltip({ content: 'De naam van deze brouw apparatuur.' });
	$("#eq_notes").jqxTooltip({ content: 'Opmerkingen over deze apparatuur.' });
	$("#eq_tun_volume").jqxTooltip({ content: 'Maisch ketel volume.' });
	$("#eq_tun_height").jqxTooltip({ content: 'Maisch ketel hoogte in cm.' });
	$("#eq_tun_weight").jqxTooltip({ content: 'Maisch ketel gewicht in Kg.' });
	$("#eq_tun_material").jqxTooltip({ content: 'Maisch ketel materiaal. Nodig om de juiste inmaisch temperatuur te berekenen.' });
	$("#eq_mash_volume").jqxTooltip({ content: 'Maisch water voor de eerste stap.' });
	$("#eq_lauter_volume").jqxTooltip({ content: 'Filterkuip volume.' });
	$("#eq_lauter_height").jqxTooltip({ content: 'Hoogte van de filterkuip in cm.' });
	$("#eq_lauter_deadspace").jqxTooltip({ content: 'Filterkuip verlies in liters.' });
	$("#eq_efficiency").jqxTooltip({ content: 'Gemiddeld brouwzaal rendement.' });
	$("#eq_kettle_volume").jqxTooltip({ content: 'Kook ketel volume in liters.' });
	$("#eq_kettle_height").jqxTooltip({ content: 'Kook ketel hoogte in cm.' });
	$("#eq_boil_size").jqxTooltip({ content: 'Normaal kook volume in liters' });
	$("#eq_evap_rate").jqxTooltip({ content: 'Verdamping in liters per uur.' });
	$("#eq_boil_time").jqxTooltip({ content: 'Normale kooktijd in minuten..' });
	$("#eq_top_up_kettle").jqxTooltip({ content: 'Extra water toevoegen tijdens de kook.' });
	$("#eq_hop_utilization").jqxTooltip({ content: '100% voor kleine installaties, hoger voor grote brouwerijen.' });
	$("#eq_batch_size").jqxTooltip({ content: 'Berekende batch grootte in liters aan het eind van de kook.' });
	$("#eq_trub_chiller_loss").jqxTooltip({ content: 'Standaard verlies bij het overbrengen naar het gistvat.' });

	// Prepare the data
	var source = {
		datatype: "json",
		cache: false,
		datafields: [
			{ name: 'record', type: 'number' },
			{ name: 'uuid', type: 'string' },
			{ name: 'name', type: 'string' },
			{ name: 'code', type: 'string' },
			{ name: 'birth', type: 'string' },
			{ name: 'stage', type: 'string' },
			{ name: 'notes', type: 'string' },
			{ name: 'log_brew', type: 'bool' },
			{ name: 'log_fermentation', type: 'bool' },
			{ name: 'inventory_reduced', type: 'bool' },
			{ name: 'locked', type: 'bool' },
			{ name: 'eq_name', type: 'string' },
			{ name: 'eq_boil_size', type: 'float' },
			{ name: 'eq_batch_size', type: 'float' },
			{ name: 'eq_tun_volume', type: 'float' },
			{ name: 'eq_tun_weight', type: 'float' },
			{ name: 'eq_trub_chiller_loss', type: 'float' },
			{ name: 'eq_evap_rate', type: 'float' },
			{ name: 'eq_boil_time', type: 'float' },
			{ name: 'eq_lauter_deadspace', type: 'float' },
			{ name: 'eq_top_up_kettle', type: 'float' },
			{ name: 'eq_hop_utilization', type: 'float' },
			{ name: 'eq_notes', type: 'string' },
			{ name: 'eq_lauter_volume', type: 'float' },
			{ name: 'eq_kettle_volume', type: 'float' },
			{ name: 'eq_tun_material', type: 'string' },
			{ name: 'eq_tun_height', type: 'float' },
			{ name: 'eq_kettle_height', type: 'float' },
			{ name: 'eq_lauter_height', type: 'float' },
			{ name: 'eq_mash_volume', type: 'float' },
			{ name: 'eq_efficiency', type: 'float' },
			{ name: 'brew_date_start', type: 'string' },
			{ name: 'brew_mash_ph', type: 'float' },
			{ name: 'brew_mash_sg', type: 'float' },

			{ name: 'brew_date_end', type: 'string' }
		],
		id: 'record',
		url: url
	};
	// Load data and select one record.
	var dataAdapter = new $.jqx.dataAdapter(source, {
		loadComplete: function () {
			var records = dataAdapter.records;
			dataRecord = records[0];
			// Hidden record uuid
			$("#name").val(dataRecord.name);
			$("#code").val(dataRecord.code);
			$("#birth").val(dataRecord.birth);
			$("#stage").val(dataRecord.stage);
			$("#notes").val(dataRecord.notes);
			$("#log_brew").val(dataRecord.log_brew);
			$("#log_fermentation").val(dataRecord.log_fermentation);
			$("#inventory_reduced").val(dataRecord.inventory_reduced);
			$("#locked").val(dataRecord.locked);
			$("#eq_name").val(dataRecord.eq_name);
			$("#eq_boil_size").val(dataRecord.eq_boil_size);
			$("#eq_batch_size").val(dataRecord.eq_batch_size);
			$("#eq_tun_volume").val(dataRecord.eq_tun_volume);
			$("#eq_tun_weight").val(dataRecord.eq_tun_weight);
			$("#eq_trub_chiller_loss").val(dataRecord.eq_trub_chiller_loss);
			$("#eq_evap_rate").val(dataRecord.eq_evap_rate);
			$("#eq_boil_time").val(dataRecord.eq_boil_time);
			$("#eq_lauter_deadspace").val(dataRecord.eq_lauter_deadspace);
			$("#eq_top_up_kettle").val(dataRecord.eq_top_up_kettle);
			$("#eq_hop_utilization").val(dataRecord.eq_hop_utilization);
			$("#eq_notes").val(dataRecord.eq_notes);
			$("#eq_lauter_volume").val(dataRecord.eq_lauter_volume);
			$("#eq_kettle_volume").val(dataRecord.eq_kettle_volume);
			$("#eq_tun_material").val(dataRecord.eq_tun_material);
			$("#eq_tun_height").val(dataRecord.eq_tun_height);
			$("#eq_kettle_height").val(dataRecord.eq_kettle_height);
			$("#eq_lauter_height").val(dataRecord.eq_lauter_height);
			$("#eq_mash_volume").val(dataRecord.eq_mash_volume);
			$("#eq_efficiency").val(dataRecord.eq_efficiency);
			$("#brew_date_start").val(dataRecord.brew_date_start);
			$("#brew_mash_ph").val(dataRecord.brew_mash_ph);
			$("#brew_mash_sg").val(dataRecord.brew_mash_sg);

			$("#brew_date_end").val(dataRecord.brew_date_end);

			switch (dataRecord.stage) {
				case 'Plan':		brewstage = 0;	break;
				case 'Wait':		brewstage = 1;	break;
				case 'Brew':		brewstage = 2;	break;
				case 'Primary':		brewstage = 3;	break;
				case 'Secondary':	brewstage = 4;	break;
				case 'Tertiary':	brewstage = 5;	break;
				case 'Package':		brewstage = 6;	break;
				case 'Carbonation':	brewstage = 7;	break;
				case 'Mature':		brewstage = 8;	break;
				case 'Taste':		brewstage = 9;	break;
				case 'Ready':		brewstage = 10;
							$("#locked").jqxCheckBox({ disabled:false });
							break;
				case 'Closed':		brewstage = 11;
							$("#locked").jqxCheckBox({ disabled:false });
							break;
			}
			// Enable or Disable settings depending on the stage.
			if (brewstage > 1)
				$("#equipmentSelect").jqxDropDownList({ disabled: true });
			if (brewstage > 0) {
				$("#Delete").jqxButton({ disabled: true });
				$("#birth").jqxDateTimeInput({ disabled: true });
			}
			if (brewstage < 3) {
				$("#brew_log").jqxButton({ disabled: true });
				$("#ferment_log").jqxButton({ disabled: true });
			} else {
				if (! dataRecord.log_brew)
					$("#brew_log").jqxButton({ disabled: true });
				if (! dataRecord.log_fermentation)
					$("#ferment_log").jqxButton({ disabled: true });
			}
			if (brewstage < 6)
				$("#inventory_reduced").jqxCheckBox({ disabled : true });
			else if ($('#inventory_reduced').jqxCheckBox('checked'))
				$("#inventory_reduced").jqxCheckBox({ disabled : true });
		},
		loadError: function (jqXHR, status, error) {
		},
		beforeLoadComplete: function (records) {
			var filteredRecords = [];
			for (var i = 0; i < records.length; i++) {
				if (records[i].record == my_record) {
				filteredRecords.push(records[i]);
				}
			}
			return filteredRecords;
		}
	});
	dataAdapter.dataBind();

	// initialize the input fields.
	var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ];
	$("#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 });
	$("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
	$("#log_brew").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#log_fermentation").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$("#inventory_reduced").jqxCheckBox({ theme: theme, width: 120, height: 23 });
	$('#inventory_reduced').on('checked', function (event) {
		// Call a script to do the work and block this.
		// Note that this script must set this flag too, so of the user doesn't Save it is still set.
		// Call the script with the uuid.
		$("#inventory_reduced").jqxCheckBox({ disabled : true });
	});
	$("#locked").jqxCheckBox({ theme: theme, width: 120, height: 23, disabled : true });
	$('#locked').on('checked', function (event) {
		$("#stage").val('Closed');
		brewstage = 11;
	});
	$('#locked').on('unchecked', function (event) {
		$("#stage").val('Ready');
		brewstage = 10;
	});
	$("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 });
	$("#eq_boil_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_weight").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 2 });
	$("#eq_trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_evap_rate").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 2,  });
	$("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 0 });
	$("#eq_notes").jqxInput({ theme: theme, width: 640, height: 100 });
	$("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_tun_material").jqxInput({ theme: theme, width: 100, height: 23 });
	$("#eq_tun_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_kettle_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_lauter_height").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_mash_volume").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });
	$("#eq_efficiency").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 1 });

	$("#brew_date_start").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });
	$("#brew_mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#brew_mash_sg").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 90, height: 23, min: 0, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });

	$("#brew_date_end").jqxDateTimeInput({ theme: theme, width: 230, height: 23, formatString: 'yyyy-MM-dd HH:mm:ss', showTimeButton: true });

	$('#jqxTabs').jqxTabs({
		theme: theme,
		width: 1280,
		height: 630,
		autoHeight: false,
		position: 'top'
	});

	// Buttons sidebar
	$("#rec_edit").jqxButton({ template: "primary", width: '140px', theme: theme });
	$("#brew_log").jqxButton({ template: "primary", width: '140px', theme: theme });
	$("#ferment_log").jqxButton({ template: "primary", width: '140px', theme: theme });

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

	$("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
	$("#Cancel").click(function () {
		window.location.href = my_return;
	});

	$("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
	$("#Save").click(function () {
		var row = {
			record: my_record,
			uuid: $("#uuid").val(),
			name: $("#name").val(),
			code: $("#code").val(),
			birth: $("#birth").val(),
			stage: $("#stage").val(),
			notes: $("#notes").val(),
			log_brew: $("#log_brew").val(),
			log_fermentation: $("#log_fermentation").val(),
			inventory_reduced: $("#inventory_reduced").val(),
			locked: $("#locked").val(),
			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: parseFloat($("#eq_tun_weight").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_lauter_deadspace: parseFloat($("#eq_lauter_deadspace").jqxNumberInput('decimal')),
			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_kettle_volume: parseFloat($("#eq_kettle_volume").jqxNumberInput('decimal')),
			eq_tun_material: $("#eq_tun_material").val(),
			eq_tun_height: parseFloat($("#eq_tun_height").jqxNumberInput('decimal')),
			eq_kettle_height: parseFloat($("#eq_kettle_height").jqxNumberInput('decimal')),
			eq_lauter_height: parseFloat($("#eq_lauter_height").jqxNumberInput('decimal')),
			eq_mash_volume: parseFloat($("#eq_mash_volume").jqxNumberInput('decimal')),
			eq_efficiency: parseFloat($("#eq_efficiency").jqxNumberInput('decimal'))
		};
		var data = "update=true&" + $.param(row);
		$.ajax({
			dataType: 'json',
			url: url,
			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) {
			}
		});
	});	
	createDelElements();
});

mercurial