diff -r 22c277be7e7e -r 92d6bc8a4cdd www/js/rec_edit.js --- a/www/js/rec_edit.js Thu Nov 15 22:36:09 2018 +0100 +++ b/www/js/rec_edit.js Fri Nov 16 16:20:17 2018 +0100 @@ -52,17 +52,13 @@ console.log("record:" + my_record + " return:" + my_return + " theme:" + theme); -// $("#jqxNotification").jqxNotification({ width: "auto", position: "top-right", opacity: 0.9, -// autoOpen: false, closeOnClick: true, autoClose: true, template: "info", blink: false, -// icon: { width: 25, height: 25, url: '../../images/smiley.png', padding: 5 } -// }); - function calcFermentables() { console.log("calcFermentables()"); - sugarsf = 0; // Sugar weight + sugarsf = 0; sugarsm = 0; - psugar = 0; // Percentage real sugars - pcara = 0; // Percentage cara/crystal malts + psugar = 0; + pcara = 0; + var colorw = 0; // Colors working var rows = $('#fermentableGrid').jqxGrid('getboundrows'); for (var i = 0; i < rows.length; i++) { @@ -77,19 +73,48 @@ sugarsm += d; } sugarsf += d; - // colorw here too + colorw += row.f_amount * ebc_to_srm(row.f_color) / parseFloat($("#batch_size").jqxNumberInput('decimal')) * 8.34436; } $('#est_og').val(estimate_sg(sugarsf, parseFloat($("#batch_size").jqxNumberInput('decimal')))); preboil_sg = estimate_sg(sugarsm, parseFloat($("#boil_size").jqxNumberInput('decimal'))); + $('#est_color').val(kw_to_ebc($("#color_method").val(), colorw)); + }; + + function calcIBUs() { + console.log("calcIBUs()"); + + var total_ibus = 0; + var rows = $('#hopGrid').jqxGrid('getboundrows'); + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + + total_ibus += toIBU(row.h_useat, + row.h_form, + preboil_sg, + parseFloat($("#batch_size").jqxNumberInput('decimal')), + parseFloat(row.h_amount), + parseFloat(row.h_time), + parseFloat(row.h_alpha), + $("#ibu_method").val() + ); + } + console.log("IBUs: " + total_ibus); + $('#est_ibu').val(total_ibus); + $('#hopGrid').jqxGrid('render'); }; function calcInit () { console.log("calc.init()"); // $('#est_og').on('change', function (event) { calcFermentables(); }); - $('#efficiency').on('change', function (event) { calcFermentables(); }); - $('#batch_size').on('change', function (event) { calcFermentables(); }); - $('#boil_time').on('change', function (event) { calcFermentables(); }); - $('#fermentableGrid').on('change', function (event) { calcFermentables(); }); + $('#color_method').on('change', function (event) { calcFermentables(); }); + $('#ibu_method').on('change', function (event) { + calcFermentables(); + calcIBUs(); + }); +// $('#efficiency').on('change', function (event) { calcFermentables(); }); +// $('#batch_size').on('change', function (event) { calcFermentables(); }); +// $('#boil_time').on('change', function (event) { calcFermentables(); }); +// $('#fermentableGrid').on('change', function (event) { calcFermentables(); }); }; // Styles dropdown list @@ -642,6 +667,7 @@ }); }, ready: function() { + calcIBUs(); $('#jqxTabs').jqxTabs('next'); }, columns: [ @@ -672,7 +698,8 @@ cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { var ibu = toIBU(rowdata.h_useat, rowdata.h_form, - parseFloat($("#est_og").jqxNumberInput('decimal')), + preboil_sg, + /*parseFloat($("#est_og").jqxNumberInput('decimal')),*/ parseFloat($("#batch_size").jqxNumberInput('decimal')), parseFloat(rowdata.h_amount), parseFloat(rowdata.h_time), @@ -683,7 +710,11 @@ } } ] - }) + }); + $("#hopGrid").on('cellendedit', function (event) { + //calcIBUs(); + //$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc'); + }); }; // Inline miscs editor @@ -1159,6 +1190,7 @@ }); }, ready: function() { + calcInit(); $('#jqxTabs').jqxTabs('first'); }, columns: [ @@ -1219,7 +1251,8 @@ // initialize the input fields. var srcType = [ "All Grain", "Partial Mash", "Extract" ]; var srcColor = [ "Morey", "Mosher", "Daniels" ]; - var srcIBU = [ "Tinseth", "Rager", "Garetz", "Daniels", "Mosher", "Noonan" ]; + //var srcIBU = [ "Tinseth", "Rager", "Garetz", "Daniels", "Mosher", "Noonan" ]; + var srcIBU = [ "Tinseth", "Rager", "Daniels" ]; // Only these are supported at this time. $("#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 }); @@ -1254,7 +1287,7 @@ $("#est_ibu").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); $("#st_ibu_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); $("#st_ibu_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); - $("#ibu_method").jqxDropDownList({ theme: theme, source: srcIBU, width: 125, height: 23, dropDownHeight: 180 }); + $("#ibu_method").jqxDropDownList({ theme: theme, source: srcIBU, width: 125, height: 23, dropDownHeight: 95, dropDownVerticalAlignment: 'top' }); $("#est_carb").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); $("#st_carb_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); @@ -1273,8 +1306,6 @@ position: 'top' }); - calcInit(); - $("#Print").jqxButton({ template: "info", width: '80px', theme: theme }); $("#Print").click(function () { // Open print in a new tab.