www/js/recipes.js

changeset 60
dbbe408108ea
parent 59
ad28e09e3abd
child 61
3469979f83be
equal deleted inserted replaced
59:ad28e09e3abd 60:dbbe408108ea
100 $.ajax({ 100 $.ajax({
101 dataType: 'json', 101 dataType: 'json',
102 url: url, 102 url: url,
103 cache: false, 103 cache: false,
104 data: data, 104 data: data,
105 type: "POST",
105 success: function (data, status, xhr) { 106 success: function (data, status, xhr) {
106 // delete command is executed. 107 // delete command is executed.
107 commit(true); 108 commit(true);
108 }, 109 },
109 error: function (jqXHR, textStatus, errorThrown) { 110 error: function (jqXHR, textStatus, errorThrown) {
116 $.ajax({ 117 $.ajax({
117 dataType: 'json', 118 dataType: 'json',
118 url: url, 119 url: url,
119 cache: false, 120 cache: false,
120 data: data, 121 data: data,
122 type: "POST",
121 success: function (data, status, xhr) { 123 success: function (data, status, xhr) {
122 commit(true); 124 commit(true);
123 }, 125 },
124 error: function(jqXHR, textStatus, errorThrown) { 126 error: function(jqXHR, textStatus, errorThrown) {
125 commit(false); 127 commit(false);
131 $.ajax({ 133 $.ajax({
132 dataType: 'json', 134 dataType: 'json',
133 url: url, 135 url: url,
134 cache: false, 136 cache: false,
135 data: data, 137 data: data,
138 type: "POST",
136 success: function (data, status, xhr) { 139 success: function (data, status, xhr) {
137 // update command is executed. 140 // update command is executed.
138 commit(true); 141 commit(true);
139 }, 142 },
140 error: function(jqXHR, textStatus, errorThrown) { 143 error: function(jqXHR, textStatus, errorThrown) {
469 } 472 }
470 ] 473 ]
471 }) 474 })
472 }; 475 };
473 476
474
475 // Inline miscs editor 477 // Inline miscs editor
478 var editMisc = function (data) {
479 var miscSource = {
480 localdata: data.miscs,
481 datatype: "local",
482 cache: false,
483 datafields: [
484 { name: 'm_name', type: 'string' },
485 { name: 'm_amount', type: 'float' },
486 { name: 'm_cost', type: 'float' },
487 { name: 'm_type', type: 'string' },
488 { name: 'm_use_use', type: 'string' },
489 { name: 'm_time', type: 'float' },
490 { name: 'm_amount_is_weight', type: 'bool' }
491 ],
492 addrow: function (rowid, rowdata, position, commit) {
493 commit(true);
494 },
495 deleterow: function (rowid, commit) {
496 commit(true);
497 }
498 };
499 var miscAdapter = new $.jqx.dataAdapter(miscSource);
500 // dropdownlist datasource from inventory_miscs
501 var miscUrl = "getmiscsources.php";
502 var miscInvSource = {
503 datatype: "json",
504 datafields: [
505 { name: 'record', type: 'number' },
506 { name: 'name', type: 'string' },
507 { name: 'type', type: 'string' },
508 { name: 'use_use', type: 'string' },
509 { name: 'amount_is_weight', type: 'bool' },
510 { name: 'time', type: 'float' },
511 { name: 'cost', type: 'float' }
512 ],
513 url: miscUrl,
514 async: true
515 };
516 var misclist = new $.jqx.dataAdapter(miscInvSource);
517
518 $("#miscGrid").jqxGrid({
519 width: 960,
520 height: 400,
521 source: miscAdapter,
522 theme: theme,
523 selectionmode: 'singlerow',
524 editmode: 'selectedrow',
525 editable: true,
526 localization: getLocalization(),
527 showtoolbar: true,
528 rendertoolbar: function (toolbar) {
529 var me = this;
530 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
531 toolbar.append(container);
532 container.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');
533 container.append('<input style="float: left; margin-left: 230px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');
534 // add misc from dropdownlist.
535 $("#maddrowbutton").jqxDropDownList({
536 placeHolder: "Kies ingredient:",
537 theme: theme,
538 source: misclist,
539 displayMember: "name",
540 width: 150,
541 height: 27,
542 dropDownWidth: 300
543 });
544 $("#maddrowbutton").on('select', function (event) {
545 if (event.args) {
546 var index = event.args.index;
547 var datarecord = misclist.records[index];
548 var row = {};
549 row["m_name"] = datarecord.name;
550 row["m_amount"] = 0;
551 row["m_cost"] = datarecord.cost;
552 row["m_type"] = datarecord.type;
553 row["m_use_use"] = datarecord.use_use;
554 row["m_time"] = 0;
555 row["m_amount_is_weight"] = datarecord.amount_is_weight;
556 var commit = $("#miscGrid").jqxGrid('addrow', null, row);
557 }
558 });
559 // delete selected misc.
560 $("#mdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
561 $("#mdeleterowbutton").on('click', function () {
562 var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex');
563 var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
564 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
565 var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex);
566 var commit = $("#miscGrid").jqxGrid('deleterow', id);
567 }
568 });
569 },
570 columns: [
571 { text: 'Ingredient', editable: false, datafield: 'm_name' },
572 { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' },
573 { text: 'Gebruik', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'm_use_use' },
574 { text: 'Gewicht', datafield: 'm_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f5',
575 columntype: 'numberinput',
576 validation: function (cell, value) {
577 if (value < 0 || value > 100000000000 ) {
578 return { result: false, message: "Volume moet 0-~ zijn" };
579 }
580 return true;
581 }
582 },
583 { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
584 columntype: 'numberinput',
585 validation: function (cell, value) {
586 if (value < 0 || value > 100000000000 ) {
587 return { result: false, message: "De tijd moet 0-~ zijn" };
588 }
589 return true;
590 }
591 }
592 ]
593 })
594 };
595
476 596
477 // Inline yeasts editor 597 // Inline yeasts editor
478 598
479 // Inline waters editor 599 // Inline waters editor
480 var editWater = function (data) { 600 var editWater = function (data) {
670 $("#mash_sparge_temp").val(78); 790 $("#mash_sparge_temp").val(78);
671 $("#mash_ph").val(5.4); 791 $("#mash_ph").val(5.4);
672 $("#mash_name").val(''); 792 $("#mash_name").val('');
673 editFermentable(''); 793 editFermentable('');
674 editHop(''); 794 editHop('');
795 editMisc('');
675 editWater(''); 796 editWater('');
676 $("#popupWindow").jqxWindow('open'); 797 $("#popupWindow").jqxWindow('open');
677 }); 798 });
678 }, 799 },
679 filterable: true, 800 filterable: true,
714 $("#mash_name").val(dataRecord.mash_name); 835 $("#mash_name").val(dataRecord.mash_name);
715 $("#mash_ph").val(dataRecord.mash_ph); 836 $("#mash_ph").val(dataRecord.mash_ph);
716 $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp); 837 $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
717 editFermentable(dataRecord); 838 editFermentable(dataRecord);
718 editHop(dataRecord); 839 editHop(dataRecord);
840 editMisc(dataRecord);
719 editWater(dataRecord); 841 editWater(dataRecord);
720 // show the popup window. 842 // show the popup window.
721 $("#popupWindow").jqxWindow('open'); 843 $("#popupWindow").jqxWindow('open');
722 } 844 }
723 } 845 }
765 $("#Save").jqxButton({ width: '90px', theme: theme }); 887 $("#Save").jqxButton({ width: '90px', theme: theme });
766 // update the edited row when the user clicks the 'Save' button. 888 // update the edited row when the user clicks the 'Save' button.
767 $("#Save").click(function () { 889 $("#Save").click(function () {
768 var fermentablerow = $('#fermentableGrid').jqxGrid('getrows'); 890 var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
769 var hoprow = $('#hopGrid').jqxGrid('getrows'); 891 var hoprow = $('#hopGrid').jqxGrid('getrows');
892 var miscrow = $('#miscGrid').jqxGrid('getrows');
770 var waterrow = $('#waterGrid').jqxGrid('getrows'); 893 var waterrow = $('#waterGrid').jqxGrid('getrows');
771 if (editrow >= 0) { 894 if (editrow >= 0) {
772 var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); 895 var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
773 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); 896 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
774 var row = { 897 var row = {
803 mash_name: $("#mash_name").val(), 926 mash_name: $("#mash_name").val(),
804 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')), 927 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
805 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), 928 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
806 fermentables: fermentablerow, 929 fermentables: fermentablerow,
807 hops: hoprow, 930 hops: hoprow,
931 miscs: miscrow,
808 waters: waterrow 932 waters: waterrow
809 }; 933 };
810 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 934 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
811 $("#popupWindow").jqxWindow('hide');
812 } else { 935 } else {
813 // Insert a record 936 // Insert a record
814 var newrow = { 937 var newrow = {
815 record: -1, 938 record: -1,
816 name: $("#name").val(), 939 name: $("#name").val(),
843 mash_name: $("#mash_name").val(), 966 mash_name: $("#mash_name").val(),
844 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')), 967 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
845 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')), 968 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
846 fermentables: fermentablerow, 969 fermentables: fermentablerow,
847 hops: hoprow, 970 hops: hoprow,
971 miscs: miscrow,
848 waters: waterrow 972 waters: waterrow
849 }; 973 };
850 $('#jqxgrid').jqxGrid('addrow', null, newrow); 974 $('#jqxgrid').jqxGrid('addrow', null, newrow);
851 $("#popupWindow").jqxWindow('hide');
852 } 975 }
976 $("#popupWindow").jqxWindow('hide');
853 }); 977 });
854 createDelElements(); 978 createDelElements();
855 }); 979 });
856 980

mercurial