Fermentables, hops, miscs and yeast now have tests against the added moment with the brewing stage. Added to inventory edit rows, delete rows, and pick choices for the moment to add or edit. Some more popups to explain certain blocks.

Sun, 23 May 2021 16:41:35 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 23 May 2021 16:41:35 +0200
changeset 752
f68e3bbc1ada
parent 751
3ba26a83eb93
child 753
a59ecd6d72f4

Fermentables, hops, miscs and yeast now have tests against the added moment with the brewing stage. Added to inventory edit rows, delete rows, and pick choices for the moment to add or edit. Some more popups to explain certain blocks.

www/js/prod_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/prod_edit.js	Fri May 21 16:36:06 2021 +0200
+++ b/www/js/prod_edit.js	Sun May 23 16:41:35 2021 +0200
@@ -128,6 +128,110 @@
 
 
 
+function drop_endis(flag, item, index) {
+ (flag) ? $(item).jqxDropDownList('disableAt', index) : $(item).jqxDropDownList('enableAt', index);
+}
+
+
+
+function block_fermentable(stage, added) {
+ if (stage > 5 && added < 4) // After fermentation and added before packaging
+  return true;
+ if (stage > 3 && added < 3) // After primary and added before sec/tert
+  return true;
+ if (stage > 2 && added < 2) // After boil and added during mash or boil
+  return true;
+ return false;
+}
+
+
+
+function minimum_fermentable(stage, added) {
+ if (stage > 5 && added < 4)
+  return 4;
+ if (stage > 3 && added < 3)
+  return 3;
+ if (stage > 2 && added < 2)
+  return 2;
+ return added;
+}
+
+
+
+function minimum_hop(stage, useat)
+{
+ if (stage > 2 && useat < 5)
+  return 5;
+ return useat;
+}
+
+
+
+function block_hop(stage, useat)
+{
+ if (stage > 2 && useat < 5)
+  return true;
+ return false;
+}
+
+
+
+function block_misc(stage, use_use) {
+ if (stage > 5 && use_use < 5)
+  return true;
+ if (stage > 3 && use_use < 4)
+  return true;
+ if (stage > 2 && use_use < 3)
+  return true;
+ if (stage > 1 && use_use < 1)
+  return true;
+ return false;
+}
+
+
+
+function minimum_misc(stage, use_use) {
+ if (stage > 5 && use_use < 5)
+  return 5;
+ if (stage > 3 && use_use < 4)
+  return 4;
+ if (stage > 2 && use_use < 3)
+  return 3;
+ if (stage > 1 && use_use < 1)
+  return 1;
+ return use_use;
+}
+
+
+
+function block_yeast(stage, use) {
+ if (stage > 3 && use < 1)
+  return true;
+ if (stage > 4 && use < 2)
+  return true;
+ if (stage > 5 && use < 3)
+  return true;
+ if (stage > 6 && use < 4)
+  return true;
+ return false;
+}
+
+
+
+function minimum_yeast(stage, use) {
+ if (stage > 3 && use < 1)
+  return 1;
+ if (stage > 4 && use < 2)
+  return 2;
+ if (stage > 5 && use < 3)
+  return 3;
+ if (stage > 6 && use < 4)
+  return 4;
+ return use;
+}
+
+
+
 $(document).ready(function() {
 
  var i,
@@ -754,12 +858,7 @@
        row['f_added'] = 0; // Mash
       }
       /* If stage > added moment, adjust the moment */
-      if (dataRecord.stage > 5 && row['f_added'] < 4)
-       row['f_added'] = 4;
-      if (dataRecord.stage > 3 && row['f_added'] < 3)
-       row['f_added'] = 3;
-      if (dataRecord.stage > 2 && row['f_added'] < 2)
-       row['f_added'] = 2;
+      row['f_added'] = minimum_fermentable(dataRecord.stage, row['f_added']);
       row['f_dissolved_protein'] = datarecord.dissolved_protein;
       row['f_recommend_mash'] = datarecord.recommend_mash;
       row['f_add_after_boil'] = datarecord.add_after_boil;
@@ -792,9 +891,15 @@
      rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
      if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
       id = $('#fermentableGrid').jqxGrid('getrowid', selectedrowindex);
-      percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_percentage');
-      amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_amount');
-      $('#fermentableGrid').jqxGrid('deleterow', id);
+      added = $('#fermentableGrid').jqxGrid('getcellvalue', selectedrowindex, 'f_added');
+      if (block_fermentable(dataRecord.stage, added)) {
+       percent = mount = 0;
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_percentage');
+       amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_amount');
+       $('#fermentableGrid').jqxGrid('deleterow', id);
+      }
      }
      rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
      if (rowscount > 1) {
@@ -840,11 +945,7 @@
     { text: 'Voorraad Kg', datafield: 'f_inventory', width: 120, align: 'right',
      cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
       var color = '#ffffff';
-      if (((dataRecord.inventory_reduced <= 2) && (rowdata.f_added <= 1)) || // Mash or boil
-          ((dataRecord.inventory_reduced <= 3) && (rowdata.f_added == 2)) || // Primary
-          ((dataRecord.inventory_reduced <= 5) && (rowdata.f_added == 3)) || // Secondary or Tertiary
-          ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 4)) || // Bottle
-          ((dataRecord.inventory_reduced <= 6) && (rowdata.f_added == 5))) { // Kegs
+      if (block_fermentable(dataRecord.inventory_reduced, rowdata.f_added) == false) {
        if (value < rowdata.f_amount)
         color = '#ff4040';
        return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + fermentableAdapter.formatNumber(value, 'f3') + '</span>';
@@ -878,7 +979,7 @@
       fermentableData = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
       if (fermentableData.f_added >= 4) {
        alert('Wijzig dit in de Verpakken tab');
-      } else if ((dataRecord.stage >= 3 && fermentableData.f_added <= 1) || (dataRecord.stage >= 4 && fermentableData.f_added <= 2) || (dataRecord.stage >= 6 && fermentableData.f_added <= 3)) {
+      } else if (block_fermentable(dataRecord.stage, fermentableData.f_added)) {
        alert('Ingredieënt is al verwerkt.');
       } else {
        $('#wf_name').val(fermentableData.f_name);
@@ -887,9 +988,9 @@
        $('#wf_max_in_batch').val(fermentableData.f_max_in_batch);
        $('#wf_adjust_to_total_100').val(fermentableData.f_adjust_to_total_100);
        $('#wf_added').val(fermentableData.f_added);
-       (dataRecord.stage >= 3) ? $('#wf_added').jqxDropDownList('disableAt', 0) : $('#wf_added').jqxDropDownList('enableAt', 0);
-       (dataRecord.stage >= 3) ? $('#wf_added').jqxDropDownList('disableAt', 1) : $('#wf_added').jqxDropDownList('enableAt', 1);
-       (dataRecord.stage >= 4) ? $('#wf_added').jqxDropDownList('disableAt', 2) : $('#wf_added').jqxDropDownList('enableAt', 2);
+       drop_endis(dataRecord.stage >= 3, '#wf_added', 0);
+       drop_endis(dataRecord.stage >= 3, '#wf_added', 1);
+       drop_endis(dataRecord.stage >= 4, '#wf_added', 2);
        $('#wf_added').jqxDropDownList('disableAt', 4);
        $('#wf_added').jqxDropDownList('disableAt', 5);
        // show the popup window.
@@ -954,7 +1055,7 @@
      theme: theme,
      template: 'primary',
      source: hoplist,
-     disabled: (dataRecord.stage > 3),
+     disabled: (dataRecord.stage > 5),
      displayMember: 'name',
      width: 150,
      height: 27,
@@ -987,25 +1088,32 @@
       row['h_myrcene'] = datarecord.myrcene;
       row['h_total_oil'] = datarecord.total_oil;
       row['h_inventory'] = datarecord.inventory;
+      /* If stage > useat moment, adjust the moment */
+      row['h_useat'] = minimum_hop(dataRecord.stage, row['h_useat']);
       $('#hopGrid').jqxGrid('addrow', null, row);
      }
      $('#haddrowbutton').jqxDropDownList('clearSelection');
     });
 
-    $('#hinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#hinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 5) });
     $('#hinstockbutton').on('change', function(event) {
      hopinstock = event.args.checked;
      hoplist.dataBind();
     });
 
     // delete selected hop.
-    $('#hdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#hdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 5) });
     $('#hdeleterowbutton').on('click', function() {
      var rowscount, id, selectedrowindex = $('#hopGrid').jqxGrid('getselectedrowindex');
      rowscount = $('#hopGrid').jqxGrid('getdatainformation').rowscount;
      if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-      id = $('#hopGrid').jqxGrid('getrowid', selectedrowindex);
-      $('#hopGrid').jqxGrid('deleterow', id);
+      useat = $('#hopGrid').jqxGrid('getcellvalue', selectedrowindex, 'h_useat');
+      if (block_hop(dataRecord.stage, useat)) {
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       id = $('#hopGrid').jqxGrid('getrowid', selectedrowindex);
+       $('#hopGrid').jqxGrid('deleterow', id);
+      }
      }
      calcIBUs();
     });
@@ -1061,8 +1169,7 @@
     },
     { text: 'Voorraad', datafield: 'h_inventory', width: 110, align: 'right',
      cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
-      if (((dataRecord.inventory_reduced <= 2) && (rowdata.h_useat <= 4)) || // Mash, FW, Boil, Aroma, Whirlpool
-          ((dataRecord.inventory_reduced <= 6) && (rowdata.h_useat == 5))) { // Dry hop
+      if (block_hop(dataRecord.inventory_reduced, rowdata.h_useat) == false) {
        var amount, color = '#ffffff';
        if (value < rowdata.h_amount)
         color = '#ff4040';
@@ -1079,12 +1186,12 @@
      cellsrenderer: function() {
       return 'Wijzig';
      }, buttonclick: function(row) {
-      if (dataRecord.stage > 3) {
+      hopRow = row;
+      hopData = $('#hopGrid').jqxGrid('getrowdata', hopRow);
+      if (block_hop(dataRecord.stage, hopData.h_useat)) {
        alert('Ingredieënt is al verwerkt.');
       } else {
        console.log('edit button row ' + row);
-       hopRow = row;
-       hopData = $('#hopGrid').jqxGrid('getrowdata', hopRow);
        $('#wh_name').val(hopData.h_name);
        $('#wh_amount').val(hopData.h_amount * 1000);
        var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg, parseFloat($('#batch_size').jqxNumberInput('decimal')),
@@ -1096,6 +1203,9 @@
        else
         $('#wh_time').val(hopData.h_time);
        $('#wh_useat').val(hopData.h_useat);
+       for (i = 0; i < 5; i++) {
+	drop_endis(dataRecord.stage > 2, '#wh_useat', i);
+       }
        // show the popup window.
        $('#popupHop').jqxWindow('open');
       }
@@ -1217,7 +1327,7 @@
      theme: theme,
      template: 'primary',
      source: misclist,
-     disabled: (dataRecord.stage > 3),
+     disabled: (dataRecord.stage > 6),
      displayMember: 'name',
      width: 150,
      height: 27,
@@ -1232,25 +1342,30 @@
       row['m_amount'] = 0;
       row['m_cost'] = datarecord.cost;
       row['m_type'] = datarecord.type;
-      row['m_use_use'] = datarecord.use_use;
+      row['m_use_use'] = minimum_misc(dataRecord.stage, datarecord.use_use);
       row['m_time'] = 0;
       row['m_amount_is_weight'] = datarecord.amount_is_weight;
       row['m_inventory'] = datarecord.inventory;
       $('#miscGrid').jqxGrid('addrow', null, row);
      }
     });
-    $('#minstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#minstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 6) });
     $('#minstockbutton').on('change', function(event) {
      miscinstock = event.args.checked;
      misclist.dataBind();
     });
     // delete selected misc.
-    $('#mdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#mdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 6) });
     $('#mdeleterowbutton').on('click', function() {
      var rowscount, type, id, selectedrowindex = $('#miscGrid').jqxGrid('getselectedrowindex');
      rowscount = $('#miscGrid').jqxGrid('getdatainformation').rowscount;
      type = $('#miscGrid').jqxGrid('getcellvalue', selectedrowindex, 'm_type');
-     if (selectedrowindex >= 0 && selectedrowindex < rowscount && type != 4) { // Water agent
+     use_use = $('#miscGrid').jqxGrid('getcellvalue', selectedrowindex, 'm_use_use');
+     if (selectedrowindex >= 0 && selectedrowindex < rowscount && type == 4) {
+      alert('Brouwzouten verwijderen in de water tab.');
+     } else if (block_misc(dataRecord.stage, use_use)) {
+      alert('Ingredieënt is al verwerkt.');
+     } else {
       id = $('#miscGrid').jqxGrid('getrowid', selectedrowindex);
       $('#miscGrid').jqxGrid('deleterow', id);
      }
@@ -1288,10 +1403,7 @@
     { text: 'Voorraad', datafield: 'm_inventory', width: 110, align: 'right',
      cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
       var vstr, color, amount;
-      if (((dataRecord.inventory_reduced <= 2) && (rowdata.m_use_use <= 2)) ||  // Starter, Mash, Boil
-          ((dataRecord.inventory_reduced <= 3) && (rowdata.m_use_use == 3)) ||  // Primary
-          ((dataRecord.inventory_reduced <= 5) && (rowdata.m_use_use == 4)) ||  // Secondary, Teriary
-          ((dataRecord.inventory_reduced <= 6) && (rowdata.m_use_use == 5))) {  // Bottle
+      if (block_misc(dataRecord.inventory_reduced, rowdata.m_use_use) == false) {
        vstr = rowdata.m_amount_is_weight ? 'gr' : 'ml';
        color = '#ffffff';
        if (value < rowdata.m_amount)
@@ -1309,7 +1421,7 @@
      }, buttonclick: function(row) {
       miscRow = row;
       miscData = $('#miscGrid').jqxGrid('getrowdata', miscRow);
-      if (dataRecord.stage > 3) {
+      if (block_misc(dataRecord.stage, miscData.m_use_use)) {
        alert('Ingredieënt is al verwerkt.');
       } else if (miscData.m_type == 4) {
        alert('Brouwzouten wijzigen in de water tab.');
@@ -1326,6 +1438,11 @@
        else
         $('#wm_time').val(miscData.m_time);
        $('#wm_use_use').val(miscData.m_use_use);
+       drop_endis(dataRecord.stage >= 2, '#wm_use_use', 0);
+       drop_endis(dataRecord.stage >= 3, '#wm_use_use', 1);
+       drop_endis(dataRecord.stage >= 3, '#wm_use_use', 2);
+       drop_endis(dataRecord.stage >= 4, '#wm_use_use', 3);
+       drop_endis(dataRecord.stage >= 5, '#wm_use_use', 4);
        // show the popup window.
        $('#popupMisc').jqxWindow('open');
       }
@@ -1396,7 +1513,7 @@
      placeHolder: 'Kies gist:',
      theme: theme,
      source: yeastlist,
-     disabled: (dataRecord.stage > 3),
+     disabled: (dataRecord.stage > 6),
      template: 'primary',
      displayMember: 'name',
      width: 150,
@@ -1419,7 +1536,7 @@
       row['y_form'] = datarecord.form;
       row['y_amount'] = 0;
       row['y_cost'] = datarecord.cost;
-      row['y_use'] = 0;
+      row['y_use'] = minimum_yeast(dataRecord.stage, 0);
       row['y_min_temperature'] = datarecord.min_temperature;
       row['y_max_temperature'] = datarecord.max_temperature;
       row['y_attenuation'] = datarecord.attenuation;
@@ -1444,21 +1561,26 @@
      calcYeast();
      $('#yaddrowbutton').jqxDropDownList('clearSelection');
     });
-    $('#yinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
+    $('#yinstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 6) });
     $('#yinstockbutton').on('change', function(event) {
      yeastinstock = event.args.checked;
      yeastlist.dataBind();
     });
     // delete selected yeast.
-    $('#ydeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 3) });
+    $('#ydeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 6) });
     $('#ydeleterowbutton').on('click', function() {
      var id, rowscount, selectedrowindex = $('#yeastGrid').jqxGrid('getselectedrowindex');
      rowscount = $('#yeastGrid').jqxGrid('getdatainformation').rowscount;
      if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
-      id = $('#yeastGrid').jqxGrid('getrowid', selectedrowindex);
-      $('#yeastGrid').jqxGrid('deleterow', id);
-      calcViability();
-      calcYeast();
+      use = $('#yeastGrid').jqxGrid('getcellvalue', selectedrowindex, 'y_use');
+      if (block_yeast(dataRecord.stage, use)) {
+       alert('Ingredieënt is al verwerkt.');
+      } else {
+       id = $('#yeastGrid').jqxGrid('getrowid', selectedrowindex);
+       $('#yeastGrid').jqxGrid('deleterow', id);
+       calcViability();
+       calcYeast();
+      }
      }
     });
    },
@@ -1504,10 +1626,7 @@
     { text: 'Voorraad', datafield: 'y_inventory', width: 90, align: 'right',
      cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
       var color, amount;
-      if (((dataRecord.inventory_reduced <= 3) && (rowdata.y_use == 0)) ||  // Primary
-          ((dataRecord.inventory_reduced <= 4) && (rowdata.y_use == 1)) ||  // Secondary
-          ((dataRecord.inventory_reduced <= 5) && (rowdata.y_use == 2)) ||  // Tertiary
-          ((dataRecord.inventory_reduced <= 6) && (rowdata.y_use == 3))) {  // Bottle
+      if (block_yeast(dataRecord.inventory_reduced, rowdata.y_use) == false) {
        color = '#ffffff';
        if (value < rowdata.y_amount)
         color = '#ff4040';
@@ -1528,10 +1647,7 @@
      }, buttonclick: function(row) {
       yeastRow = row;
       yeastData = $('#yeastGrid').jqxGrid('getrowdata', yeastRow);
-      if ((dataRecord.stage > 3 && yeastData.y_use == 0) ||
-          (dataRecord.stage > 4 && yeastData.y_use == 1) ||
-          (dataRecord.stage > 5 && yeastData.y_use == 2) ||
-          (dataRecord.stage > 6 && yeastData.y_use == 3)) {
+      if (block_yeast(dataRecord.stage, yeastData.y_use)) {
        alert('Ingredieënt is al verwerkt.');
       } else {
        if (yeastData.y_form == 0) {
@@ -1551,6 +1667,9 @@
        $('#wy_laboratory').val(yeastData.y_laboratory);
        $('#wy_product_id').val(yeastData.y_product_id);
        $('#wy_use').val(yeastData.y_use);
+       drop_endis(dataRecord.stage > 3, '#wy_use', 0);
+       drop_endis(dataRecord.stage > 4, '#wy_use', 1);
+       drop_endis(dataRecord.stage > 5, '#wy_use', 2);
        // show the popup window.
        $('#popupYeast').jqxWindow('open');
       }

mercurial