www/js/mon_fermenter.js

Sun, 02 Jun 2019 12:48:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 02 Jun 2019 12:48:54 +0200
changeset 392
544d7d0183b2
parent 390
1c52a6875960
child 455
f319a8ab931a
permissions
-rw-r--r--

Added 15 fields to the recipes table. Added 18 fields to the products table. These are calculated values that are now stored in the database so export programs can use these values without calculating them again. Product and recipe print have water and mash schedule added. Product print has brewday results added if the brewday is over. The ingredients layout changed in the product and recipe prints.

/*****************************************************************************
 * Copyright (C) 2019
 *
 * 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.
 *
 * Brewery Management System istributed 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 createAbortElements() {
	$('#eventWindow').jqxWindow({
		theme: theme,
		position: { x: 440, y: 210 },
		width: 400,
		height: 200,
		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	record = {};
	var	blank = {};
	var	ppayload = '';
	var	newBase = false;
	var	newProduct = false;
	var	newSwitch = false;
	var	newProfile = false;
	var	schedule = 0;
	var	yl = 12;	// Normal yeast temp range
	var	yh = 24;

	var productSource = {
		datatype: "json",
		cache: false,
		datafields: [
			{ name: 'code', type: 'string' },
			{ name: 'name', type: 'string' },
			{ name: 'uuid', type: 'string' },
			{ name: 'stage', type: 'int' },
			{ name: 'yeast_lo', type: 'float' },
			{ name: 'yeast_hi', type: 'float' }
		],
		id: 'code',
		url: "includes/db_product.php?select=ferment"
	};
	var productlist = new $.jqx.dataAdapter(productSource, {
		beforeLoadComplete: function (records) {
			var data = new Array();
			// Create a dummy beer on top to store in idle fermenters.
			blank['code'] = "Free";	 // Will override this later.
			blank['name'] = 'Dummy';
			blank['uuid'] = '66ecccbf-e942-4a35-af49-8b02314561a5';
			blank['stage'] = 10;
			blank['yeast_lo'] = 12.0;
			blank['yeast_hi'] = 24.0;
			data.push(blank);
			for (var i = 0; i < records.length; i++) {
				var row = records[i];
				data.push(row);
			}
			return data;
		},
        	loadError: function(jqXHR, status, error) {
                	$('#err').text(status + ' ' + error);
		},
	});
	$("#select_beer").jqxDropDownList({
		placeHolder: "Kies bier:",
		theme: theme,
		source: productlist,
		displayMember: "code",
		width: 150,
		height: 24,
		dropDownWidth: 500,
		autoDropDownHeight: true,
		renderer: function (index, label, value) {
			var datarecord = productlist.records[index];
			return datarecord.code + " - " + datarecord.name;
		}
	});

	var profileSource = {
		datatype: "json",
		cache: false,
		datafields: [
			{ name: 'record', type: 'int' },
			{ name: 'uuid', type: 'string' },
			{ name: 'name', type: 'string' },
			{ name: 'inittemp_lo', type: 'float' },
			{ name: 'inittemp_hi', type: 'float' },
			{ name: 'fridgemode', type: 'int' },
			{ name: 'totalsteps', type: 'int' },
			{ name: 'duration', type: 'int' },
			{ name: 'steps', type: 'array' }
		],
		id: 'record',
		url: "includes/db_profile_fermentation.php"
	};
	var profilelist = new $.jqx.dataAdapter(profileSource, {
		beforeLoadComplete: function (records) {
			var data = new Array();
			var empty = {};
			// Create a dummy profile on top of the list.
			empty['record'] = -1;
			empty['uuid'] = '';
			empty['name'] = 'Wis profiel';
			empty['inittemp_lo'] = 20;
			empty['inittemp_hi'] = 20;
			empty['fridgemode'] = 0;
			empty['totalsteps'] = 0;
			empty['duration'] = 0;
			empty['steps'] = '[]';
			data.push(empty);
			for (var i = 0; i < records.length; i++) {
				var row = records[i];
				data.push(row);
			}
			return data;
		},
		loadError: function(jqXHR, status, error) {
			$('#err').text(status + ' ' + error);
		},
	});
	$("#select_profile").jqxDropDownList({
		placeHolder: "Kies profiel:",
		theme: theme,
		source: profilelist,
		displayMember: "name",
		width: 150,
		height: 24,
		dropDownWidth: 500,
		autoDropDownHeight: true,
	});

	var gaugeoptions = {
		min: 0, max: 40, width: 375, height: 375,
		ranges: [{ startValue:  0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
			 { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
			 { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }],
		ticksMinor: { interval: 1, size: '5%' },
		ticksMajor: { interval: 5, size: '9%' },
		labels: { interval: 5 },
		style: { fill: '#eeeeee', stroke: '#666666' },
		value: 0,
		colorScheme: 'scheme05'
	};
	var gaugeSmalloptions = {
		min: -15, max: 25, width: 190, height: 190,
		ranges: [{ startValue: -15, endValue:  0, startWidth: 5, endWidth: 5, style: { fill: '#3399FF', stroke: '#3399FF' }},
		         { startValue:   0, endValue: 10, startWidth: 5, endWidth: 5, style: { fill: '#00CC33', stroke: '#00CC33' }},
			 { startValue:  10, endValue: 25, startWidth: 5, endWidth: 5, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }}],
		ticksMinor: { interval: 1, size: '5%' },
		ticksMajor: { interval: 5, size: '9%' },
		labels: { interval: 5 },
		style: { fill: '#eeeeee', stroke: '#666666' },
		value: 0,
		colorScheme: 'scheme05',
		caption: { value: 'Chiller', position: 'bottom', offset: [0, 10] }
	};
	$("#gaugeContainer_air").jqxGauge( gaugeoptions );
	$("#gaugeContainer_air").jqxGauge( { caption: { value: 'Air: 00.000' }} );
	$("#gaugeContainer_beer").jqxGauge( gaugeoptions );
	$("#gaugeContainer_beer").jqxGauge( { caption: { value: 'Beer: 00.000' }} );
	$("#gaugeContainer_chiller").jqxGauge( gaugeSmalloptions );

	var switchoptions = {
		height: 68,
		width: 35,
		onLabel:'AAN',
		offLabel:'UIT',
		theme: theme,
		thumbSize:'50%',
		orientation: 'vertical'
	};
	$("#fermenter_toggle1").jqxSwitchButton( switchoptions );
	$("#fermenter_toggle2").jqxSwitchButton( switchoptions );
	$("#fermenter_toggle3").jqxSwitchButton( switchoptions );

	srcMode = [ "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" ];
	srcStage = [ "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" ];
	$("#info_mode").jqxDropDownList({  theme: theme, source: srcMode, width: 100, height: 24, dropDownHeight: 156 });
	$("#info_stage").jqxDropDownList({ theme: theme, source: srcStage, width: 150, height: 24, dropDownHeight: 125 });

	var targetoptions = { inputMode: 'simple', theme: theme, width: 70, min: 0, max: 40, decimalDigits: 1, spinButtons: true };
	$("#target_lo").jqxNumberInput( targetoptions );
	$("#target_hi").jqxNumberInput( targetoptions );

	$("#Profile1").jqxButton({ template: "info", width: '150px', height: 24, theme: theme });
	$("#Profile2").jqxButton({ template: "info", width: '150px', height: 24, theme: theme });
	$("#Profile1").hide();	// Hide these until they are needed.
	$("#Profile2").hide();

	function sendBase(stage, mode, tlo, thi) {

		console.log("sendBase("+stage+", "+mode+", "+tlo+", "+thi+")");
		var data  = 'node='+record.node+'&alias='+record.alias+'&payload={"stage":"'+stage;
		    data += '","mode":"'+mode+'","setpoint":{"low":'+tlo+',"high":'+thi+'}}';
		$.ajax({
			url: "cmd_fermenter.php",
			data: data,
			type: "POST",
			success: function(data) {},
			error: function(jqXHR, textStatus, errorThrown) { console.log("sendBase() error"); }
		});
	}

	function sendSwitch(sw1, sw2, sw3, sw4) {

		console.log("sendSwitch("+sw1+", "+sw2+", "+sw3+", "+sw4+")");
		var data  = 'node='+record.node+'&alias='+record.alias+'&payload=';
		    data += '{"heater":{"state":'+sw1+'},"cooler":{"state":'+sw2+'},"fan":{"state":'+sw3+'},"light":{"state":'+sw4+'}}';
		$.ajax({
			url: "cmd_fermenter.php",
			data: data,
			type: "POST",
			success: function(data) {},
			error: function(jqXHR, textStatus, errorThrown) { console.log("sendSwitch() error"); }
		});
	}

	function sendProduct(code, name, uuid, yeast_lo, yeast_hi) {

		console.log("sendProduct("+code+", "+name+", "+uuid+", "+yeast_lo+", "+yeast_hi+")");
		var data  = 'node='+record.node+'&alias='+record.alias+'&payload=';
		    data += '{"product":{"code":"'+code+'","name":"'+name+'","uuid":"'+uuid+'","yeast_lo":'+yeast_lo+',"yeast_hi":'+yeast_hi+'}}';
		$.ajax({
			url: "cmd_fermenter.php",
			data: data,
			type: "POST",
			success: function(data) {},
			error: function(jqXHR, textStatus, errorThrown) { console.log("sendProduct() error"); }
		});
	}

	function sendProfile(payload) {

		console.log("sendProfile("+payload+")");
		var data  = 'node='+record.node+'&alias='+record.alias+'&payload='+payload;
		$.ajax({
			url: "cmd_fermenter.php",
			data: data,
			type: "POST",
			success: function(data) {},
			error: function(jqXHR, textStatus, errorThrown) { console.log("sendProfile() error"); }
		});
	}

    	var url = "getfermenter.php?uuid='" + my_uuid + "'";
    	var source = {
		datatype: "json",
		datafields: [
			{ name: 'record', type: 'int' },
			{ name: 'uuid', type: 'string' },
			{ name: 'alias', type: 'string' },
			{ name: 'node', type: 'string' },
			{ name: 'online', type: 'int' },
			{ name: 'beercode', type: 'string' },
			{ name: 'beername', type: 'string' },
			{ name: 'air_state', type: 'string' },
			{ name: 'air_temperature', type: 'float' },
			{ name: 'beer_state', type: 'string' },
			{ name: 'beer_temperature', type: 'float' },
			{ name: 'chiller_state', type: 'string' },
			{ name: 'chiller_temperature', type: 'float' },
			{ name: 'heater_state', type: 'int' },
			{ name: 'heater_usage', type: 'int' },
			{ name: 'cooler_state', type: 'int' },
			{ name: 'cooler_usage', type: 'int' },
			{ name: 'fan_state', type: 'int' },
			{ name: 'fan_usage', type: 'int' },
			{ name: 'light_address', type: 'string' },
			{ name: 'light_state', type: 'int' },
			{ name: 'light_usage', type: 'int' },
			{ name: 'door_address', type: 'string' },
			{ name: 'door_state', type: 'int' },
			{ name: 'psu_address', type: 'string' },
			{ name: 'psu_state', type: 'int' },
			{ name: 'mode', type: 'string' },
			{ name: 'alarm', type: 'int' },
			{ name: 'setpoint_high', type: 'float' },
			{ name: 'setpoint_low', type: 'float' },
			{ name: 'profile_uuid', type: 'string' },
			{ name: 'profile_name', type: 'string' },
			{ name: 'profile_state', type: 'string' },
			{ name: 'profile_percent', type: 'int' },
			{ name: 'profile_inittemp_high', type: 'float' },
			{ name: 'profile_inittemp_low', type: 'float' },
			{ name: 'profile_steps', type: 'string' },
			{ name: 'stage', type: 'string' },
			{ name: 'beeruuid', type: 'string' },
			{ name: 'yeast_lo', type: 'float' },
			{ name: 'yeast_hi', type: 'float' },
			{ name: 'webcam_url', type: 'string' },
			{ name: 'webcam_light', type: 'int' }
		],
		id: 'record',
		url: url
	};

	var dataAdapter = new $.jqx.dataAdapter(source, {
		loadComplete: function (records) {
			record = dataAdapter.records[0];
			var oline = (record.online) ? "On-line" : "Off-line";
			$("#info_uuid").html(record.uuid);
			$("#info_system").html(record.node +  "/" + record.alias);
			$("#info_online").html(oline);
			$("#info_beer").html(record.beercode + " - " + record.beername);
			$("#info_mode").jqxDropDownList('selectItem', record.mode);
			$("#info_stage").jqxDropDownList('selectItem', record.stage);
			$("#info_profile").html(record.profile_name);
			blank['name'] = record.alias;
			blank['code'] = record.alias.toUpperCase();
			blank['uuid'] = record.uuid;
			if (record.profile_name == "")
				$("#info_mode").jqxDropDownList('disableItem', "PROFILE");
			else
				$("#info_mode").jqxDropDownList('enableItem', "PROFILE");
			$("#target_lo").val(record.setpoint_low);
			$("#target_hi").val(record.setpoint_high);
			if (record.online && ((record.mode == "FRIDGE") || (record.mode == "BEER"))) {
				$("#target_lo").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
				$("#target_hi").jqxNumberInput({ readOnly: false, Width: 70, spinButtons: true });
			} else {
				$("#target_lo").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
				$("#target_hi").jqxNumberInput({ readOnly: true, Width: 50, spinButtons: false });
			}

			if (record.online && record.door_address && (record.door_state != "0")) {
				$("#fermenter_doorled").html('<div class="LEDyellow_on"></div>Door');
			} else {
				$("#fermenter_doorled").html('<div class="LEDyellow_off"></div>Door');
			}
			if (record.online && record.light_address && (record.light_state != "0")) {
				$("#fermenter_lightled").html('<div class="LEDyellow_on"></div>Light');
			} else {
				$("#fermenter_lightled").html('<div class="LEDyellow_off"></div>Light');
			}

			if (record.online && (record.mode != "OFF")) {
				$("#fermenter_powerled").html('<div class="LEDblue_on"></div>Power');
				$("#select_beer").jqxDropDownList({ disabled: true });
				$("#select_beer").jqxDropDownList('clearSelection');
				$("#select_beer").hide();
			} else {
				$("#fermenter_powerled").html('<div class="LEDblue_off"></div>Power');
				$("#select_beer").show();
				$("#select_beer").jqxDropDownList({ disabled: false });
			}
			if (record.online && (record.alarm != "0")) {
				$("#fermenter_alarmled").html('<div class="LEDred_on"></div>Alarm');
			} else {
				$("#fermenter_alarmled").html('<div class="LEDred_off"></div>Alarm');
			}

			if (record.online && (record.heater_state != "0")) {
				$("#fermenter_led1").html('<div class="LEDgreen_on"></div>Heat');
			} else {
				$("#fermenter_led1").html('<div class="LEDgreen_off"></div>Heat');
			}
			if (record.online && (record.cooler_state != "0")) {
				$("#fermenter_led2").html('<div class="LEDgreen_on"></div>Cool');
			} else {
				$("#fermenter_led2").html('<div class="LEDgreen_off"></div>Cool');
			}
			if (record.online && (record.fan_state != "0")) {
				$("#fermenter_led3").html('<div class="LEDgreen_on"></div>Fan');
			} else {
				$("#fermenter_led3").html('<div class="LEDgreen_off"></div>Fan');
			}
			if (record.online && (record.mode == "NONE")) {
				$("#fermenter_toggle1").jqxSwitchButton( 'enable' );
				$("#fermenter_toggle2").jqxSwitchButton( 'enable' );
				$("#fermenter_toggle3").jqxSwitchButton( 'enable' );
			} else {
				$("#fermenter_toggle1").jqxSwitchButton( 'disable' );
				$("#fermenter_toggle2").jqxSwitchButton( 'disable' );
				$("#fermenter_toggle3").jqxSwitchButton( 'disable' );
				$("#fermenter_toggle1").val( (record.heater_state != "0") );
				$("#fermenter_toggle2").val( (record.cooler_state != "0") );
				$("#fermenter_toggle3").val( (record.fan_state != "0") );
			}

			if (record.online && (record.mode == "PROFILE")) {
				if (record.profile_state == "OFF") {
					$("#select_profile").show();
					$("#select_profile").jqxDropDownList({ disabled: false });
					$("#info_mode").jqxDropDownList({ disabled: false });
					$('#Profile1').jqxButton({ template: "success", value: "Starten" });
					$("#Profile1").show();
					$("#Profile2").hide();
					$("#status_profile").html('');
				} else if (record.profile_state == "RUN") {
					$("#select_profile").jqxDropDownList({ disabled: true });
					$("#select_profile").hide();
					$("#info_mode").jqxDropDownList({ disabled: true });
					$('#Profile1').jqxButton({ template: "danger", value: "Afbreken" });
					$('#Profile2').jqxButton({ template: "primary", value: "Pauze" });
					$("#Profile1").show();
					$("#Profile2").show();
					$("#status_profile").html('Profiel actief, '+record.profile_percent+'% gereed');
				} else if (record.profile_state == "PAUSE") {
					$("#select_profile").jqxDropDownList({ disabled: true });
					$("#select_profile").hide();
					$("#info_mode").jqxDropDownList({ disabled: true });
					$('#Profile1').jqxButton({ template: "danger", value: "Afbreken" });
					$('#Profile2').jqxButton({ template: "success", value: "Doorgaan" });
					$("#Profile1").show();
					$("#Profile2").show();
					$("#status_profile").html('Profiel pauze, '+record.profile_percent+'% gereed');
				} else if (record.profile_state == "DONE") {
					$("#select_profile").jqxDropDownList({ disabled: true });
					$("#select_profile").hide();
					$("#info_mode").jqxDropDownList({ disabled: true });
					$('#Profile1').jqxButton({ template: "primary", value: "Profiel Ok" });
					$("#Profile1").show();
					$("#Profile2").hide();
					$("#status_profile").html('Profiel is gereed');
				}
			} else {
				$("#select_profile").show();
				$("#select_profile").jqxDropDownList({ disabled: false });
				$("#info_mode").jqxDropDownList({ disabled: false });
				$("#Profile1").hide();
				$("#Profile2").hide();
				$("#status_profile").html('');
			}
			if (record.online && (record.webcam_url != "")) {
				$("#Camera").show();
			} else {
				$("#Camera").hide();
			}

			yl = record.yeast_lo;
			yh = record.yeast_hi;
			var range = { ranges: [{ startValue:  0, endValue: yl, style: { fill: '#3399FF', stroke: '#3399FF' }, endWidth: 10, startWidth: 10 },
			                       { startValue: yl, endValue: yh, style: { fill: '#00CC33', stroke: '#00CC33' }, endWidth: 10, startWidth: 10 },
					       { startValue: yh, endValue: 40, style: { fill: '#FC6A6A', stroke: '#FC6A6A' }, endWidth: 10, startWidth: 10 }] };
			$("#gaugeContainer_air").jqxGauge( range );
			$("#gaugeContainer_beer").jqxGauge( range );

			$("#gaugeContainer_air").jqxGauge({ caption: { value: 'Air: '+record.air_temperature.toFixed(3) }});
			$('#gaugeContainer_air').jqxGauge({ value: record.air_temperature });
			if (record.air_state == "OK") {
				$("#gaugeContainer_air").jqxGauge({ disabled: false });
			} else {
				$("#gaugeContainer_air").jqxGauge({ disabled: true });
			}
			$("#gaugeContainer_beer").jqxGauge({ caption: { value: 'Beer: '+record.beer_temperature.toFixed(3) }});
			$('#gaugeContainer_beer').jqxGauge({ value: record.beer_temperature });
			if (record.beer_state == "OK") {
				$("#gaugeContainer_beer").jqxGauge({ disabled: false });
			} else {
				$("#gaugeContainer_beer").jqxGauge({ disabled: true });
			}
			$("#gaugeContainer_chiller").jqxGauge({ value: record.chiller_temperature });
			if (record.chiller_state == "OK") {
				$("#gaugeContainer_chiller").jqxGauge({ disabled: false });
			} else {
				$("#gaugeContainer_chiller").jqxGauge({ disabled: true });
			}
		}
	});

	// Get the data immediatly and then at regular intervals to refresh.
	dataAdapter.dataBind();
	setInterval(function() {
		var skip = false;
		if (newBase) {
			sendBase(record.stage, record.mode, record.setpoint_low, record.setpoint_high);
			newBase = false;
			skip = true;
		}
		if (newSwitch) {
			sendSwitch(record.heater_state, record.cooler_state, record.fan_state, record.light_state);
			newSwitch = false;
			skip = true;
		}
		if (newProduct) {
			sendProduct(record.beercode, record.beername, record.beeruuid, record.yeast_lo, record.yeast_hi);
			newProduct = false;
			skip = true;
		}
		if (newProfile) {
			sendProfile(ppayload);
			newProfile = false;
			skip = true;
		}
		if (skip) {
			schedule = 4;	// 2 seconds wait to get the results
		} else {
			if (schedule > 0)
				schedule--;
		}

		if (schedule <= 0) {
			dataAdapter.dataBind();
			schedule = 20;
		}
	}, 500);

	$('#info_mode').on('change', function (event) {
		record.mode = args.item.value;
		$("#fermenter_toggle1").val(0);
		$("#fermenter_toggle2").val(0);
		$("#fermenter_toggle3").val(0);
		newBase = true;
	});
	$('#info_stage').on('select', function (event) {
		record.stage = args.item.value;
		newBase = true;
	});
	$("#select_beer").on('select', function (event) {
		if (event.args) {
			var index = event.args.index;
			var datarecord = productlist.records[index];
			record.beercode = datarecord.code;
			record.beername = datarecord.name;
			record.beeruuid = datarecord.uuid;
			record.yeast_lo = datarecord.yeast_lo;
			record.yeast_hi = datarecord.yeast_hi;
			newProduct = true;
		}
	});
	$("#select_profile").on('select', function (event) {
		if (event.args) {
			var index = event.args.index;
			var datarecord = profilelist.records[index];
			if (datarecord.record == -1) {
				ppayload  = '{"profile":null}';
			} else {
				ppayload  = '{"profile":{"uuid":"'+datarecord.uuid+'","name":"'+datarecord.name+'",';
				ppayload += '"inittemp":{"low":'+datarecord.inittemp_lo+',"high":'+datarecord.inittemp_hi+'},';
				ppayload += '"fridgemode":'+datarecord.fridgemode+',"steps":[';
				for (var i = 0; i < datarecord.steps.length; i++) {
					var row = datarecord.steps[i];
					if (i > 0)
						ppayload += ',';
					ppayload += '{"steptime":'+row['steptime']+',"resttime":'+row['resttime'];
					ppayload += ',"target_lo":'+row['target_lo']+',"target_hi":'+row['target_hi'];
					ppayload += ',"fridgemode":'+row['fridgemode']+',"name":"'+row['name']+'"}';
				}
				ppayload += ']}}';
			}
			newProfile = true;
		}
	});

	$('#target_lo').on('change', function (event) {
		record.setpoint_low = parseFloat(event.args.value);
		// Keep the high target above the low.
		if (record.setpoint_low > record.setpoint_high) {
			record.setpoint_high = record.setpoint_low;
			$("#target_hi").val(record.setpoint_high);
		}
		newBase = true;
	});
	$('#target_hi').on('change', function (event) {
		record.setpoint_high = parseFloat(event.args.value);
		// Keep the low target below the high.
		if (record.setpoint_high < record.setpoint_low) {
			record.setpoint_low = record.setpoint_high;
			$("#target_lo").val(record.setpoint_low);
		}
		newBase = true;
	});

	$("#fermenter_toggle1").on('checked', function (event) {
		if (record.mode == "NONE") {
			record.heater_state = 0;
			newSwitch = true;
		}
	});
	$("#fermenter_toggle1").on('unchecked', function (event) {
		if (record.mode == "NONE") {
			record.heater_state = 100;
			record.cooler_state = 0;
			$("#fermenter_toggle2").val(0);
			newSwitch = true;
		}
	});
	$("#fermenter_toggle2").on('checked', function (event) {
		if (record.mode == "NONE") {
			record.cooler_state = 0;
			newSwitch = true;
		}
	});
	$("#fermenter_toggle2").on('unchecked', function (event) {
		if (record.mode == "NONE") {
			record.cooler_state = 100;
			record.heater_state = 0;
			$("#fermenter_toggle1").val(0);
			newSwitch = true;
		}
	});
	$("#fermenter_toggle3").on('checked', function (event) {
		if (record.mode == "NONE") {
			record.fan_state = 0;
			newSwitch = true;
		}
	});
	$("#fermenter_toggle3").on('unchecked', function (event) {
		if (record.mode == "NONE") {
			record.fan_state = 100;
			newSwitch = true;
		}
	});
	$("#Profile1").click(function () {
		if (record.mode == "PROFILE") {
			if (record.profile_state == "OFF") {
				ppayload  = '{"profile":{"command":"start"}}';
				newProfile = true;
			} else if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) {
				// Open a popup to confirm this action.
				$('#eventWindow').jqxWindow('open');
				$("#delOk").click(function () {
					ppayload  = '{"profile":{"command":"abort"}}';
					newProfile = true;
				});
			} else if (record.profile_state == "DONE") {
				ppayload  = '{"profile":{"command":"done"}}';
				newProfile = true;
			}
		}
	});
	$("#Profile2").click(function () {
		if (record.mode == "PROFILE") {
			if ((record.profile_state == "RUN") || (record.profile_state == "PAUSE")) {
				ppayload  = '{"profile":{"command":"pause"}}';
				newProfile = true;
			}
		}
	});

	// The chart button.
   	$("#FLog").jqxButton({ template: "primary", width: '150px', theme: theme });
	$("#FLog").click(function () {
		var url="log_fermentation.php?code=" + record.beercode + "&name=" + record.beername;
		window.open(url);
	});
	$("#Camera").jqxButton({ template: "primary", width: '150px', theme: theme });
	$("#Camera").click(function () {
		record.light_state = 100;
		newSwitch = true;
		var url=record.webcam_url;
		window.open(url);
	});
	createAbortElements();
});

mercurial