www/js/recipes.js

changeset 58
83ccc36df675
parent 57
bb9a06aa9acd
child 59
ad28e09e3abd
equal deleted inserted replaced
57:bb9a06aa9acd 58:83ccc36df675
308 ] 308 ]
309 }) 309 })
310 }; 310 };
311 311
312 // Inline hops editor 312 // Inline hops editor
313 var editHop = function (data) {
314 var hopSource = {
315 localdata: data.hops,
316 datatype: "local",
317 datafields: [
318 { name: 'h_name', type: 'string' },
319 { name: 'h_origin', type: 'string' },
320 { name: 'h_amount', type: 'float' },
321 { name: 'h_cost', type: 'float' },
322 { name: 'h_type', type: 'string' },
323 { name: 'h_form', type: 'string' },
324 { name: 'h_useat', type: 'string' },
325 { name: 'h_time', type: 'float' },
326 { name: 'h_alpha', type: 'float' },
327 { name: 'h_beta', type: 'float' },
328 { name: 'h_hsi', type: 'float' },
329 { name: 'h_humulene', type: 'float' },
330 { name: 'h_carophyllene', type: 'float' },
331 { name: 'h_cohumulone', type: 'float' },
332 { name: 'h_myrcene', type: 'float' },
333 { name: 'h_total_oil', type: 'float' }
334 ],
335 addrow: function (rowid, rowdata, position, commit) {
336 commit(true);
337 },
338 deleterow: function (rowid, commit) {
339 commit(true);
340 }
341 };
342 var hopAdapter = new $.jqx.dataAdapter(hopSource);
343 // dropdownlist datasource from inventory_hops
344 var hopUrl = "gethopsources.php";
345 var hopInvSource = {
346 datatype: "json",
347 datafields: [
348 { name: 'record', type: 'number' },
349 { name: 'name', type: 'string' },
350 { name: 'origin', type: 'string' },
351 { name: 'type', type: 'string' },
352 { name: 'alpha', type: 'float' },
353 { name: 'beta', type: 'float' },
354 { name: 'humulene', type: 'float' },
355 { name: 'caryophyllene', type: 'float' },
356 { name: 'cohumulone', type: 'float' },
357 { name: 'myrcene', type: 'float' },
358 { name: 'hsi', type: 'float' },
359 { name: 'useat', type: 'string' },
360 { name: 'form', type: 'string' },
361 { name: 'total_oil', type: 'float' },
362 { name: 'cost', type: 'float' }
363 ],
364 url: hopUrl,
365 async: true
366 };
367 var hoplist = new $.jqx.dataAdapter(hopInvSource);
368
369 $("#hopGrid").jqxGrid({
370 width: 960,
371 height: 400,
372 source: hopAdapter,
373 theme: theme,
374 selectionmode: 'singlerow',
375 editmode: 'selectedrow',
376 editable: true,
377 localization: getLocalization(),
378 showtoolbar: true,
379 rendertoolbar: function (toolbar) {
380 var me = this;
381 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
382 toolbar.append(container);
383 container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
384 container.append('<input style="float: left; margin-left: 230px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
385 // add hop from dropdownlist.
386 $("#haddrowbutton").jqxDropDownList({
387 placeHolder: "Kies hop:",
388 theme: theme,
389 source: hoplist,
390 displayMember: "name",
391 width: 150,
392 height: 27,
393 dropDownWidth: 300
394 });
395 $("#haddrowbutton").on('select', function (event) {
396 if (event.args) {
397 var index = event.args.index;
398 var datarecord = hoplist.records[index];
399 var row = {};
400 row["h_name"] = datarecord.name;
401 row["h_origin"] = datarecord.origin;
402 row["h_amount"] = 0;
403 row["h_cost"] = datarecord.cost;
404 row["h_type"] = datarecord.type;
405 row["h_form"] = datarecord.form;
406 row["h_useat"] = datarecord.useat;
407 row["h_time"] = 0;
408 row["h_alpha"] = datarecord.alpha;
409 row["h_beta"] = datarecord.beta;
410 row["h_hsi"] = datarecord.hsi;
411 row["h_humulene"] = datarecord.humulene;
412 row["h_carophyllene"] = datarecord.carophyllene;
413 row["h_cohumulone"] = datarecord.cohumulone;
414 row["h_myrcene"] = datarecord.myrcene;
415 row["h_total_oil"] = datarecord.total_oil;
416 var commit = $("#hopGrid").jqxGrid('addrow', null, row);
417 }
418 });
419
420 // delete selected hop.
421 $("#hdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
422 $("#hdeleterowbutton").on('click', function () {
423 var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
424 var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
425 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
426 var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
427 var commit = $("#hopGrid").jqxGrid('deleterow', id);
428 }
429 });
430 },
431 columns: [
432 { text: 'Hop', editable: false, datafield: 'h_name' },
433 { text: 'Type', editable: false, width: 100, datafield: 'h_type' },
434 { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
435 { text: 'Beta', datafield: 'h_beta', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
436 { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
437 columntype: 'numberinput',
438 validation: function (cell, value) {
439 if (value < 0 || value > 100000000000 ) {
440 return { result: false, message: "Volume moet 0-~ zijn" };
441 }
442 return true;
443 }
444 },
445 { text: 'Tijd', datafield: 'h_time', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f0',
446 columntype: 'numberinput',
447 validation: function (cell, value) {
448 if (value < 0 || value > 100000000000 ) {
449 return { result: false, message: "De tijd moet 0-~ zijn" };
450 }
451 return true;
452 }
453 }
454 ]
455 })
456 };
457
313 458
314 // Inline miscs editor 459 // Inline miscs editor
315 460
316 // Inline yeasts editor 461 // Inline yeasts editor
317 462
508 $("#ibu_method").val('Tinseth'); 653 $("#ibu_method").val('Tinseth');
509 $("#mash_sparge_temp").val(78); 654 $("#mash_sparge_temp").val(78);
510 $("#mash_ph").val(5.4); 655 $("#mash_ph").val(5.4);
511 $("#mash_name").val(''); 656 $("#mash_name").val('');
512 editFermentable(''); 657 editFermentable('');
658 editHop('');
513 editWater(''); 659 editWater('');
514 $("#popupWindow").jqxWindow('open'); 660 $("#popupWindow").jqxWindow('open');
515 }); 661 });
516 }, 662 },
517 filterable: true, 663 filterable: true,
551 $("#ibu_method").val(dataRecord.ibu_method); 697 $("#ibu_method").val(dataRecord.ibu_method);
552 $("#mash_name").val(dataRecord.mash_name); 698 $("#mash_name").val(dataRecord.mash_name);
553 $("#mash_ph").val(dataRecord.mash_ph); 699 $("#mash_ph").val(dataRecord.mash_ph);
554 $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp); 700 $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
555 editFermentable(dataRecord); 701 editFermentable(dataRecord);
702 editHop(dataRecord);
556 editWater(dataRecord); 703 editWater(dataRecord);
557 // show the popup window. 704 // show the popup window.
558 $("#popupWindow").jqxWindow('open'); 705 $("#popupWindow").jqxWindow('open');
559 } 706 }
560 } 707 }
601 $("#Cancel").jqxButton({ width: '90px', theme: theme }); 748 $("#Cancel").jqxButton({ width: '90px', theme: theme });
602 $("#Save").jqxButton({ width: '90px', theme: theme }); 749 $("#Save").jqxButton({ width: '90px', theme: theme });
603 // update the edited row when the user clicks the 'Save' button. 750 // update the edited row when the user clicks the 'Save' button.
604 $("#Save").click(function () { 751 $("#Save").click(function () {
605 var fermentablerow = $('#fermentableGrid').jqxGrid('getrows'); 752 var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
753 var hoprow = $('#hopGrid').jqxGrid('getrows');
606 var waterrow = $('#waterGrid').jqxGrid('getrows'); 754 var waterrow = $('#waterGrid').jqxGrid('getrows');
607 if (editrow >= 0) { 755 if (editrow >= 0) {
608 var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); 756 var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
609 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); 757 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
610 var row = { 758 var row = {
638 ibu_method: $("#ibu_method").val(), 786 ibu_method: $("#ibu_method").val(),
639 mash_name: $("#mash_name").val(), 787 mash_name: $("#mash_name").val(),
640 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')), 788 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
641 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), 789 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
642 fermentables: fermentablerow, 790 fermentables: fermentablerow,
791 hops: hopwor,
643 waters: waterrow 792 waters: waterrow
644 }; 793 };
645 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 794 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
646 $("#popupWindow").jqxWindow('hide'); 795 $("#popupWindow").jqxWindow('hide');
647 } else { 796 } else {
677 ibu_method: $("#ibu_method").val(), 826 ibu_method: $("#ibu_method").val(),
678 mash_name: $("#mash_name").val(), 827 mash_name: $("#mash_name").val(),
679 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')), 828 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
680 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), 829 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
681 fermentables: fermentablerow, 830 fermentables: fermentablerow,
831 hops: hoprow,
682 waters: waterrow 832 waters: waterrow
683 }; 833 };
684 $('#jqxgrid').jqxGrid('addrow', null, newrow); 834 $('#jqxgrid').jqxGrid('addrow', null, newrow);
685 $("#popupWindow").jqxWindow('hide'); 835 $("#popupWindow").jqxWindow('hide');
686 } 836 }

mercurial