www/js/rec_edit.js

changeset 808
f6dcde592a7b
parent 807
ffb16dafbc93
child 809
8b30068497a9
equal deleted inserted replaced
807:ffb16dafbc93 808:f6dcde592a7b
101 var rw = ! ro, w100 = 110, w80 = 80; 101 var rw = ! ro, w100 = 110, w80 = 80;
102 if (ro) { // jqxNumberInput width -20 for no spinbuttons 102 if (ro) { // jqxNumberInput width -20 for no spinbuttons
103 w100 = 90; 103 w100 = 90;
104 w80 = 60; 104 w80 = 60;
105 } 105 }
106 $('#miscGrid').jqxGrid({ editable: rw });
107 $('#maddrowbutton').jqxDropDownList({ disabled: ro });
108 $('#minstockbutton').jqxCheckBox({ disabled: ro });
109 $('#mdeleterowbutton').jqxButton({ disabled: ro });
110 $('#yeastGrid').jqxGrid({ editable: rw });
111 $('#yaddrowbutton').jqxDropDownList({ disabled: ro });
112 $('#yinstockbutton').jqxCheckBox({ disabled: ro });
113 $('#ydeleterowbutton').jqxButton({ disabled: ro });
114 $('#mashGrid').jqxGrid({ editable: rw });
115 $('#saddrowbutton').jqxButton({ disabled: ro });
116 $('#sdeleterowbutton').jqxButton({ disabled: ro });
117 $('#w1_name').jqxDropDownList({ disabled: ro }); 106 $('#w1_name').jqxDropDownList({ disabled: ro });
118 $('#w2_name').jqxDropDownList({ disabled: ro }); 107 $('#w2_name').jqxDropDownList({ disabled: ro });
119 $('#pr_name').jqxDropDownList({ disabled: ro }); 108 $('#pr_name').jqxDropDownList({ disabled: ro });
120 $('#wa_cacl2').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 }); 109 $('#wa_cacl2').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
121 $('#wa_caso4').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 }); 110 $('#wa_caso4').jqxNumberInput({ spinButtons: rw, readOnly: ro, width: w100 });
302 291
303 // Calculate the calories in kcal/l (from brouwhulp) 292 // Calculate the calories in kcal/l (from brouwhulp)
304 alc = 1881.22 * fig * (org - fig) / (1.775 - org); 293 alc = 1881.22 * fig * (org - fig) / (1.775 - org);
305 sug = 3550 * fig * (0.1808 * org + 0.8192 * fig - 1.0004); 294 sug = 3550 * fig * (0.1808 * org + 0.8192 * fig - 1.0004);
306 $('#kcal').val(Math.round((alc + sug) / (12 * 0.0295735296))); 295 $('#kcal').val(Math.round((alc + sug) / (12 * 0.0295735296)));
307 }
308
309
310 function swapMash(r1, r2) {
311
312 console.log('swap mash rows ' + r1 + ' ' + r2);
313 var row1 = $('#mashGrid').jqxGrid('getrowdata', r1);
314 var row2 = $('#mashGrid').jqxGrid('getrowdata', r2);
315 var obj1 = { step_name: row1.step_name, step_type: row1.step_type, step_volume: row1.step_volume, step_infuse_amount: row1.step_infuse_amount,
316 step_infuse_temp: row1.step_infuse_temp, step_temp: row1.step_temp, step_time: row1.step_time,
317 ramp_time: row1.ramp_time, end_temp: row1.end_temp, step_wg_ratio: row1.step_wg_ratio };
318 var obj2 = { step_name: row2.step_name, step_type: row2.step_type, step_volume: row2.step_volume, step_infuse_amount: row2.step_infuse_amount,
319 step_infuse_temp: row2.step_infuse_temp, step_temp: row2.step_temp, step_time: row2.step_time,
320 ramp_time: row2.ramp_time, end_temp: row2.end_temp, step_wg_ratio: row2.step_wg_ratio };
321 $("#mashGrid").jqxGrid('updaterow', r1, obj2);
322 $("#mashGrid").jqxGrid('updaterow', r2, obj1);
323 } 296 }
324 297
325 298
326 function infusionVol(step_infused, step_mashkg, infuse_temp, step_temp, last_temp) { 299 function infusionVol(step_infused, step_mashkg, infuse_temp, step_temp, last_temp) {
327 var a = last_temp * (eq_tun_weight * eq_tun_specific_heat + step_infused * SpecificHeatWater + step_mashkg * SpecificHeatMalt); 300 var a = last_temp * (eq_tun_weight * eq_tun_specific_heat + step_infused * SpecificHeatWater + step_mashkg * SpecificHeatMalt);
1242 { name: 'y_sg_lo', type: 'float' }, 1215 { name: 'y_sg_lo', type: 'float' },
1243 { name: 'y_gr_hl_hi', type: 'int' }, 1216 { name: 'y_gr_hl_hi', type: 'int' },
1244 { name: 'y_sg_hi', type: 'float' }, 1217 { name: 'y_sg_hi', type: 'float' },
1245 { name: 'y_avail', type: 'int' } 1218 { name: 'y_avail', type: 'int' }
1246 ], 1219 ],
1247 // addrow: function(rowid, rowdata, position, commit) { commit(true); },
1248 // deleterow: function(rowid, commit) { commit(true); },
1249 // updaterow: function(rowid, rowdata, commit) { commit(true); }
1250 }, 1220 },
1251 yeastAdapter = new $.jqx.dataAdapter(yeastSource); 1221 yeastAdapter = new $.jqx.dataAdapter(yeastSource);
1252 1222
1253 $('#yeastGrid').jqxGrid({ 1223 $('#yeastGrid').jqxGrid({
1254 width: 1240, 1224 width: 1240,
1316 { name: 'step_time', type: 'float' }, 1286 { name: 'step_time', type: 'float' },
1317 { name: 'step_wg_ratio', type: 'float' }, 1287 { name: 'step_wg_ratio', type: 'float' },
1318 { name: 'ramp_time', type: 'float' }, 1288 { name: 'ramp_time', type: 'float' },
1319 { name: 'end_temp', type: 'float' } 1289 { name: 'end_temp', type: 'float' }
1320 ], 1290 ],
1321 addrow: function(rowid, rowdata, position, commit) { commit(true); }, 1291 // addrow: function(rowid, rowdata, position, commit) { commit(true); },
1322 deleterow: function(rowid, commit) { commit(true); } 1292 // deleterow: function(rowid, commit) { commit(true); }
1323 }, 1293 },
1324 mashAdapter = new $.jqx.dataAdapter(mashSource, { 1294 mashAdapter = new $.jqx.dataAdapter(mashSource, {
1325 beforeLoadComplete: function(records) { 1295 beforeLoadComplete: function(records) {
1326 mash_infuse = 0; 1296 mash_infuse = 0;
1327 var row, i, data = new Array(); 1297 var row, i, data = new Array();
1337 $('#mashGrid').jqxGrid({ 1307 $('#mashGrid').jqxGrid({
1338 width: 1240, 1308 width: 1240,
1339 height: 400, 1309 height: 400,
1340 source: mashAdapter, 1310 source: mashAdapter,
1341 theme: theme, 1311 theme: theme,
1342 selectionmode: 'singlerow', 1312 editable: false,
1343 showtoolbar: true,
1344 rendertoolbar: function(toolbar) {
1345 //var me = this;
1346 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
1347 toolbar.append(container);
1348 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');
1349 container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');
1350 $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, height: 27, width: 150 });
1351 $('#saddrowbutton').on('click', function() {
1352 var row = {}, rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
1353 row['step_name'] = 'Stap ' + (rowscount + 1);
1354 if (rowscount > 0) {
1355 row['step_type'] = 1;
1356 row['step_infuse_amount'] = 0;
1357 row['step_volume'] = mash_infuse;
1358 } else {
1359 row['step_type'] = 0;
1360 row['step_infuse_amount'] = 15;
1361 row['step_volume'] = 15;
1362 }
1363 row['step_infuse_temp'] = 0;
1364 row['step_temp'] = 62.0;
1365 row['step_time'] = 20.0;
1366 row['step_wg_ratio'] = 0;
1367 row['ramp_time'] = 1.0;
1368 row['end_temp'] = 62.0;
1369 $('#mashGrid').jqxGrid('addrow', null, datarow);
1370 calcMash();
1371 });
1372 // delete selected yeast.
1373 $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
1374 $('#sdeleterowbutton').on('click', function() {
1375 var id, rowscount, selectedrowindex = $('#mashGrid').jqxGrid('getselectedrowindex');
1376 rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
1377 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
1378 id = $('#mashGrid').jqxGrid('getrowid', selectedrowindex);
1379 $('#mashGrid').jqxGrid('deleterow', id);
1380 calcMash();
1381 }
1382 });
1383 },
1384 ready: function() { 1313 ready: function() {
1385 calcFermentables(); 1314 calcFermentables();
1386 calcInit(); 1315 calcInit();
1387 calcMash(); 1316 calcMash();
1388 $('#jqxLoader').jqxLoader('close'); 1317 $('#jqxLoader').jqxLoader('close');
1418 var color = '#ffffff'; 1347 var color = '#ffffff';
1419 if (value < 2.0 || value > 6.0) 1348 if (value < 2.0 || value > 6.0)
1420 color = '#ff4040'; 1349 color = '#ff4040';
1421 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + dataAdapter.formatNumber(value, 'f2') + '</span>'; 1350 return '<span style="margin: 4px; margin-top: 6px; float: right; color: ' + color + ';">' + dataAdapter.formatNumber(value, 'f2') + '</span>';
1422 } 1351 }
1423 },
1424 { text: '', columntype: 'button', width: 15, align: 'center',
1425 cellsrenderer: function(row) {
1426 if (row < 2)
1427 return ' ';
1428 return '▴';
1429 }, buttonclick: function(row) {
1430 if (row >= 2) {
1431 swapMash(row, row-1);
1432 }
1433 }
1434 },
1435 { text: '', columntype: 'button', width: 15, align: 'center',
1436 cellsrenderer: function(row) {
1437 rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
1438 if (row < 1 || row > (rowscount -2))
1439 return ' ';
1440 return '▾';
1441 }, buttonclick: function(row) {
1442 rowscount = $('#mashGrid').jqxGrid('getdatainformation').rowscount;
1443 if (row >= 1 && row <= (rowscount -2)) {
1444 swapMash(row, row+1);
1445 }
1446 }
1447 },
1448 { text: '', datafield: 'Edit', columntype: 'button', width: 80, align: 'center',
1449 cellsrenderer: function() {
1450 return 'Wijzig';
1451 }, buttonclick: function(row) {
1452 mashRow = row;
1453 mashData = $('#mashGrid').jqxGrid('getrowdata', mashRow);
1454 if (mashRow == 0)
1455 $("#wstep_type").jqxDropDownList('disableAt', 2);
1456 else
1457 $("#wstep_type").jqxDropDownList('enableAt', 2);
1458 $('#wstep_name').val(mashData.step_name);
1459 $('#wstep_type').val(mashData.step_type);
1460 $('#wstep_infuse_amount').val(mashData.step_infuse_amount);
1461 $('#wstep_infuse_temp').val(mashData.step_infuse_temp);
1462 $('#wstep_temp').val(mashData.step_temp);
1463 $('#wend_temp').val(mashData.end_temp);
1464 $('#wstep_time').val(mashData.step_time);
1465 $('#wramp_time').val(mashData.ramp_time);
1466 $('#wstep_infuse_amount').hide(); // Hide all untile we need it.
1467 $('#wstep_infuse_temp').hide();
1468 $('#wstep_pmpt_amount').hide();
1469 $('#wstep_pmpt_temp').hide();
1470 if (mashData.step_type == 0) {
1471 if (mashRow == 0) {
1472 $('#wstep_infuse_amount').show();
1473 $('#wstep_pmpt_amount').show();
1474 } else {
1475 $('#wstep_infuse_temp').show();
1476 $('#wstep_pmpt_temp').show();
1477 }
1478 }
1479 // show the popup window.
1480 $('#popupMash').jqxWindow('open');
1481 }
1482 } 1352 }
1483 ] 1353 ]
1484 }); 1354 });
1485 }; 1355 };
1486
1487
1488 1356
1489 1357
1490 /* 1358 /*
1491 * Remove the top menu so that we MUST use the buttons to leave the editor. 1359 * Remove the top menu so that we MUST use the buttons to leave the editor.
1492 */ 1360 */
2405 $('#est_abv2').jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' }); 2273 $('#est_abv2').jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
2406 $('#est_abv2').jqxNumberInput(Smal1dec); 2274 $('#est_abv2').jqxNumberInput(Smal1dec);
2407 2275
2408 // Tab 6, Maischen 2276 // Tab 6, Maischen
2409 $('#mash_name').jqxInput({ theme: theme, width: 320, height: 23 }); 2277 $('#mash_name').jqxInput({ theme: theme, width: 320, height: 23 });
2410 $('#mash_select').jqxDropDownList({
2411 placeHolder: 'Kies schema:',
2412 theme: theme,
2413 source: mashlist,
2414 displayMember: 'name',
2415 width: 250,
2416 height: 23,
2417 dropDownWidth: 500,
2418 dropDownHeight: 500,
2419 dropDownHorizontalAlignment: 'right'
2420 });
2421 $('#mash_select').on('select', function(event) {
2422 if (event.args) {
2423 var infused = 0, data, datarecord, i, row, rows, rowIDs, index = event.args.index;
2424 // First delete all current steps
2425 rowIDs = new Array();
2426 rows = $('#mashGrid').jqxGrid('getdisplayrows');
2427 for (i = 0; i < rows.length; i++) {
2428 row = rows[i];
2429 rowIDs.push(row.uid);
2430 }
2431 $('#mashGrid').jqxGrid('deleterow', rowIDs);
2432 // Then add the new steps
2433 datarecord = mashlist.records[index];
2434 $('#mash_name').val(datarecord.name);
2435 for (i = 0; i < datarecord.steps.length; i++) {
2436 data = datarecord.steps[i];
2437 row = {};
2438 row['step_name'] = data.step_name;
2439 row['step_type'] = parseInt(data.step_type);
2440 row['step_temp'] = parseFloat(data.step_temp);
2441 row['end_temp'] = parseFloat(data.end_temp);
2442 row['step_time'] = parseFloat(data.step_time);
2443 row['ramp_time'] = parseFloat(data.ramp_time);
2444 row['step_infuse_temp'] = 0.0;
2445 row['step_infuse_amount'] = 0.0;
2446 if (mash_infuse == 0 && dataRecord.wg_amount > 0)
2447 mash_infuse = dataRecord.wg_amount;
2448 if (data.step_type == 0) { // Infusion
2449 if (i == 0) {
2450 row['step_infuse_amount'] = parseFloat(mash_infuse);
2451 } else {
2452 row['step_infuse_temp'] = 99.0;
2453 }
2454 }
2455 //console.log(i + ' type: ' + row['step_type'] + ' start infusion: ' + parseFloat(row['step_infuse_amount']) + ' mash_infuse: ' + mash_infuse);
2456 infused += parseFloat(row['step_infuse_amount']);
2457 row['step_volume'] = infused;
2458 if (mashkg > 0)
2459 row['step_wg_ratio'] = Round(parseFloat(mash_infuse / mashkg), 2);
2460 else
2461 row['step_wg_ratio'] = 0;
2462 $('#mashGrid').jqxGrid('addrow', null, row);
2463 }
2464 calcMash();
2465 }
2466 });
2467 $('#popupMash').jqxWindow({
2468 width: 800,
2469 height: 375,
2470 position: { x: 230, y: 100 },
2471 resizable: false,
2472 theme: theme,
2473 isModal: true,
2474 autoOpen: false,
2475 cancelButton: $('#MashReady'),
2476 modalOpacity: 0.40
2477 });
2478 $('#MashReady').jqxButton({ template: 'success', width: '90px', theme: theme });
2479 $('#MashReady').click(function() {
2480 calcMash();
2481 });
2482 $('#wstep_name').jqxInput({ theme: theme, width: 320, height: 23 });
2483 $('#wstep_name').on('change', function(event) {
2484 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2485 rowdata.step_name = $('#wstep_name').val();
2486 });
2487 $('#wstep_type').jqxDropDownList({
2488 theme: theme,
2489 source: MashStepTypeAdapter,
2490 valueMember: 'id',
2491 displayMember: 'nl',
2492 width: 180,
2493 height: 23,
2494 autoDropDownHeight: true
2495 });
2496 $('#wstep_type').on('select', function(event) {
2497 if (event.args) {
2498 var rowdata, rows, i, row, index = event.args.index;
2499 rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2500 if (rowdata.step_type != index) {
2501 rowdata.step_type = index;
2502 $('#wstep_infuse_amount').hide();
2503 $('#wstep_infuse_temp').hide();
2504 $('#wstep_pmpt_amount').hide();
2505 $('#wstep_pmpt_temp').hide();
2506 if (index == 0) { // Infusion
2507 if (mashRow == 0) {
2508 $('#wstep_infuse_amount').show();
2509 $('#wstep_pmpt_amount').show();
2510 } else {
2511 $('#wstep_infuse_temp').show();
2512 $('#wstep_pmpt_temp').show();
2513 }
2514 }
2515 if (index == 1) { // Temperature
2516 if (mashRow > 0)
2517 rowdata.step_infuse_amount = 0;
2518 rowdata.step_infuse_temp = 0;
2519 }
2520 if (index == 2) { // Decoction
2521 var rowprev = $('#mashGrid').jqxGrid('getrowdata', mashRow-1);
2522 rowdata.step_infuse_temp = 99;
2523 rowdata.step_infuse_amount = decoctionVol(rowdata.step_volume, rowdata.step_temp, rowprev.end_temp);
2524 console.log('decoction: ' + rowdata.step_infuse_amount + '/' + rowdata.step_infuse_temp);
2525 }
2526 $('#mashGrid').jqxGrid('updaterow', mashRow, rowdata);
2527 mash_infuse = 0;
2528 rows = $('#mashGrid').jqxGrid('getrows');
2529 for (i = 0; i < rows.length; i++) {
2530 row = rows[i];
2531 if (row.step_type == 0) // Infusion
2532 mash_infuse += parseFloat(row.step_infuse_amount);
2533 }
2534 calcMash();
2535 }
2536 }
2537 });
2538 $('#wstep_temp').jqxNumberInput(Spin1dec);
2539 $('#wstep_temp').on('change', function(event) {
2540 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2541 if (rowdata.step_type == 2) { // Decoction
2542 var rowprev = $('#mashGrid').jqxGrid('getrowdata', mashRow-1);
2543 var a = (eq_tun_weight * eq_tun_specific_heat + rowdata.step_volume * SpecificHeatWater) *
2544 (parseFloat(event.args.value) - rowprev.end_temp);
2545 var b = SpecificHeatWater * (99 - parseFloat(event.args.value));
2546 if (b > 0) {
2547 rowdata.step_temp = parseFloat(event.args.value);
2548 rowdata.step_infuse_amount = Round(a / b, 2);
2549 } else
2550 rowdata.step_infuse_amount = 0;
2551 console.log('change temp ' + rowdata.step_temp + ' decoction: ' + rowdata.step_infuse_amount + '/' + rowdata.step_infuse_temp);
2552 } else {
2553 rowdata.step_temp = parseFloat(event.args.value);
2554 }
2555 });
2556 $('#wend_temp').jqxNumberInput(Spin1dec);
2557 $('#wend_temp').on('change', function(event) {
2558 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2559 rowdata.end_temp = parseFloat(event.args.value);
2560 });
2561 $('#wstep_time').jqxNumberInput(PosInt);
2562 $('#wstep_time').on('change', function(event) {
2563 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2564 rowdata.step_time = parseFloat(event.args.value);
2565 });
2566 $('#wramp_time').jqxNumberInput(PosInt);
2567 $('#wramp_time').on('change', function(event) {
2568 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2569 rowdata.ramp_time = parseFloat(event.args.value);
2570 });
2571 $('#wstep_infuse_amount').jqxNumberInput(Spin1dec);
2572 $('#wstep_infuse_amount').on('change', function(event) {
2573 var i, rows, row, rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2574 rowdata.step_infuse_amount = parseFloat(event.args.value);
2575 if (mashRow == 0) {
2576 rowdata.step_infuse_amount = parseFloat(event.args.value);
2577 mash_infuse = 0;
2578 rows = $('#mashGrid').jqxGrid('getrows');
2579 for (i = 0; i < rows.length; i++) {
2580 row = rows[i];
2581 if (row.step_type == 0) // Infusion
2582 mash_infuse += parseFloat(row.step_infuse_amount);
2583 }
2584 if (dataRecord.w2_amount == 0) {
2585 dataRecord.w1_amount = mash_infuse;
2586 $('#w1_amount').val(mash_infuse);
2587 } else {
2588 var w1_amount = (dataRecord.w1_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
2589 var w2_amount = (dataRecord.w2_amount / (dataRecord.w1_amount + dataRecord.w2_amount)) * mash_infuse;
2590 dataRecord.w1_amount = Round(w1_amount, 3);
2591 dataRecord.w2_amount = Round(w2_amount, 3);
2592 $('#w1_amount').val(dataRecord.w1_amount);
2593 $('#w2_amount').val(dataRecord.w2_amount);
2594 }
2595 $('#wg_amount').val(mash_infuse);
2596 console.log('new infuse amount: ' + mash_infuse);
2597 calcWater();
2598 }
2599 });
2600 $('#wstep_infuse_temp').jqxNumberInput(Spin1dec);
2601 $('#wstep_infuse_temp').on('change', function(event) {
2602 var prevdata = $('#mashGrid').jqxGrid('getrowdata', mashRow-1);
2603 var rowdata = $('#mashGrid').jqxGrid('getrowdata', mashRow);
2604 rowdata.step_infuse_temp = parseFloat(event.args.value);
2605 var vol = infusionVol(prevdata.step_volume, mashkg, rowdata.step_infuse_temp, rowdata.step_temp, prevdata.end_temp);
2606 console.log('new vol: ' + vol);
2607 rowdata.step_infuse_amount = vol;
2608 $('#wstep_infuse_amount').val(vol);
2609 });
2610 2278
2611 // Tab 7, Water 2279 // Tab 7, Water
2612 $('#tgt_bu').jqxNumberInput(Show2wat); 2280 $('#tgt_bu').jqxNumberInput(Show2wat);
2613 $('#tgt_so4_cl,#got_so4_cl').jqxNumberInput(Show1wat); 2281 $('#tgt_so4_cl,#got_so4_cl').jqxNumberInput(Show1wat);
2614 2282

mercurial