Fri, 14 Jun 2019 20:28:26 +0200
Version 0.4.3 Major rework on priming sugars.
/***************************************************************************** * Copyright (C) 2014-2019 * * Michiel Broek <mbroek at mbse dot eu> * * This file is part of BrewCloud * * 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 dataRecord = {}; function calcBatchVolume() { var calc = $("#calc_boil_volume").val(); var boil_size = parseFloat($("#boil_size").jqxNumberInput('decimal')); var evap_rate = parseFloat($("#evap_rate").jqxNumberInput('decimal')); var boil_time = parseFloat($("#boil_time").jqxNumberInput('decimal')); var top_up = parseFloat($("#top_up_kettle").jqxNumberInput('decimal')); if (calc) { // If checked, calculate the batch size. var batch = boil_size - (evap_rate * boil_time / 60) + top_up; $("#batch_size").val(batch); } } var url = "includes/db_inventory_equipments.php"; // tooltips $("#name").jqxTooltip({ content: 'The unique name of this brew equipment.' }); $("#notes").jqxTooltip({ content: 'Some notes about the equipment.' }); $("#tun_volume").jqxTooltip({ content: 'Mash TUN volume.' }); $("#tun_height").jqxTooltip({ content: 'Mash TUN height in cm.' }); $("#tun_weight").jqxTooltip({ content: 'Mash TUN weight in Kg.' }); $("#tun_material").jqxTooltip({ content: 'Mash TUN material. Needed to calculate the right strike temperature.' }); $("#mash_volume").jqxTooltip({ content: 'Liters maisch water voor de eerste maisch stap.' }); $("#mash_max").jqxTooltip({ content: 'Maximale moutstort voor deze installatie in Kg.' }); $("#lauter_volume").jqxTooltip({ content: 'Total lauter volume.' }); $("#lauter_height").jqxTooltip({ content: 'Height of the lauter TUN in cm.' }); $("#lauter_deadspace").jqxTooltip({ content: 'Volume loss in the lauter TUN.' }); $("#efficiency").jqxTooltip({ content: 'Average efficiency.' }); $("#kettle_volume").jqxTooltip({ content: 'Boil kettle volume in liters.' }); $("#kettle_height").jqxTooltip({ content: 'Boil kettle height in cm.' }); $("#boil_size").jqxTooltip({ content: 'Normal boil volume in liters' }); $("#evap_rate").jqxTooltip({ content: 'Evaporation in liters per hour.' }); $("#boil_time").jqxTooltip({ content: 'Normal boil time in minutes.' }); $("#top_up_kettle").jqxTooltip({ content: 'Extra water added to the boil.' }); $("#hop_utilization").jqxTooltip({ content: '100% for smaller installations, higher for large breweries.' }); $("#batch_size").jqxTooltip({ content: 'Calculated batch size, liters at end of the boil.' }); $("#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: 'name', type: 'string' }, { name: 'boil_size', type: 'float' }, { name: 'batch_size', type: 'float' }, { name: 'tun_volume', type: 'float' }, { name: 'tun_weight', type: 'float' }, { name: 'tun_specific_heat', type: 'float' }, { name: 'tun_material', type: 'int' }, { name: 'tun_height', type: 'float' }, { name: 'top_up_water', type: 'float' }, { name: 'trub_chiller_loss', type: 'float' }, { name: 'evap_rate', type: 'float' }, { name: 'boil_time', type: 'float' }, { name: 'calc_boil_volume', type: 'int' }, { name: 'top_up_kettle', type: 'float' }, { name: 'hop_utilization', type: 'float' }, { name: 'notes', type: 'string' }, { name: 'lauter_volume', type: 'float' }, { name: 'lauter_height', type: 'float' }, { name: 'lauter_deadspace', type: 'float' }, { name: 'kettle_volume', type: 'float' }, { name: 'kettle_height', type: 'float' }, { name: 'mash_volume', type: 'float' }, { name: 'mash_max', type: 'float' }, { name: 'efficiency', type: 'float' } ], id: 'record', url: url, deleterow: function (rowid, commit) { // synchronize with the server - send delete command var data = "delete=true&" + $.param({ record: rowid }); $.ajax({ dataType: 'json', url: url, cache: false, data: data, type: "POST", success: function (data, status, xhr) { // delete command is executed. commit(true); }, error: function (jqXHR, textStatus, errorThrown) { commit(false); } }); }, addrow: function (rowid, rowdata, position, commit) { var data = "insert=true&" + $.param(rowdata); $.ajax({ dataType: 'json', url: url, cache: false, data: data, type: "POST", success: function (data, status, xhr) { commit(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } }); }, updaterow: function (rowid, rowdata, commit) { var data = "update=true&" + $.param(rowdata); $.ajax({ dataType: 'json', url: url, cache: false, data: data, type: "POST", success: function (data, status, xhr) { // update command is executed. commit(true); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } }); } }; // initialize the input fields. $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); $("#boil_size").jqxNumberInput( Spin1dec ); $("#batch_size").jqxNumberInput( Spin2dec ); $("#batch_size").jqxNumberInput({ spinButtonsStep: 0.5 }); $("#tun_volume").jqxNumberInput( Spin1dec ); $("#tun_weight").jqxNumberInput( Spin2dec ); $("#tun_specific_heat").jqxNumberInput({ inputMode: 'simple', readOnly: true, theme: theme, width: 70, height: 23, decimalDigits: 3 }); $("#tun_material").jqxDropDownList({ theme: theme, source: MaterialAdapter, valueMember: 'id', displayMember: 'nl', // selectedIndex: 0, width: 180, height: 23, autoDropDownHeight: true }); $("#tun_height").jqxNumberInput( Spin1dec ); $("#top_up_water").jqxNumberInput( Spin1dec ); $("#trub_chiller_loss").jqxNumberInput( Spin1dec ); $("#evap_rate").jqxNumberInput( Spin2dec ); $("#boil_time").jqxNumberInput( PosInt ); $("#boil_time").jqxNumberInput({ max: 1440 }); $("#calc_boil_volume").jqxCheckBox({ theme: theme, width: 120, height: 23 }); $("#calc_boil_volume").on('checked', function (event) { $("#batch_size").jqxNumberInput({ readOnly: true, width: 90, spinButtons: false }); }); $("#calc_boil_volume").on('unchecked', function (event) { $("#batch_size").jqxNumberInput({ readOnly: false, width: 110, spinButtons: true }); }); $("#top_up_kettle").jqxNumberInput( Spin1dec ); $("#hop_utilization").jqxNumberInput( Perc0 ); $("#hop_utilization").jqxNumberInput({ Max: 200 }); $("#lauter_volume").jqxNumberInput( Spin1dec ); $("#lauter_height").jqxNumberInput( Spin1dec ); $("#lauter_deadspace").jqxNumberInput( Spin1dec ); $("#kettle_volume").jqxNumberInput( Spin1dec ); $("#kettle_height").jqxNumberInput( Spin1dec ); $("#mash_volume").jqxNumberInput( Spin1dec ); $("#mash_max").jqxNumberInput( Spin1dec ); $("#efficiency").jqxNumberInput( Perc1dec ); var dataAdapter = new $.jqx.dataAdapter(source); var editrow = -1; // initialize jqxGrid $("#jqxgrid").jqxGrid({ width: 1280, height: 630, source: dataAdapter, theme: theme, showstatusbar: true, renderstatusbar: function (statusbar) { var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>"); container.append(addButton); statusbar.append(container); addButton.jqxButton({ theme: theme, width: 90, height: 20 }); // add new row. addButton.click(function (event) { editrow = -1; $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); $("#name").val('Nieuwe brouwset'); $("#boil_size").val(18); $("#batch_size").val(15.3); $("#tun_volume").val(20); $("#tun_weight").val(2); $("#tun_specific_heat").val(0.11); $("#tun_material").val(0); $("#tun_height").val(20); $("#top_up_water").val(0); $("#trub_chiller_loss").val(0.5); $("#evap_rate").val(1.8); $("#boil_time").val(90); $("#calc_boil_volume").val(1); $("#top_up_kettle").val(0); $("#hop_utilization").val(100); $("#notes").val(''); $("#lauter_volume").val(20); $("#lauter_height").val(20); $("#lauter_deadspace").val(0.5); $("#kettle_volume").val(20); $("#kettle_height").val(20); $("#mash_volume").val(18); $("#mash_max").val(6); $("#efficiency").val(75); $("#popupWindow").jqxWindow('open'); }); }, filterable: false, ready: function() { $('#boil_size').on('change', function (event) { calcBatchVolume(); }); $('#evap_rate').on('change', function (event) { calcBatchVolume(); }); $('#boil_time').on('change', function (event) { calcBatchVolume(); }); $('#top_up_kettle').on('change', function (event) { calcBatchVolume(); }); $("#calc_boil_volume").on('change', function (event) { calcBatchVolume(); }); $('#tun_material').on('change', function (event) { dataRecord.tun_specific_heat = MaterialData[event.args.index].sh; $("#tun_specific_heat").val(dataRecord.tun_specific_heat); }); }, columns: [ { text: 'Installatie naam', datafield: 'name', width: 200 }, { text: 'Kook volume', datafield: 'boil_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, { text: 'Batch volume', datafield: 'batch_size', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, { text: 'Opmerkingen', datafield: 'notes' }, { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () { return "Wijzig"; }, buttonclick: function (row) { // open the popup window when the user clicks a button. editrow = row; $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); // get the clicked row's data and initialize the input fields. dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); $("#name").val(dataRecord.name); $("#boil_size").val(dataRecord.boil_size); $("#batch_size").val(dataRecord.batch_size); $("#tun_volume").val(dataRecord.tun_volume); $("#tun_weight").val(dataRecord.tun_weight); $("#tun_specific_heat").val(dataRecord.tun_specific_heat); $("#tun_material").val(dataRecord.tun_material); $("#tun_height").val(dataRecord.tun_height); $("#top_up_water").val(dataRecord.top_up_water); $("#trub_chiller_loss").val(dataRecord.trub_chiller_loss); $("#evap_rate").val(dataRecord.evap_rate); $("#boil_time").val(dataRecord.boil_time); $("#calc_boil_volume").val(dataRecord.calc_boil_volume); $("#top_up_kettle").val(dataRecord.top_up_kettle); $("#hop_utilization").val(dataRecord.hop_utilization); $("#notes").val(dataRecord.notes); $("#lauter_volume").val(dataRecord.lauter_volume); $("#lauter_height").val(dataRecord.lauter_height); $("#lauter_deadspace").val(dataRecord.lauter_deadspace); $("#kettle_volume").val(dataRecord.kettle_volume); $("#kettle_height").val(dataRecord.kettle_height); $("#mash_volume").val(dataRecord.mash_volume); $("#mash_max").val(dataRecord.mash_max); $("#efficiency").val(dataRecord.efficiency); // show the popup window. $("#popupWindow").jqxWindow('open'); } } ] }); // initialize the popup window and buttons. $("#popupWindow").jqxWindow({ width: 1050, height: 600, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 }); $("#popupWindow").on('open', function () { $("#name").jqxInput('selectAll'); }); $("#Delete").jqxButton({ template: "danger", width: '90px', theme: theme }); $("#Delete").click(function () { if (editrow >= 0) { // Open a popup to confirm this action. $('#eventWindow').jqxWindow('open'); $("#delOk").click(function () { var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); $("#jqxgrid").jqxGrid('deleterow', rowID); }); } $("#popupWindow").jqxWindow('hide'); }); $("#Cancel").jqxButton({ template: "primary", width: '90px', theme: theme }); $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); // update the edited row when the user clicks the 'Save' button. $("#Save").click(function () { var rowID = -1; if (editrow >= 0) { var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); } var row = { record: rowID, name: $("#name").val(), boil_size: parseFloat($("#boil_size").jqxNumberInput('decimal')), batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), tun_volume: parseFloat($("#tun_volume").jqxNumberInput('decimal')), tun_weight: parseFloat($("#tun_weight").jqxNumberInput('decimal')), tun_specific_heat: parseFloat($("#tun_specific_heat").jqxNumberInput('decimal')), tun_material: $("#tun_material").val(), tun_height: parseFloat($("#tun_height").jqxNumberInput('decimal')), top_up_water: parseFloat($("#top_up_water").jqxNumberInput('decimal')), trub_chiller_loss: parseFloat($("#trub_chiller_loss").jqxNumberInput('decimal')), evap_rate: parseFloat($("#evap_rate").jqxNumberInput('decimal')), boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), calc_boil_volume: $("#calc_boil_volume").val(), top_up_kettle: parseFloat($("#top_up_kettle").jqxNumberInput('decimal')), hop_utilization: parseFloat($("#hop_utilization").jqxNumberInput('decimal')), notes: $("#notes").val(), lauter_volume: parseFloat($("#lauter_volume").jqxNumberInput('decimal')), lauter_height: parseFloat($("#lauter_height").jqxNumberInput('decimal')), lauter_deadspace: parseFloat($("#lauter_deadspace").jqxNumberInput('decimal')), kettle_volume: parseFloat($("#kettle_volume").jqxNumberInput('decimal')), kettle_height: parseFloat($("#kettle_height").jqxNumberInput('decimal')), mash_volume: parseFloat($("#mash_volume").jqxNumberInput('decimal')), mash_max: parseFloat($("#mash_max").jqxNumberInput('decimal')), efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')) }; if (editrow >= 0) { $('#jqxgrid').jqxGrid('updaterow', rowID, row); } else { $('#jqxgrid').jqxGrid('addrow', null, row); } $("#popupWindow").jqxWindow('hide'); location.reload( true ); // reload ourself. }); createDelElements(); });