824 { name: 'h_hsi', type: 'float' }, |
824 { name: 'h_hsi', type: 'float' }, |
825 { name: 'h_humulene', type: 'float' }, |
825 { name: 'h_humulene', type: 'float' }, |
826 { name: 'h_carophyllene', type: 'float' }, |
826 { name: 'h_carophyllene', type: 'float' }, |
827 { name: 'h_cohumulone', type: 'float' }, |
827 { name: 'h_cohumulone', type: 'float' }, |
828 { name: 'h_myrcene', type: 'float' }, |
828 { name: 'h_myrcene', type: 'float' }, |
829 { name: 'h_total_oil', type: 'float' } |
829 { name: 'h_total_oil', type: 'float' }, |
|
830 { name: 'h_weight', type: 'float' } |
830 ], |
831 ], |
831 addrow: function (rowid, rowdata, position, commit) { |
832 addrow: function (rowid, rowdata, position, commit) { |
832 commit(true); |
833 commit(true); |
833 }, |
834 }, |
834 deleterow: function (rowid, commit) { |
835 deleterow: function (rowid, commit) { |
835 commit(true); |
836 commit(true); |
836 } |
837 } |
837 }; |
838 }; |
838 var hopAdapter = new $.jqx.dataAdapter(hopSource); |
839 var hopAdapter = new $.jqx.dataAdapter(hopSource, { |
|
840 beforeLoadComplete: function (records) { |
|
841 var data = new Array(); |
|
842 for (var i = 0; i < records.length; i++) { |
|
843 var row = records[i]; |
|
844 row.h_weight = row.h_amount * 1000; |
|
845 data.push(row); |
|
846 } |
|
847 return data; |
|
848 }, |
|
849 loadError: function(jqXHR, status, error) { |
|
850 $('#err').text(status + ' ' + error); |
|
851 }, |
|
852 }); |
839 // dropdownlist datasource from inventory_hops |
853 // dropdownlist datasource from inventory_hops |
840 var hopUrl = "gethopsources.php"; |
854 var hopUrl = "gethopsources.php"; |
841 var hopInvSource = { |
855 var hopInvSource = { |
842 datatype: "json", |
856 datatype: "json", |
843 datafields: [ |
857 datafields: [ |
935 columns: [ |
950 columns: [ |
936 { text: 'Hop', editable: false, datafield: 'h_name' }, |
951 { text: 'Hop', editable: false, datafield: 'h_name' }, |
937 { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' }, |
952 { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' }, |
938 { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' }, |
953 { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' }, |
939 { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, |
954 { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, |
940 // Edit the amount in grams, shoukd be fine for batches < 10 hl. |
955 { text: 'Amount', hidden: true, datafield: 'h_amount' }, |
941 { text: 'Gewicht gr', datafield: 'grams', width: 120, align: 'right', columntype: 'numberinput', cellsformat: 'f1', |
956 { text: 'Gewicht gr', datafield: 'h_weight', width: 120, align: 'right', cellsalign: 'right', |
|
957 columntype: 'numberinput', |
942 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { |
958 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { |
943 var gram = rowdata.h_amount * 1000; |
959 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(value, "f1") + " gr</div>"; |
944 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(gram, "f1") + " gr</div>"; |
960 }, |
|
961 initeditor: function (row, cellvalue, editor, celltext, pressedChar) { |
|
962 editor.jqxNumberInput({ |
|
963 inputMode: 'simple', |
|
964 symbol: ' gr', symbolPosition: 'right', |
|
965 decimalDigits: 1, |
|
966 min: 0, max: parseFloat(dataRecord.batch_size * 200), |
|
967 spinButtons: false |
|
968 }); |
945 }, |
969 }, |
946 validation: function (cell, value) { |
970 validation: function (cell, value) { |
947 var maxhops = parseFloat($("#batch_size").jqxNumberInput('decimal')) * 200; |
971 var maxhops = parseFloat(dataRecord.batch_size) * 200; |
948 if (value < 0 || value > maxhops ) { |
972 if (value < 0 || value > maxhops ) { |
949 return { result: false, message: "Gewicht moet 0-"+maxhops+" gram zijn" }; |
973 return { result: false, message: "Gewicht moet tussen 0 en "+maxhops+" gram zijn" }; |
950 } |
974 } |
951 return true; |
975 return true; |
952 } |
976 } |
953 }, |
977 }, |
954 { datafield: 'h_amount', hidden: true }, // We need to declare this column |
|
955 { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat', columntype: 'dropdownlist', |
978 { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat', columntype: 'dropdownlist', |
956 createeditor: function (row, column, editor) { |
979 createeditor: function (row, column, editor) { |
957 var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ]; |
980 var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ]; |
958 editor.jqxDropDownList({ autoDropDownHeight: true, source: srcUse }); |
981 editor.jqxDropDownList({ autoDropDownHeight: true, source: srcUse }); |
959 }, |
982 }, |
960 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { |
983 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { |
961 if ((newvalue == "Mash") || (newvalue == "First Wort")) { |
984 if ((newvalue == "Mash") || (newvalue == "First Wort")) { |
962 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat($("#boil_time").jqxNumberInput('decimal'))); |
985 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat(dataRecord.boil_time)); |
963 } else if (newvalue == "Aroma") { |
986 } else if (newvalue == "Aroma") { |
964 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", 0); |
987 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", 0); |
965 } |
988 } |
966 } |
989 } |
967 }, |
990 }, |
968 { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', |
991 { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', |
969 columntype: 'numberinput', |
992 columntype: 'numberinput', |
|
993 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { |
|
994 if ((rowdata.h_useat == "Boil") || (rowdata.h_useat == "Dry Hop") || (rowdata.h_useat == "Dry hop")) |
|
995 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+"</div>"; |
|
996 else |
|
997 return "<div style='margin: 4px;' class='jqx-right-align'> </div>"; |
|
998 }, |
970 initeditor: function (row, cellvalue, editor, celltext, pressedChar) { |
999 initeditor: function (row, cellvalue, editor, celltext, pressedChar) { |
971 editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) }); |
1000 editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) }); |
972 }, |
1001 }, |
973 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { |
1002 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { |
974 var use = $("#hopGrid").jqxGrid('getcellvalue', row, "h_useat"); |
1003 var use = $("#hopGrid").jqxGrid('getcellvalue', row, "h_useat"); |
975 if (use != "Boil") |
1004 if ((use == "Mash") || (use == "First Wort") || (use == "First wort") || (use == "Aroma")) |
976 return oldvalue; |
1005 return oldvalue; |
977 }, |
1006 }, |
978 validation: function (cell, value) { |
1007 validation: function (cell, value) { |
979 var high = parseFloat(dataRecord.boil_time); |
1008 var high = parseFloat(dataRecord.boil_time); |
980 if (value < 0 || value > high ) { |
1009 if (value < 0 || value > high ) { |
983 return true; |
1012 return true; |
984 } |
1013 } |
985 }, |
1014 }, |
986 { text: 'IBU', editable: false, datafield: 'ibu', width: 80, align: 'right', |
1015 { text: 'IBU', editable: false, datafield: 'ibu', width: 80, align: 'right', |
987 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { |
1016 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { |
988 var ibu = toIBU(rowdata.h_useat, |
1017 var ibu = toIBU(rowdata.h_useat, |
989 rowdata.h_form, |
1018 rowdata.h_form, |
990 preboil_sg, |
1019 preboil_sg, |
991 parseFloat($("#batch_size").jqxNumberInput('decimal')), |
1020 parseFloat($("#batch_size").jqxNumberInput('decimal')), |
992 parseFloat(rowdata.h_amount), |
1021 parseFloat(rowdata.h_amount), |
993 parseFloat(rowdata.h_time), |
1022 parseFloat(rowdata.h_time), |
994 parseFloat(rowdata.h_alpha), |
1023 parseFloat(rowdata.h_alpha), |
995 $("#ibu_method").val() |
1024 $("#ibu_method").val() |
996 ); |
1025 ); |
997 calcIBUs(); |
1026 calcIBUs(); |
998 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>"; |
1027 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>"; |
999 } |
1028 } |
1000 } |
1029 } |
1001 ] |
1030 ] |
1002 }); |
1031 }); |
1003 $("#hopGrid").on('cellendedit', function (event) { |
1032 $("#hopGrid").on('cellendedit', function (event) { |
1004 var args = event.args; |
1033 var args = event.args; |
1005 console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value); |
1034 console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value); |
1006 if (args.datafield == 'grams') { |
1035 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value); |
1007 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', parseFloat(args.value / 1000)); |
1036 if (args.datafield == 'h_weight') |
1008 } else { |
1037 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', args.value / 1000); |
1009 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value); |
1038 //$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc'); |
1010 } |
|
1011 // //$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc'); |
|
1012 }); |
1039 }); |
1013 }; |
1040 }; |
1014 |
1041 |
1015 // Inline miscs editor |
1042 // Inline miscs editor |
1016 var editMisc = function (data) { |
1043 var editMisc = function (data) { |