www/js/prod_edit.js

changeset 820
16ae12aa872e
parent 819
d759d9ed357e
child 821
293ec25995db
equal deleted inserted replaced
819:d759d9ed357e 820:16ae12aa872e
43 resizable: false, 43 resizable: false,
44 isModal: true, 44 isModal: true,
45 modalOpacity: 0.4, 45 modalOpacity: 0.4,
46 autoOpen: false, 46 autoOpen: false,
47 cancelButton: $('#pitchrateReady') 47 cancelButton: $('#pitchrateReady')
48 });
49
50 $('#popupFermentable').jqxWindow({
51 width: 800,
52 height: 300,
53 position: { x: 230, y: 100 },
54 resizable: false,
55 theme: theme,
56 isModal: true,
57 autoOpen: false,
58 cancelButton: $('#FermentableReady'),
59 modalOpacity: 0.40
60 }); 48 });
61 49
62 $('#popupHop').jqxWindow({ 50 $('#popupHop').jqxWindow({
63 width: 800, 51 width: 800,
64 height: 300, 52 height: 300,
771 { name: 'f_di_ph', type: 'float' }, 759 { name: 'f_di_ph', type: 'float' },
772 { name: 'f_acid_to_ph_57', type: 'float' }, 760 { name: 'f_acid_to_ph_57', type: 'float' },
773 { name: 'f_inventory', type: 'float' }, 761 { name: 'f_inventory', type: 'float' },
774 { name: 'f_avail', type: 'int' } 762 { name: 'f_avail', type: 'int' }
775 ], 763 ],
776 addrow: function(rowid, rowdata, position, commit) { commit(true); },
777 deleterow: function(rowid, commit) { commit(true); },
778 updaterow: function(rowid, rowdata, commit) { commit(true); }
779 }, 764 },
780 fermentableAdapter = new $.jqx.dataAdapter(fermentableSource); 765 fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
781 766
782 $('#fermentableGrid').jqxGrid({ 767 $('#fermentableGrid').jqxGrid({
783 width: 1240, 768 width: 1240,
784 height: 470, 769 height: 470,
785 source: fermentableAdapter, 770 source: fermentableAdapter,
786 theme: theme, 771 theme: theme,
787 selectionmode: 'singlerow', 772 editable: false,
788 showtoolbar: true,
789 rendertoolbar: function(toolbar) {
790 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
791 toolbar.append(container);
792 container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
793 container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
794 container.append('<div style="float: left; margin-left: 10px;" id="finstockbutton"></div>');
795 container.append('<input style="float: left; margin-left: 400px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
796 // add fermentable from dropdownlist.
797 $('#faddrowbutton').jqxDropDownList({
798 placeHolder: 'Kies mout:',
799 theme: theme,
800 template: 'primary',
801 source: fermentablelist,
802 displayMember: 'name',
803 disabled: (dataRecord.stage > 6),
804 width: 150,
805 height: 27,
806 dropDownWidth: 500,
807 dropDownHeight: 500,
808 renderer: function(index, label, value) {
809 var datarecord = fermentablelist.records[index];
810 return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC) (' + Round(datarecord.inventory, 3) + ' kg)';
811 }
812 });
813 $('#faddrowbutton').on('select', function(event) {
814 if (event.args) {
815 var index, datarecord, row = {}, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
816 index = event.args.index;
817 datarecord = fermentablelist.records[index];
818 row['f_name'] = datarecord.name;
819 row['f_origin'] = datarecord.origin;
820 row['f_supplier'] = datarecord.supplier;
821 row['f_amount'] = 0;
822 row['f_cost'] = datarecord.cost;
823 row['f_type'] = datarecord.type;
824 row['f_yield'] = datarecord.yield;
825 row['f_color'] = datarecord.color;
826 row['f_coarse_fine_diff'] = datarecord.coarse_fine_diff;
827 row['f_moisture'] = datarecord.moisture;
828 row['f_diastatic_power'] = datarecord.diastatic_power;
829 row['f_protein'] = datarecord.protein;
830 row['f_max_in_batch'] = datarecord.max_in_batch;
831 row['f_graintype'] = datarecord.graintype;
832 if (datarecord.add_after_boil) {
833 row['f_added'] = 2; // Fermentation
834 } else if ((datarecord.type == 1) || (datarecord.type == 4)) { // Sugar or Adjunct
835 row['f_added'] = 1; // Boil
836 } else {
837 row['f_added'] = 0; // Mash
838 }
839 /* If stage > added moment, adjust the moment */
840 row['f_added'] = minimum_fermentable(dataRecord.stage, row['f_added']);
841 row['f_dissolved_protein'] = datarecord.dissolved_protein;
842 row['f_recommend_mash'] = datarecord.recommend_mash;
843 row['f_add_after_boil'] = datarecord.add_after_boil;
844 if (rowscount == 0) {
845 // The first fermentable
846 row['f_adjust_to_total_100'] = 1;
847 row['f_percentage'] = 100;
848 } else {
849 row['f_adjust_to_total_100'] = 0;
850 row['f_percentage'] = 0;
851 }
852 row['f_di_ph'] = datarecord.di_ph;
853 row['f_acid_to_ph_57'] = datarecord.acid_to_ph_57;
854 row['f_inventory'] = datarecord.inventory;
855 $('#fermentableGrid').jqxGrid('addrow', null, row);
856 }
857 });
858
859 $('#finstockbutton').jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 6) });
860 $('#finstockbutton').on('change', function(event) {
861 fermentableinstock = event.args.checked;
862 fermentablelist.dataBind();
863 });
864
865 // delete selected fermentable.
866 $('#fdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150, disabled: (dataRecord.stage > 6) });
867 $('#fdeleterowbutton').on('click', function() {
868 var rowscount, id, percent, amount, i, rowdata,
869 selectedrowindex = $('#fermentableGrid').jqxGrid('getselectedrowindex');
870 rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
871 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
872 id = $('#fermentableGrid').jqxGrid('getrowid', selectedrowindex);
873 added = $('#fermentableGrid').jqxGrid('getcellvalue', selectedrowindex, 'f_added');
874 if (block_fermentable(dataRecord.stage, added)) {
875 percent = mount = 0;
876 alert('Ingredieënt is al verwerkt.');
877 } else {
878 percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_percentage');
879 amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, 'f_amount');
880 $('#fermentableGrid').jqxGrid('deleterow', id);
881 }
882 }
883 rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
884 if (rowscount > 1) {
885 if (to_100) {
886 for (i = 0; i < rowscount; i++) {
887 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
888 if (rowdata.f_adjust_to_total_100) {
889 rowdata.f_percentage += percent;
890 rowdata.f_amount += amount;
891 }
892 }
893 } else {
894 calcPercentages();
895 }
896 } else {
897 $('#fermentableGrid').jqxGrid('setcellvalue', 0, 'f_percentage', 100);
898 }
899 calcFermentables();
900 calcIBUs();
901 });
902 },
903 ready: function() { calcFermentables(); $('#jqxTabs').jqxTabs('next'); }, 773 ready: function() { calcFermentables(); $('#jqxTabs').jqxTabs('next'); },
904 columns: [ 774 columns: [
905 { text: 'Vergistbaar ingredi&euml;nt', datafield: 'f_name', 775 { text: 'Vergistbaar ingredi&euml;nt', datafield: 'f_name' },
776 { text: 'Leverancier', datafield: 'f_supplier', width: 180 },
777 { text: 'Kleur', datafield: 'f_color', width: 90, align: 'right',
906 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 778 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
907 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + rowdata.f_supplier + ' / ' + 779 return '<span style="margin: 4px; margin-top: 6px; float: right;">' + dataAdapter.formatNumber(value, 'f0') + ' EBC</span>';
908 rowdata.f_name + ' (' + rowdata.f_color + ' EBC)</span>';
909 } 780 }
910 }, 781 },
911 { text: 'Type', width: 100, datafield: 'f_type', 782 { text: 'Type', width: 100, datafield: 'f_type',
912 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 783 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
913 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + FermentableTypeData[value].nl + '</span>'; 784 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + FermentableTypeData[value].nl + '</span>';
918 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + AddedData[value].nl + '</span>'; 789 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + AddedData[value].nl + '</span>';
919 } 790 }
920 }, 791 },
921 { text: 'Maxinbatch', datafield: 'f_max_in_batch', hidden: true }, 792 { text: 'Maxinbatch', datafield: 'f_max_in_batch', hidden: true },
922 { text: 'Opbrengst', datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, 793 { text: 'Opbrengst', datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
923 { text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3' }, 794 { text: 'Gewicht Kg', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3' },
924 { text: 'Voorraad Kg', datafield: 'f_inventory', width: 120, align: 'right', 795 { text: 'Voorraad Kg', datafield: 'f_inventory', width: 110, align: 'right',
925 cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) { 796 cellsrenderer: function(row, columnfield, value, defaulthtml, columnproperties, rowdata) {
926 var color = (value < rowdata.f_amount) ? '#ff4040':'#ffffff'; 797 var color = (value < rowdata.f_amount) ? '#ff4040':'#ffffff';
927 if (block_fermentable(dataRecord.inventory_reduced, rowdata.f_added) == false) { 798 if (block_fermentable(dataRecord.inventory_reduced, rowdata.f_added) == false) {
928 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + fermentableAdapter.formatNumber(value, 'f3') + '</span>'; 799 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + fermentableAdapter.formatNumber(value, 'f3') + '</span>';
929 } else { 800 } else {
942 { text: '100%', datafield: 'f_adjust_to_total_100', width: 70, align: 'center', cellsalign: 'center', 813 { text: '100%', datafield: 'f_adjust_to_total_100', width: 70, align: 'center', cellsalign: 'center',
943 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 814 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
944 if (value == 0) 815 if (value == 0)
945 return '<span></span>'; 816 return '<span></span>';
946 return '<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>'; 817 return '<span><img style="float:left; margin-left:25px; margin-top:4px;" src="images/dialog-ok-apply.png"></span>';
947 }
948 },
949 { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center',
950 cellsrenderer: function() {
951 return 'Wijzig';
952 }, buttonclick: function(row) {
953 fermentableRow = row;
954 fermentableData = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
955 if (fermentableData.f_added >= 4) {
956 alert('Wijzig dit in de Verpakken tab');
957 } else if (block_fermentable(dataRecord.stage, fermentableData.f_added)) {
958 alert('Ingredieënt is al verwerkt.');
959 } else {
960 $('#wf_name').val(fermentableData.f_name);
961 $('#wf_amount').val(fermentableData.f_amount);
962 $('#wf_percentage').val(fermentableData.f_percentage);
963 $('#wf_max_in_batch').val(fermentableData.f_max_in_batch);
964 $('#wf_adjust_to_total_100').val(fermentableData.f_adjust_to_total_100);
965 $('#wf_added').val(fermentableData.f_added);
966 drop_endis(dataRecord.stage >= 3, '#wf_added', 0);
967 drop_endis(dataRecord.stage >= 3, '#wf_added', 1);
968 drop_endis(dataRecord.stage >= 4, '#wf_added', 2);
969 $('#wf_added').jqxDropDownList('disableAt', 4);
970 $('#wf_added').jqxDropDownList('disableAt', 5);
971 // show the popup window.
972 $('#popupFermentable').jqxWindow('open');
973 }
974 } 818 }
975 } 819 }
976 ] 820 ]
977 }); 821 });
978 }; 822 };
4478 calcFermentables(); 4322 calcFermentables();
4479 calcIBUs(); 4323 calcIBUs();
4480 calcMash(); 4324 calcMash();
4481 // Waters: yes there is impact. 4325 // Waters: yes there is impact.
4482 }); 4326 });
4483 $('#wf_name').jqxInput({ theme: theme, width: 320, height: 23 });
4484 $('#wf_instock').jqxCheckBox({ theme: theme, height: 23 });
4485 $('#wf_instock').on('change', function(event) {
4486 fermentableinstock = event.args.checked;
4487 fermentablelist.dataBind();
4488 });
4489 $('#wf_select').jqxDropDownList({
4490 placeHolder: 'Kies mout:',
4491 theme: theme,
4492 source: fermentablelist,
4493 displayMember: 'name',
4494 width: 150,
4495 height: 23,
4496 dropDownWidth: 500,
4497 dropDownHeight: 500,
4498 renderer: function(index, label, value) {
4499 var datarecord = fermentablelist.records[index];
4500 return datarecord.supplier + ' / ' + datarecord.name + ' (' + datarecord.color + ' EBC)';
4501 }
4502 });
4503 $('#wf_select').on('select', function(event) {
4504 if (event.args) {
4505 var datarecord, index = event.args.index;
4506 datarecord = fermentablelist.records[index];
4507 $('#wf_name').val(datarecord.name);
4508 fermentableData.f_name = datarecord.name;
4509 fermentableData.f_origin = datarecord.origin;
4510 fermentableData.f_supplier = datarecord.supplier;
4511 fermentableData.f_type = datarecord.type;
4512 fermentableData.f_cost = datarecord.cost;
4513 fermentableData.f_yield = datarecord.yield;
4514 fermentableData.f_color = datarecord.color;
4515 fermentableData.f_coarse_fine_diff = datarecord.coarse_fine_diff;
4516 fermentableData.f_moisture = datarecord.moisture;
4517 fermentableData.f_diastatic_power = datarecord.diastatic_power;
4518 fermentableData.f_protein = datarecord.protein;
4519 fermentableData.f_max_in_batch = datarecord.max_in_batch;
4520 fermentableData.f_graintype = datarecord.graintype;
4521 fermentableData.f_dissolved_protein = datarecord.dissolved_protein;
4522 fermentableData.f_recommend_mash = datarecord.recommend_mash;
4523 fermentableData.f_add_after_boil = datarecord.add_after_boil;
4524 fermentableData.f_di_ph = datarecord.di_ph;
4525 fermentableData.f_acid_to_ph_57 = datarecord.acid_to_ph_57;
4526 fermentableData.f_inventory = datarecord.inventory;
4527 }
4528 });
4529 $('#wf_amount').jqxNumberInput(Spin3dec);
4530 $('#wf_amount').on('change', function(event) {
4531 console.log('amount changed: ' + event.args.value);
4532 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', event.args.value);
4533 fermentableData.f_amount = event.args.value;
4534 if (! to_100) {
4535 calcPercentages();
4536 calcFermentables();
4537 calcIBUs();
4538 calcMash();
4539 }
4540 });
4541 $('#wf_percentage').jqxNumberInput(Perc1dec);
4542 $('#wf_percentage').on('change', function(event) {
4543 var newvalue, rowscount, rowdata, diff, tw, damount, namount, nw, newperc,
4544 oldvalue = Math.round(fermentableData.f_percentage * 10) / 10.0;
4545 newvalue = event.args.value;
4546 console.log('percentage changed: ' + newvalue + ' old: ' + oldvalue);
4547 fermentableData.f_percent = newvalue;
4548 rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
4549 if ((oldvalue != newvalue) && (rowscount > 1)) {
4550 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
4551 if (rowdata.f_adjust_to_total_100) {
4552 $('#wf_percentage').val(oldvalue);
4553 } else {
4554 diff = newvalue - oldvalue;
4555 tw = 0; // total weight
4556 for (i = 0; i < rowscount; i++) {
4557 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
4558 if (rowdata.f_added < 4)
4559 tw += Math.round(rowdata.f_amount * 1000) / 1000;
4560 }
4561 tw = Math.round(tw * 1000) / 1000;
4562 if (to_100) {
4563 // Adjust this row and the 100% row.
4564 damount = Math.round(tw * diff * 10) / 1000;
4565 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', fermentableRow);
4566 namount = Round(rowdata.f_amount + damount, 3);
4567 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_amount', namount);
4568 $('#wf_amount').val(namount);
4569 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_percentage', rowdata.f_percentage + diff);
4570 for (i = 0; i < rowscount; i++) {
4571 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
4572 if (rowdata.f_adjust_to_total_100) {
4573 namount = rowdata.f_amount - damount;
4574 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', rowdata.f_percentage - diff);
4575 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
4576 }
4577 }
4578 calcFermentables();
4579 calcIBUs();
4580 calcMash();
4581 } else {
4582 // Adjust all the rows.
4583 nw = tw * diff / 100;
4584 for (i = 0; i < rowscount; i++) {
4585 rowdata = $('#fermentableGrid').jqxGrid('getrowdata', i);
4586 if (rowdata.f_added < 4) {
4587 if (i == fermentableRow) {
4588 namount = Math.round((rowdata.f_amount + nw) * 1000) / 1000;
4589 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
4590 // $('#wf_amount').val(namount); // Will crash the script.
4591 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newvalue);
4592 } else {
4593 namount = Math.round((rowdata.f_amount - (nw / (rowscount - 1))) * 1000) / 1000;
4594 newperc = Math.round((namount / tw) * 1000) / 10.0;
4595 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_amount', namount);
4596 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', newperc);
4597 }
4598 } else {
4599 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_percentage', 0);
4600 }
4601 }
4602 calcFermentables();
4603 calcIBUs();
4604 calcMash();
4605 }
4606 }
4607 }
4608 });
4609 $('#wf_max_in_batch').jqxNumberInput(Show1dec);
4610 $('#wf_adjust_to_total_100').jqxCheckBox({ theme: theme, width: 120, height: 23 });
4611 $('#wf_adjust_to_total_100').on('checked', function(event) {
4612 if (fermentableData.f_adjust_to_total_100 == 0) {
4613 if (to_100) {
4614 // Reset other flag first.
4615 var i, rowscount = $('#fermentableGrid').jqxGrid('getdatainformation').rowscount;
4616 for (i = 0; i < rowscount; i++) {
4617 if (i != fermentableRow) {
4618 $('#fermentableGrid').jqxGrid('setcellvalue', i, 'f_adjust_to_total_100', 0);
4619 }
4620 }
4621 }
4622 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 1);
4623 calcFermentables();
4624 }
4625 });
4626 $('#wf_adjust_to_total_100').on('unchecked', function(event) {
4627 if (fermentableData.f_adjust_to_total_100 != 0) {
4628 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_adjust_to_total_100', 0);
4629 calcFermentables();
4630 }
4631 });
4632 $('#wf_added').jqxDropDownList({
4633 theme: theme,
4634 source: AddedAdapter,
4635 valueMember: 'id',
4636 displayMember: 'nl',
4637 width: 180,
4638 height: 23,
4639 autoDropDownHeight: true,
4640 dropDownVerticalAlignment: 'top'
4641 });
4642 $('#wf_added').on('select', function(event) {
4643 if (event.args) {
4644 var index = event.args.index;
4645 $('#fermentableGrid').jqxGrid('setcellvalue', fermentableRow, 'f_added', index);
4646 calcFermentables();
4647 calcIBUs();
4648 calcMash();
4649 }
4650 });
4651 4327
4652 // Tab 4, Hops 4328 // Tab 4, Hops
4653 $('#est_ibu2').jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' }); 4329 $('#est_ibu2').jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
4654 $('#est_ibu2').jqxNumberInput(Smal0dec); 4330 $('#est_ibu2').jqxNumberInput(Smal0dec);
4655 $('#hop_flavour').jqxProgressBar({ 4331 $('#hop_flavour').jqxProgressBar({

mercurial