# HG changeset patch # User Michiel Broek # Date 1659703277 -7200 # Node ID 16ae12aa872ecb1057cf06959a0cd8cd2298c93b # Parent d759d9ed357e19f5477b46d0d8bc891e9a2584d7 Tab 3 is a viewer. diff -r d759d9ed357e -r 16ae12aa872e www/js/prod_edit.js --- a/www/js/prod_edit.js Fri Aug 05 14:24:29 2022 +0200 +++ b/www/js/prod_edit.js Fri Aug 05 14:41:17 2022 +0200 @@ -47,18 +47,6 @@ cancelButton: $('#pitchrateReady') }); - $('#popupFermentable').jqxWindow({ - width: 800, - height: 300, - position: { x: 230, y: 100 }, - resizable: false, - theme: theme, - isModal: true, - autoOpen: false, - cancelButton: $('#FermentableReady'), - modalOpacity: 0.40 - }); - $('#popupHop').jqxWindow({ width: 800, height: 300, @@ -773,9 +761,6 @@ { name: 'f_inventory', type: 'float' }, { name: 'f_avail', type: 'int' } ], - addrow: function(rowid, rowdata, position, commit) { commit(true); }, - deleterow: function(rowid, commit) { commit(true); }, - updaterow: function(rowid, rowdata, commit) { commit(true); } }, fermentableAdapter = new $.jqx.dataAdapter(fermentableSource); @@ -784,128 +769,14 @@ height: 470, source: fermentableAdapter, theme: theme, - selectionmode: 'singlerow', - showtoolbar: true, - rendertoolbar: function(toolbar) { - var container = $("
"); - toolbar.append(container); - container.append('
'); - container.append('
In voorraad:
'); - container.append('
'); - container.append(''); - // add fermentable from dropdownlist. - $('#faddrowbutton').jqxDropDownList({ - placeHolder: 'Kies mout:', - theme: theme, - template: 'primary', - source: fermentablelist, - displayMember: 'name', - disabled: (dataRecord.stage > 6), - width: 150, - height: 27, - dropDownWidth: 500, - dropDownHeight: 500, - renderer: function(index, label, value) { - var datarecord = fermentablelist.records[index]; - return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC) (' + Round(datarecord.inventory, 3) + ' kg)'; - } - }); - $('#faddrowbutton').on('select', function(event) { - if (event.args) { - var index, datarecord, row = {}, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount; - index = event.args.index; - datarecord = fermentablelist.records[index]; - row['f_name'] = datarecord.name; - row['f_origin'] = datarecord.origin; - row['f_supplier'] = datarecord.supplier; - row['f_amount'] = 0; - row['f_cost'] = datarecord.cost; - row['f_type'] = datarecord.type; - row['f_yield'] = datarecord.yield; - row['f_color'] = datarecord.color; - row['f_coarse_fine_diff'] = datarecord.coarse_fine_diff; - row['f_moisture'] = datarecord.moisture; - row['f_diastatic_power'] = datarecord.diastatic_power; - row['f_protein'] = datarecord.protein; - row['f_max_in_batch'] = datarecord.max_in_batch; - row['f_graintype'] = datarecord.graintype; - if (datarecord.add_after_boil) { - row['f_added'] = 2; // Fermentation - } else if ((datarecord.type == 1) || (datarecord.type == 4)) { // Sugar or Adjunct - row['f_added'] = 1; // Boil - } else { - row['f_added'] = 0; // Mash - } - /* If stage > added moment, adjust the moment */ - 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; - if (rowscount == 0) { - // The first fermentable - row['f_adjust_to_total_100'] = 1; - row['f_percentage'] = 100; - } else { - row['f_adjust_to_total_100'] = 0; - row['f_percentage'] = 0; - } - row['f_di_ph'] = datarecord.di_ph; - row['f_acid_to_ph_57'] = datarecord.acid_to_ph_57; - row['f_inventory'] = datarecord.inventory; - $('#fermentableGrid').jqxGrid('addrow', null, row); - } - }); - - $('#finstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 6) }); - $('#finstockbutton').on('change', function(event) { - fermentableinstock = event.args.checked; - fermentablelist.dataBind(); - }); - - // delete selected fermentable. - $('#fdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 6) }); - $('#fdeleterowbutton').on('click', function() { - var rowscount, id, percent, amount, i, rowdata, - selectedrowindex = $('#fermentableGrid').jqxGrid('getselectedrowindex'); - rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount; - if (selectedrowindex >= 0 && selectedrowindex < rowscount) { - id = $('#fermentableGrid').jqxGrid('getrowid', selectedrowindex); - 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) { - if (to_100) { - for (i = 0; i < rowscount; i++) { - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i); - if (rowdata.f_adjust_to_total_100) { - rowdata.f_percentage += percent; - rowdata.f_amount += amount; - } - } - } else { - calcPercentages(); - } - } else { - $('#fermentableGrid').jqxGrid('setcellvalue', 0, 'f_percentage', 100); - } - calcFermentables(); - calcIBUs(); - }); - }, + editable: false, ready: function() { calcFermentables(); $('#jqxTabs').jqxTabs('next'); }, columns: [ - { text: 'Vergistbaar ingrediënt', datafield: 'f_name', + { text: 'Vergistbaar ingrediënt', datafield: 'f_name' }, + { text: 'Leverancier', datafield: 'f_supplier', width: 180 }, + { text: 'Kleur', datafield: 'f_color', width: 90, align: 'right', cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { - return '' + rowdata.f_supplier + ' / ' + - rowdata.f_name + ' (' + rowdata.f_color + ' EBC)'; + return '' + dataAdapter.formatNumber(value, 'f0') + ' EBC'; } }, { text: 'Type', width: 100, datafield: 'f_type', @@ -920,8 +791,8 @@ }, { text: 'Maxinbatch', datafield: 'f_max_in_batch', hidden: true }, { text: 'Opbrengst', datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, - { text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3' }, - { text: 'Voorraad Kg', datafield: 'f_inventory', width: 120, align: 'right', + { text: 'Gewicht Kg', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3' }, + { text: 'Voorraad Kg', datafield: 'f_inventory', width: 110, align: 'right', cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) { var color = (value < rowdata.f_amount) ? '#ff4040':'#ffffff'; if (block_fermentable(dataRecord.inventory_reduced, rowdata.f_added) == false) { @@ -945,33 +816,6 @@ return ''; return ''; } - }, - { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', - cellsrenderer: function() { - return 'Wijzig'; - }, buttonclick: function(row) { - fermentableRow = row; - fermentableData = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow); - if (fermentableData.f_added >= 4) { - alert('Wijzig dit in de Verpakken tab'); - } else if (block_fermentable(dataRecord.stage, fermentableData.f_added)) { - alert('Ingredieënt is al verwerkt.'); - } else { - $('#wf_name').val(fermentableData.f_name); - $('#wf_amount').val(fermentableData.f_amount); - $('#wf_percentage').val(fermentableData.f_percentage); - $('#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); - 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. - $('#popupFermentable').jqxWindow('open'); - } - } } ] }); @@ -4480,174 +4324,6 @@ calcMash(); // Waters: yes there is impact. }); - $('#wf_name').jqxInput({ theme: theme, width: 320, height: 23 }); - $('#wf_instock').jqxCheckBox({ theme: theme, height: 23 }); - $('#wf_instock').on('change', function(event) { - fermentableinstock = event.args.checked; - fermentablelist.dataBind(); - }); - $('#wf_select').jqxDropDownList({ - placeHolder: 'Kies mout:', - theme: theme, - source: fermentablelist, - displayMember: 'name', - width: 150, - height: 23, - dropDownWidth: 500, - dropDownHeight: 500, - renderer: function(index, label, value) { - var datarecord = fermentablelist.records[index]; - return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC)'; - } - }); - $('#wf_select').on('select', function(event) { - if (event.args) { - var datarecord, index = event.args.index; - datarecord = fermentablelist.records[index]; - $('#wf_name').val(datarecord.name); - fermentableData.f_name = datarecord.name; - fermentableData.f_origin = datarecord.origin; - fermentableData.f_supplier = datarecord.supplier; - fermentableData.f_type = datarecord.type; - fermentableData.f_cost = datarecord.cost; - fermentableData.f_yield = datarecord.yield; - fermentableData.f_color = datarecord.color; - fermentableData.f_coarse_fine_diff = datarecord.coarse_fine_diff; - fermentableData.f_moisture = datarecord.moisture; - fermentableData.f_diastatic_power = datarecord.diastatic_power; - fermentableData.f_protein = datarecord.protein; - fermentableData.f_max_in_batch = datarecord.max_in_batch; - fermentableData.f_graintype = datarecord.graintype; - fermentableData.f_dissolved_protein = datarecord.dissolved_protein; - fermentableData.f_recommend_mash = datarecord.recommend_mash; - fermentableData.f_add_after_boil = datarecord.add_after_boil; - fermentableData.f_di_ph = datarecord.di_ph; - fermentableData.f_acid_to_ph_57 = datarecord.acid_to_ph_57; - fermentableData.f_inventory = datarecord.inventory; - } - }); - $('#wf_amount').jqxNumberInput(Spin3dec); - $('#wf_amount').on('change', function(event) { - console.log('amount changed: ' + event.args.value); - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value); - fermentableData.f_amount = event.args.value; - if (! to_100) { - calcPercentages(); - calcFermentables(); - calcIBUs(); - calcMash(); - } - }); - $('#wf_percentage').jqxNumberInput(Perc1dec); - $('#wf_percentage').on('change', function(event) { - var newvalue, rowscount, rowdata, diff, tw, damount, namount, nw, newperc, - oldvalue = Math.round(fermentableData.f_percentage * 10) / 10.0; - newvalue = event.args.value; - console.log('percentage changed: ' + newvalue + ' old: ' + oldvalue); - fermentableData.f_percent = newvalue; - rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount; - if ((oldvalue != newvalue) && (rowscount > 1)) { - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow); - if (rowdata.f_adjust_to_total_100) { - $('#wf_percentage').val(oldvalue); - } else { - diff = newvalue - oldvalue; - tw = 0; // total weight - for (i = 0; i < rowscount; i++) { - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i); - if (rowdata.f_added < 4) - tw += Math.round(rowdata.f_amount * 1000) / 1000; - } - tw = Math.round(tw * 1000) / 1000; - if (to_100) { - // Adjust this row and the 100% row. - damount = Math.round(tw * diff * 10) / 1000; - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow); - namount = Round(rowdata.f_amount + damount, 3); - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount); - $('#wf_amount').val(namount); - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff); - for (i = 0; i < rowscount; i++) { - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i); - if (rowdata.f_adjust_to_total_100) { - namount = rowdata.f_amount - damount; - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', rowdata.f_percentage - diff); - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount); - } - } - calcFermentables(); - calcIBUs(); - calcMash(); - } else { - // Adjust all the rows. - nw = tw * diff / 100; - for (i = 0; i < rowscount; i++) { - rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i); - if (rowdata.f_added < 4) { - if (i == fermentableRow) { - namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000; - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount); - // $('#wf_amount').val(namount); // Will crash the script. - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newvalue); - } else { - namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000; - newperc = Math.round((namount / tw) * 1000) / 10.0; - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount); - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newperc); - } - } else { - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', 0); - } - } - calcFermentables(); - calcIBUs(); - calcMash(); - } - } - } - }); - $('#wf_max_in_batch').jqxNumberInput(Show1dec); - $('#wf_adjust_to_total_100').jqxCheckBox({ theme: theme, width: 120, height: 23 }); - $('#wf_adjust_to_total_100').on('checked', function(event) { - if (fermentableData.f_adjust_to_total_100 == 0) { - if (to_100) { - // Reset other flag first. - var i, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount; - for (i = 0; i < rowscount; i++) { - if (i != fermentableRow) { - $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_adjust_to_total_100', 0); - } - } - } - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 1); - calcFermentables(); - } - }); - $('#wf_adjust_to_total_100').on('unchecked', function(event) { - if (fermentableData.f_adjust_to_total_100 != 0) { - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 0); - calcFermentables(); - } - }); - $('#wf_added').jqxDropDownList({ - theme: theme, - source: AddedAdapter, - valueMember: 'id', - displayMember: 'nl', - width: 180, - height: 23, - autoDropDownHeight: true, - dropDownVerticalAlignment: 'top' - }); - $('#wf_added').on('select', function(event) { - if (event.args) { - var index = event.args.index; - $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_added', index); - calcFermentables(); - calcIBUs(); - calcMash(); - } - }); // Tab 4, Hops $('#est_ibu2').jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });