# HG changeset patch # User Michiel Broek # Date 1584559763 -3600 # Node ID 9ac2fb6b13116bcac2c832506388925cd106673d # Parent 9d1af81b20efb7f6d99c40cea5127f7778f2ab68 Added failsave starting calcWater() when the main data is not yet loaded. diff -r 9d1af81b20ef -r 9ac2fb6b1311 www/js/prod_edit.js --- a/www/js/prod_edit.js Wed Mar 18 19:46:15 2020 +0100 +++ b/www/js/prod_edit.js Wed Mar 18 20:29:23 2020 +0100 @@ -64,6 +64,7 @@ ok_yeasts = 1, // Yeasts are in stock ok_waters = 1, // Waters are in stock + data_loaded = 0; error_count = 0; hop_flavour = 0, @@ -567,6 +568,7 @@ calcStage(); $('#jqxTabs').jqxTabs('select', 2); console.log('main data ready'); + data_loaded = 1; }, loadError: function(jqXHR, status, error) { console.log('main data load error: ' + status + ' ' + error); @@ -2781,6 +2783,7 @@ } function MashpH() { + console.log('MashpH()'); var n = 0, pH = 5.4, deltapH = 0.001, deltapd = 0.1, pd = ProtonDeficit(pH); while (((pd < -deltapd) || (pd > deltapd)) && (n < 2000)) { @@ -2811,7 +2814,12 @@ function calcWater() { - //console.log('calcWater()'); + console.log('calcWater()'); + if (! data_loaded) { + console.log('failsave'); + return; + } + var liters = 0, calcium = 0, magnesium = 0, @@ -2870,9 +2878,10 @@ $('#wg_sulfate').val(Math.round(sulfate * 10) / 10); // Note: brouwhulp has the malts included here in the result. //var wg_ph = ph; + var mash_ph = Round(MashpH(), 1); $('#wg_ph').val(Round(ph, 1)); - $('#wb_ph').val(Round(MashpH(), 1)); - $('#est_mash_ph').val(Round(MashpH(), 1)); + $('#wb_ph').val(mash_ph); + $('#est_mash_ph').val(mash_ph); bicarbonate = total_alkalinity * 1.22; wg_bicarbonate = bicarbonate; diff -r 9d1af81b20ef -r 9ac2fb6b1311 www/js/rec_edit.js --- a/www/js/rec_edit.js Wed Mar 18 19:46:15 2020 +0100 +++ b/www/js/rec_edit.js Wed Mar 18 20:29:23 2020 +0100 @@ -48,7 +48,7 @@ MMNa2CO3 = 105.996, MMNaCl = 58.443, MMCaOH2 = 74.06268; - + data_loaded = 0; function createDelElements() { $('#eventWindow').jqxWindow({ @@ -851,6 +851,7 @@ editYeast(dataRecord); editMash(dataRecord); $('#jqxTabs').jqxTabs('next'); + data_loaded = 1; }, loadError: function(jqXHR, status, error) {}, beforeLoadComplete: function(records) { $('#jqxLoader').jqxLoader('open'); } @@ -1922,6 +1923,11 @@ function calcWater() { console.log('calcWater()'); + if (! data_loaded) { + console.log('failsave'); + return; + } + var liters = 0, calcium = 0, magnesium = 0,