diff -r 2a6c00d325b2 -r e6e5d007eb54 www/js/rec_edit.js --- a/www/js/rec_edit.js Mon Dec 17 13:46:15 2018 +0100 +++ b/www/js/rec_edit.js Mon Dec 17 22:24:32 2018 +0100 @@ -174,6 +174,44 @@ } } + + function calcWater() { + + console.log("calcWater()"); + var rows = $('#waterGrid').jqxGrid('getrows'); + var liters = 0; + var calcium = 0; + var magnesium = 0; + var sodium = 0; + var total_alkalinity = 0; + var chloride = 0; + var sulfate = 0; + var ph = 0; + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + liters += row.w_amount; + calcium += row.w_amount * row.w_calcium; + magnesium += row.w_amount * row.w_magnesium; + sodium += row.w_amount * row.w_sodium; + total_alkalinity += row.w_amount * row.w_total_alkalinity; + chloride += row.w_amount * row.w_chloride; + sulfate += row.w_amount * row.w_sulfate; + ph += Math.pow(10, -row.w_ph) * row.w_amount; + } + $('#wg_volume').val(liters); + calcium = Math.round(calcium / liters * 10) / 10; + $('#wg_calcium').val(calcium); + $('#wg_magnesium').val(Math.round(magnesium / liters * 10) / 10); + $('#wg_sodium').val(Math.round(sodium / liters * 10) / 10); + $('#wg_total_alkalinity').val(Math.round(total_alkalinity / liters * 10) / 10); + $('#wg_chloride').val(Math.round(chloride / liters * 10) / 10); + sulfate = Math.round(sulfate / liters * 10) / 10; + $('#wg_sulfate').val(sulfate); + // Note: brouwhulp has the malts included here in the result. + ph = Math.round(-Math.log10(ph / liters) * 10) / 10; + $('#wg_ph').val(ph); + } + function calcFermentablesFromOG(OG) { console.log("calcFermentablesFromOG("+OG+")"); @@ -259,6 +297,10 @@ calcABV(); // and ABV calcIBUs(); // and the IBU's. }); + $('#mash_ph').on('change', function (event) { + $("#tgt_mash_ph").val(parseFloat(event.args.value)); + calcWater(); + }); }; $("#styleSelect").jqxDropDownList({ @@ -378,9 +420,15 @@ { name: 'est_ibu', type: 'float' }, { name: 'ibu_method', type: 'string' }, { name: 'est_carb', type: 'float' }, - { name: 'mash_sparge_temp', type: 'float' }, + { name: 'sparge_temp', type: 'float' }, + { name: 'sparge_ph', type: 'float' }, + { name: 'sparge_volume', type: 'float' }, + { name: 'sparge_acid_type', type: 'string' }, + { name: 'sparge_acid_perc', type: 'float' }, + { name: 'sparge_acid_amount', type: 'float' }, { name: 'mash_ph', type: 'float' }, { name: 'mash_name', type: 'string' }, + { name: 'calc_acid', type: 'bool' }, { name: 'fermentables', type: 'array' }, { name: 'hops', type: 'string' }, { name: 'miscs', type: 'string' }, @@ -434,7 +482,14 @@ $("#st_carb_max").val(dataRecord.st_carb_max); $("#mash_name").val(dataRecord.mash_name); $("#mash_ph").val(dataRecord.mash_ph); - $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp); + $("#tgt_mash_ph").val(dataRecord.mash_ph); + $("#sparge_temp").val(dataRecord.sparge_temp); + $("#sparge_ph").val(dataRecord.sparge_ph); + $("#sparge_volume").val(dataRecord.sparge_volume); + $("#sparge_acid_type").val(dataRecord.sparge_acid_type); + $("#sparge_acid_perc").val(dataRecord.sparge_acid_perc); + $("#sparge_acid_amount").val(dataRecord.sparge_acid_amount); + $("#calc_acid").val(dataRecord.calc_acid); editFermentable(dataRecord); editHop(dataRecord); editMisc(dataRecord); @@ -999,6 +1054,15 @@ var row = records[i]; row.m_weight = row.m_amount * 1000; data.push(row); + // Initial set water agent values. + if (row.m_name == 'CaCl2') + $("#wa_cacl2").val(row.m_weight); + if (row.m_name == 'CaSO4') + $("#wa_caso4").val(row.m_weight); + if (row.m_name == 'MgSO4') + $("#wa_mgso4").val(row.m_weight); + if (row.m_name == 'NaCl') + $("#wa_nacl").val(row.m_weight); } return data; }, @@ -1421,9 +1485,11 @@ var id = $("#waterGrid").jqxGrid('getrowid', selectedrowindex); var commit = $("#waterGrid").jqxGrid('deleterow', id); } + calcWater(); }); }, ready: function() { + calcWater(); $('#jqxTabs').jqxTabs('next'); }, columns: [ @@ -1447,7 +1513,13 @@ { text: 'pH', editable: false, datafield: 'w_ph', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' } ] }); - }; // editWater = function (data) { + $("#waterGrid").on('cellendedit', function (event) { + var args = event.args; + console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value); + $("#waterGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value); + calcWater(); + }); + }; // inline mash editor var editMash = function (data) { @@ -1583,6 +1655,8 @@ var srcColor = [ "Morey", "Mosher", "Daniels" ]; //var srcIBU = [ "Tinseth", "Rager", "Garetz", "Daniels", "Mosher", "Noonan" ]; var srcIBU = [ "Tinseth", "Rager", "Daniels" ]; // Only these are supported at this time. + var srcDeAcid = [ "NaHCO3", "Na2CO3", "CaCO3", "Ca(OH)2" ]; + var srcAcid = [ "Melkzuur", "Zoutzuur", "Fosforzuur", "Zwavelzuur" ]; $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); $("#st_name").jqxInput({ theme: theme, width: 250, height: 23 }); @@ -1627,11 +1701,53 @@ $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 }); $("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); + $("#tgt_mash_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, readOnly: true }); $("#mash_sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 70, max: 98, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); // Hop flavour and aroma gauges $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); + // Water treatment + $("#wg_volume").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wg_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + + $("#wb_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#wb_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + + $("#pr_calcium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_magnesium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_sodium").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_total_alkalinity").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_chloride").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_sulfate").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + $("#pr_ph").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 74, height: 23, decimalDigits: 1, readOnly: true }); + + $("#wa_cacl2").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); + $("#wa_caso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); + $("#wa_mgso4").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); + $("#wa_nacl").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: ' gr', symbolPosition: 'right' }); + + $("#calc_acid").jqxCheckBox({ theme: theme, width: 120, height: 23 }); + $("#wa_ph_up").jqxDropDownList({ theme: theme, source: srcDeAcid, width: 125, height: 23, dropDownHeight: 128 }); + $("#wa_ph_up").val('NaHCO3'); + $("#wa_ph_down").jqxDropDownList({ theme: theme, source: srcAcid, width: 125, height: 23, dropDownHeight: 128 }) + $("#wa_ph_down").val('Melkzuur'); + + $("#sparge_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); + $("#sparge_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); + $("#sparge_acid_amount").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, decimalDigits: 5, readOnly: true }); + // Tabs inside the popup window. $('#jqxTabs').jqxTabs({ theme: theme, @@ -1720,7 +1836,13 @@ est_carb: parseFloat($("#est_carb").jqxNumberInput('decimal')), mash_name: $("#mash_name").val(), mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')), - mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), + sparge_temp: parseFloat($("#sparge_temp").jqxNumberInput('decimal')), + sparge_ph: parseFloat($("#sparge_ph").jqxNumberInput('decimal')), + sparge_volume: parseFloat($("#sparge_volume").jqxNumberInput('decimal')), + sparge_acid_type: $("#sparge_acid_type").val(), + sparge_acid_perc: parseFloat($("#sparge_acid_perc").jqxNumberInput('decimal')), + sparge_acid_amount: parseFloat($("#sparge_acid_amount").jqxNumberInput('decimal')), + calc_acid: $("#calc_acid").val(), fermentables: fermentablerow, hops: hoprow, miscs: miscrow,