www/js/prod_edit.js

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 114
4935e86b2775
permissions
-rw-r--r--

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

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

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

	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: 'The unique name of this brew equipment.' });
	$("#eq_notes").jqxTooltip({ content: 'Some notes about the equipment.' });
	$("#eq_tun_volume").jqxTooltip({ content: 'Mash TUN volume.' });
	$("#eq_tun_height").jqxTooltip({ content: 'Mash TUN height in cm.' });
	$("#eq_tun_weight").jqxTooltip({ content: 'Mash TUN weight in Kg.' });
	$("#eq_tun_material").jqxTooltip({ content: 'Mash TUN material. Needed to calculate the right strike temperature.' });
	$("#eq_mash_volume").jqxTooltip({ content: 'Mash water for the first step.' });
	$("#eq_lauter_volume").jqxTooltip({ content: 'Total lauter volume.' });
	$("#eq_lauter_height").jqxTooltip({ content: 'Height of the lauter TUN in cm.' });
	$("#eq_lauter_deadspace").jqxTooltip({ content: 'Volume loss in the lauter TUN.' });
	$("#eq_efficiency").jqxTooltip({ content: 'Average efficiency.' });
	$("#eq_kettle_volume").jqxTooltip({ content: 'Boil kettle volume in liters.' });
	$("#eq_kettle_height").jqxTooltip({ content: 'Boil kettle height in cm.' });
	$("#eq_boil_size").jqxTooltip({ content: 'Normal boil volume in liters' });
	$("#eq_evap_rate").jqxTooltip({ content: 'Evaporation in liters per hour.' });
	$("#eq_boil_time").jqxTooltip({ content: 'Normal boil time in minutes.' });
	$("#eq_top_up_kettle").jqxTooltip({ content: 'Extra water added to the boil.' });
	$("#eq_hop_utilization").jqxTooltip({ content: '100% for smaller installations, higher for large breweries.' });
	$("#eq_batch_size").jqxTooltip({ content: 'Calculated batch size, liters at end of the boil.' });
	$("#eq_trub_chiller_loss").jqxTooltip({ content: 'Standard loss in liters during transfer to the fermenter.' });


	// 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: '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' }
		],
		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);
			$("#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);

			if (dataRecord.stage != "Plan") {
				// Only allow Delete when in Plan stage.
				$("#Delete").jqxButton({ 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 });
	$("#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 });
	$("#eq_batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: 'true', theme: theme, width: 50, height: 23, min: 0, decimalDigits: 1 });
	$("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#eq_tun_weight").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true });
	$("#eq_trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#eq_evap_rate").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 });
	$("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true });
	$("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
	$("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true });
	$("#eq_notes").jqxInput({ theme: theme, width: 640, height: 100 });
	$("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#eq_tun_material").jqxDropDownList({ theme: theme, source: srcMaterial, selectedIndex: 0, width: 110, height: 23, dropDownHeight: 130 });
	$("#eq_tun_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#eq_kettle_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#eq_lauter_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
	$("#eq_mash_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
	$("#eq_efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });

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

	// Buttons sidebar
	$("#rec_edit").jqxButton({ template: "primary", width: '110px', 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;
	});

	createDelElements();
});

mercurial