diff -r 6d94167c2697 -r 7224109adfe1 www/js/recipes.js --- a/www/js/recipes.js Sat Sep 01 22:24:09 2018 +0200 +++ b/www/js/recipes.js Tue Sep 04 13:44:02 2018 +0200 @@ -47,7 +47,7 @@ // tooltips $("#name").jqxTooltip({ content: 'De naam voor dit recept.' }); $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' }); - $("#style_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'}); + $("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'}); $("#type").jqxTooltip({ content: 'Het brouw type van dit recept.' }); // prepare the data var source = { @@ -55,9 +55,11 @@ cache: false, datafields: [ { name: 'record', type: 'number' }, - { name: 'style_name', type: 'string' }, - { name: 'style_letter', type: 'string' }, - { name: 'style_guide', type: 'string' }, + { name: 'st_name', type: 'string' }, + { name: 'st_letter', type: 'string' }, + { name: 'st_guide', type: 'string' }, + { name: 'st_og_min', type: 'float' }, + { name: 'st_og_max', type: 'float' }, { name: 'name', type: 'string' }, { name: 'notes', type: 'string' }, { name: 'type', type: 'number' }, @@ -70,12 +72,15 @@ { name: 'color_method', type: 'string' }, { name: 'est_ibu', type: 'float' }, { name: 'ibu_method', type: 'string' }, - { name: 'json_fermentables', type: 'string' }, - { name: 'json_hops', type: 'string' }, - { name: 'json_miscs', type: 'string' }, - { name: 'json_yeasts', type: 'string' }, - { name: 'json_waters', type: 'string' }, - { name: 'json_mash', type: 'string' } + { name: 'mash_sparge_temp', type: 'float' }, + { name: 'mash_ph', type: 'float' }, + { name: 'mash_name', type: 'string' }, + { name: 'fermentables', type: 'string' }, + { name: 'hops', type: 'string' }, + { name: 'miscs', type: 'string' }, + { name: 'yeasts', type: 'string' }, + { name: 'waters', type: 'array' }, + { name: 'mashs', type: 'string' } ], id: 'record', url: url, @@ -129,28 +134,35 @@ } }; var dataAdapter = new $.jqx.dataAdapter(source); - // Inline steps editor -/* var editsteps = function (data) { - var generaterow = function () { - var row = {}; - row["step_name"] = "Stap 1"; - row["step_type"] = "Infusion"; - row["step_temp"] = 62.0; - row['step_time'] = 20.0; - row['ramp_time'] = 1.0; - row['end_temp'] = 62.0; - return row; - } - var stepSource = { - localdata: data.steps, + + // Inline waters editor + var editWater = function (data) { +// var generaterow = function () { +// var row = {}; +// row["w_name"] = "Water 1"; +// row["step_type"] = "Infusion"; +// row["w_amount"] = 22.0; +// row['step_time'] = 20.0; +// row['ramp_time'] = 1.0; +// row['end_temp'] = 62.0; +// return row; +// } + var waterSource = { + localdata: data.waters, datatype: "local", datafields: [ - { name: 'step_name', type: 'string' }, - { name: 'step_type', type: 'string' }, - { name: 'step_temp', type: 'float' }, - { name: 'step_time', type: 'float' }, - { name: 'ramp_time', type: 'float' }, - { name: 'end_temp', type: 'float' } + { name: 'w_name', type: 'string' }, + { name: 'w_amount', type: 'float' }, + { name: 'w_calcium', type: 'float' }, + { name: 'w_bicarbonate', type: 'float' }, + { name: 'w_sulfate', type: 'float' }, + { name: 'w_chloride', type: 'float' }, + { name: 'w_sodium', type: 'float' }, + { name: 'w_magnesium', type: 'float' }, + { name: 'w_ph', type: 'float' }, + { name: 'w_total_alkalinity', type: 'float' }, + { name: 'w_cost', type: 'float' }, + { name: 'w_default_water', type: 'bool' } ], addrow: function (rowid, rowdata, position, commit) { commit(true); @@ -159,15 +171,18 @@ commit(true); } }; - var stepAdapter = new $.jqx.dataAdapter(stepSource); - $("#grid").jqxGrid({ - width: 640, - height: 330, - source: stepAdapter, + var waterAdapter = new $.jqx.dataAdapter(waterSource); + $("#waterGrid").jqxGrid({ + width: 960, + height: 200, + source: waterAdapter, theme: theme, selectionmode: 'singlerow', editmode: 'selectedrow', editable: true, + showstatusbar: true, + statusbarheight: 50, + showaggregates: true, showtoolbar: true, rendertoolbar: function (toolbar) { var me = this; @@ -177,87 +192,72 @@ container.append(''); $("#addrowbutton").jqxButton({ theme: theme, width: 150 }); $("#deleterowbutton").jqxButton({ theme: theme, width: 150 }); - // create new row. - $("#addrowbutton").on('click', function () { - var datarow = generaterow(); - var commit = $("#grid").jqxGrid('addrow', null, datarow); - }); + // create new row. Dropdown uit water inventory. +// $("#addrowbutton").on('click', function () { +// var datarow = generaterow(); +// var commit = $("#waterGrid").jqxGrid('addrow', null, datarow); +// }); // delete row. - $("#deleterowbutton").on('click', function () { - var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); - var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; - if (selectedrowindex >= 0 && selectedrowindex < rowscount) { - var id = $("#grid").jqxGrid('getrowid', selectedrowindex); - var commit = $("#grid").jqxGrid('deleterow', id); - } - }); + // Overgebleven waters in volume verhogen met het verwijderde water. +// $("#deleterowbutton").on('click', function () { +// var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); +// var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; +// if (selectedrowindex >= 0 && selectedrowindex < rowscount) { +// var id = $("#grid").jqxGrid('getrowid', selectedrowindex); +// var commit = $("#grid").jqxGrid('deleterow', id); +// } +// }); }, columns: [ - { text: 'Stap naam', datafield: 'step_name' }, - { text: 'Stap type', datafield: 'step_type', width: 100, columntype: 'dropdownlist', - createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) { - var dataSource = [ "Infusion", "Temperature", "Decoction" ]; - editor.jqxDropDownList({ source: dataSource, dropDownHeight: 95 }); - } - }, - { text: 'Temperatuur', datafield: 'step_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1', + { text: 'Water bron', editable: false, datafield: 'w_name' }, + { text: 'Volume', datafield: 'w_amount', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1', + columntype: 'numberinput', + aggregates: ['sum'], validation: function (cell, value) { - if (value < 35 || value > 80) { - return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." }; + if (value < 0 || value > 100000000000 ) { + return { result: false, message: "Volume moet 0-~ zijn" }; } return true; } }, - { text: 'Eind', datafield: 'end_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1', - validation: function (cell, value) { - if (value < 35 || value > 80) { - return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." }; - } - return true; - } - }, - { text: 'Tijd', datafield: 'step_time', width: 70, align: 'right', cellsalign: 'right', - validation: function (cell, value) { - if (value < 1 || value > 360) { - return { result: false, message: "De tijd moet tussen 1 en 360 zijn." }; - } - return true; - } - }, - { text: 'Stap', datafield: 'ramp_time', width: 70, align: 'right', cellsalign: 'right', - validation: function (cell, value) { - if (value < 1 || value > 60) { - return { result: false, message: "De tijd moet tussen 1 en 60 zijn." }; - } - return true; - } - } + // TODO: validator test max is hoeveelheid maischwater. Dan water verdelen voor totaal. + { text: 'Ca', editable: false, datafield: 'w_calcium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Mg', editable: false, datafield: 'w_magnesium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Na', editable: false, datafield: 'w_sodium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Tot Alk', editable: false, datafield: 'w_total_alkalinity', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'CaSO4', editable: false, datafield: 'w_sulfate', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Cl', editable: false, datafield: 'w_chloride', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'pH', editable: false, datafield: 'w_ph', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' } ] }); - $("#grid").on('cellendedit', function (event) { - $('#grid').jqxGrid('sortby', 'step_temp', 'asc'); - }); - }; -*/ +// $("#grid").on('cellendedit', function (event) { +// $('#grid').jqxGrid('sortby', 'step_temp', 'asc'); +// }); + }; // editWater = function (data) { + // initialize the input fields. var srcType = [ "All Grain", "Partial Mash", "Extract" ]; var srcColor = [ "Morey", "Mosher", "Daniels" ]; var srcIBU = [ "Tinseth", "Rager", "Garetz", "Daniels", "Mosher", "Noonan" ]; $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); - $("#style_name").jqxInput({ theme: theme, width: 250, height: 23 }); - $("#style_letter").jqxInput({ theme: theme, width: 100, height: 23 }); - $("#style_guide").jqxInput({ theme: theme, width: 250, height: 23 }); + $("#st_name").jqxInput({ theme: theme, width: 250, height: 23 }); + $("#st_letter").jqxInput({ theme: theme, width: 100, height: 23 }); + $("#st_guide").jqxInput({ theme: theme, width: 250, height: 23 }); $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 125, height: 23, dropDownHeight: 95 }); $("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: 'L', symbolPosition: 'right' }); $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', template: "success", theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true }); $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' }); $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1, max: 1.9, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 }); + $("#st_og_min").jqxNumberInput({ disabled: true, inputMode: 'simple', width: 50, height: 23, decimalDigits: 3, readOnly: true }); + $("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); $("#est_fg").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, min: 0.980, max: 1.040, decimalDigits: 3, readOnly: true }); $("#est_color").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1, max: 200, decimalDigits: 0, spinButtons: true }); $("#color_method").jqxDropDownList({ theme: theme, source: srcColor, width: 125, height: 23, dropDownHeight: 95 }); $("#est_ibu").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 200, decimalDigits: 0, spinButtons: true }); $("#ibu_method").jqxDropDownList({ theme: theme, source: srcIBU, width: 125, height: 23, dropDownHeight: 180 }); + $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 }); + $("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); var editrow = -1; // initialize jqxGrid $("#jqxgrid").jqxGrid({ @@ -280,9 +280,9 @@ $("#popupWindow").jqxWindow({ position: { x: 40, y: 20 } }); $("#name").val(''); $("#notes").val(''); - $("#style_name").val(''); - $("#style_letter").val(''); - $("#style_guide").val(''); + $("#st_name").val(''); + $("#st_letter").val(''); + $("#st_guide").val(''); $("#type").val('All Grain'); $("#batch_size").val(20); $("#boil_time").val(90); @@ -293,16 +293,16 @@ $("#color_method").val('Morey'); $("#est_ibu").val(0); $("#ibu_method").val('Tinseth'); - // editsteps(''); + editWater(''); $("#popupWindow").jqxWindow('open'); }); }, filterable: true, filtermode: 'excel', columns: [ - { text: 'Stijlgids', datafield: 'style_guide', width: 120 }, - { text: 'Letter', datafield: 'style_letter', width: 60 }, - { text: 'Stijl', datafield: 'style_name', width: 150 }, + { text: 'Stijlgids', datafield: 'st_guide', width: 120 }, + { text: 'Letter', datafield: 'st_letter', width: 60 }, + { text: 'Stijl', datafield: 'st_name', width: 150 }, { text: 'Naam', datafield: 'name' }, { text: 'OG', datafield: 'est_og', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f3' }, { text: 'EBC', datafield: 'est_color', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f0' }, @@ -317,26 +317,31 @@ var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); $("#name").val(dataRecord.name); $("#notes").val(dataRecord.notes); - $("#style_name").val(dataRecord.style_name); - $("#style_letter").val(dataRecord.style_letter); - $("#style_guide").val(dataRecord.style_guide); + $("#st_name").val(dataRecord.st_name); + $("#st_letter").val(dataRecord.st_letter); + $("#st_guide").val(dataRecord.st_guide); $("#type").val(dataRecord.type); $("#batch_size").val(dataRecord.batch_size); $("#boil_time").val(dataRecord.boil_time); $("#efficiency").val(dataRecord.efficiency); $("#est_og").val(dataRecord.est_og); + $("#st_og_min").val(dataRecord.st_og_min); + $("#st_og_max").val(dataRecord.st_og_max); $("#est_fg").val(dataRecord.est_fg); $("#est_color").val(dataRecord.est_color); $("#color_method").val(dataRecord.color_method); $("#est_ibu").val(dataRecord.est_ibu); $("#ibu_method").val(dataRecord.ibu_method); + $("#mash_name").val(dataRecord.mash_name); + $("#mash_ph").val(dataRecord.mash_ph); + editWater(dataRecord); // editsteps(dataRecord); // show the popup window. $("#popupWindow").jqxWindow('open'); } } ], - groups: ['style_guide','style_letter' ] + groups: ['st_guide','st_letter' ] }); // initialize the popup window and buttons. @@ -385,9 +390,9 @@ record: rowID, name: $("#name").val(), notes: $("#notes").val(), - style_name: $('#style_name').val(), - style_letter: $('#style_letter').val(), - style_guide: $('#style_guide').val(), + st_name: $('#st_name').val(), + st_letter: $('#st_letter').val(), + st_guide: $('#st_guide').val(), type: $("#type").val(), batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), @@ -397,7 +402,9 @@ est_color: parseFloat($("#est_color").jqxNumberInput('decimal')), color_method: $("#color_method").val(), est_ibu: parseFloat($("#est_ibu").jqxNumberInput('decimal')), - ibu_method: $("#ibu_method").val() + ibu_method: $("#ibu_method").val(), + mash_name: $("#mash_name").val(), + mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')) // steps: steprows }; $('#jqxgrid').jqxGrid('updaterow', rowID, row); @@ -408,9 +415,9 @@ record: -1, name: $("#name").val(), notes: $("#notes").val(), - style_name: $('#style_name').val(), - style_letter: $('#style_letter').val(), - style_guide: $('#style_guide').val(), + st_name: $('#st_name').val(), + st_letter: $('#st_letter').val(), + st_guide: $('#st_guide').val(), type: $("#type").val(), batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), @@ -420,7 +427,9 @@ est_color: parseFloat($("#est_color").jqxNumberInput('decimal')), color_method: $("#color_method").val(), est_ibu: parseFloat($("#est_ibu").jqxNumberInput('decimal')), - ibu_method: $("#ibu_method").val() + ibu_method: $("#ibu_method").val(), + mash_name: $("#mash_name").val(), + mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')) // steps: steprows }; $('#jqxgrid').jqxGrid('addrow', null, newrow);