www/js/rec_edit.js

changeset 223
0de4455bd2a1
parent 221
a8aabb63fbcc
child 224
d3cdcfac81cb
equal deleted inserted replaced
222:78946739b3a6 223:0de4455bd2a1
1619 { name: 'h_time', type: 'float' }, 1619 { name: 'h_time', type: 'float' },
1620 { name: 'h_alpha', type: 'float' }, 1620 { name: 'h_alpha', type: 'float' },
1621 { name: 'h_beta', type: 'float' }, 1621 { name: 'h_beta', type: 'float' },
1622 { name: 'h_hsi', type: 'float' }, 1622 { name: 'h_hsi', type: 'float' },
1623 { name: 'h_humulene', type: 'float' }, 1623 { name: 'h_humulene', type: 'float' },
1624 { name: 'h_carophyllene', type: 'float' }, 1624 { name: 'h_caryophyllene', type: 'float' },
1625 { name: 'h_cohumulone', type: 'float' }, 1625 { name: 'h_cohumulone', type: 'float' },
1626 { name: 'h_myrcene', type: 'float' }, 1626 { name: 'h_myrcene', type: 'float' },
1627 { name: 'h_total_oil', type: 'float' }, 1627 { name: 'h_total_oil', type: 'float' },
1628 { name: 'h_weight', type: 'float' } 1628 { name: 'h_inventory', type: 'float' },
1629 { name: 'h_avail', type: 'int' }
1629 ], 1630 ],
1630 addrow: function (rowid, rowdata, position, commit) { 1631 addrow: function (rowid, rowdata, position, commit) {
1631 commit(true); 1632 commit(true);
1632 }, 1633 },
1633 deleterow: function (rowid, commit) { 1634 deleterow: function (rowid, commit) {
1634 commit(true); 1635 commit(true);
1635 } 1636 }
1636 }; 1637 };
1637 var hopAdapter = new $.jqx.dataAdapter(hopSource, { 1638 var hopAdapter = new $.jqx.dataAdapter(hopSource);
1638 beforeLoadComplete: function (records) {
1639 var data = new Array();
1640 for (var i = 0; i < records.length; i++) {
1641 var row = records[i];
1642 row.h_weight = row.h_amount * 1000;
1643 data.push(row);
1644 }
1645 return data;
1646 },
1647 loadError: function(jqXHR, status, error) {
1648 $('#err').text(status + ' ' + error);
1649 },
1650 });
1651 $("#hopGrid").jqxGrid({ 1639 $("#hopGrid").jqxGrid({
1652 width: 1050, 1640 width: 1240,
1653 height: 400, 1641 height: 400,
1654 source: hopAdapter, 1642 source: hopAdapter,
1655 theme: theme, 1643 theme: theme,
1656 selectionmode: 'singlerow', 1644 selectionmode: 'singlerow',
1657 editmode: 'selectedcell',
1658 editable: true,
1659 localization: getLocalization(), 1645 localization: getLocalization(),
1660 showtoolbar: true, 1646 showtoolbar: true,
1661 rendertoolbar: function (toolbar) { 1647 rendertoolbar: function (toolbar) {
1662 var me = this; 1648 var me = this;
1663 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); 1649 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
1664 toolbar.append(container); 1650 toolbar.append(container);
1665 container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>'); 1651 container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
1666 container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>'); 1652 container.append('<div style="float: left; margin-left: 10px; margin-top: 5px;">In voorraad:</div>');
1667 container.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>'); 1653 container.append('<div style="float: left; margin-left: 10px;" id="hinstockbutton"></div>');
1668 container.append('<input style="float: left; margin-left: 280px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />'); 1654 container.append('<input style="float: left; margin-left: 400px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
1669 // add hop from dropdownlist. 1655 // add hop from dropdownlist.
1670 $("#haddrowbutton").jqxDropDownList({ 1656 $("#haddrowbutton").jqxDropDownList({
1671 placeHolder: "Kies hop:", 1657 placeHolder: "Kies hop:",
1672 theme: theme, 1658 theme: theme,
1659 template: "primary",
1673 source: hoplist, 1660 source: hoplist,
1674 displayMember: "name", 1661 displayMember: "name",
1675 width: 150, 1662 width: 150,
1676 height: 27, 1663 height: 27,
1677 dropDownWidth: 500, 1664 dropDownWidth: 500,
1690 row["h_origin"] = datarecord.origin; 1677 row["h_origin"] = datarecord.origin;
1691 row["h_amount"] = 0; 1678 row["h_amount"] = 0;
1692 row["h_cost"] = datarecord.cost; 1679 row["h_cost"] = datarecord.cost;
1693 row["h_type"] = datarecord.type; 1680 row["h_type"] = datarecord.type;
1694 row["h_form"] = datarecord.form; 1681 row["h_form"] = datarecord.form;
1695 row["h_useat"] = datarecord.useat; 1682 row["h_useat"] = 2; // Boil
1696 row["h_time"] = 0; 1683 row["h_time"] = 0;
1697 row["h_alpha"] = datarecord.alpha; 1684 row["h_alpha"] = datarecord.alpha;
1698 row["h_beta"] = datarecord.beta; 1685 row["h_beta"] = datarecord.beta;
1699 row["h_hsi"] = datarecord.hsi; 1686 row["h_hsi"] = datarecord.hsi;
1700 row["h_humulene"] = datarecord.humulene; 1687 row["h_humulene"] = datarecord.humulene;
1701 row["h_carophyllene"] = datarecord.carophyllene; 1688 row["h_caryophyllene"] = datarecord.caryophyllene;
1702 row["h_cohumulone"] = datarecord.cohumulone; 1689 row["h_cohumulone"] = datarecord.cohumulone;
1703 row["h_myrcene"] = datarecord.myrcene; 1690 row["h_myrcene"] = datarecord.myrcene;
1704 row["h_total_oil"] = datarecord.total_oil; 1691 row["h_total_oil"] = datarecord.total_oil;
1705 row["h_weight"] = 0; 1692 row["h_inventory"] = datarecord.inventory;
1706 var commit = $("#hopGrid").jqxGrid('addrow', null, row); 1693 var commit = $("#hopGrid").jqxGrid('addrow', null, row);
1707 } 1694 }
1708 }); 1695 });
1709 1696
1710 $("#hinstockbutton").jqxCheckBox({ theme: theme, height: 27 }); 1697 $("#hinstockbutton").jqxCheckBox({ theme: theme, height: 27 });
1712 hopinstock = event.args.checked; 1699 hopinstock = event.args.checked;
1713 hoplist.dataBind(); 1700 hoplist.dataBind();
1714 }); 1701 });
1715 1702
1716 // delete selected hop. 1703 // delete selected hop.
1717 $("#hdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 }); 1704 $("#hdeleterowbutton").jqxButton({ template: "danger", theme: theme, height: 27, width: 150 });
1718 $("#hdeleterowbutton").on('click', function () { 1705 $("#hdeleterowbutton").on('click', function () {
1719 var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex'); 1706 var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
1720 var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount; 1707 var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
1721 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 1708 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
1722 var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex); 1709 var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
1723 var commit = $("#hopGrid").jqxGrid('deleterow', id); 1710 var commit = $("#hopGrid").jqxGrid('deleterow', id);
1724 } 1711 }
1712 calcIBUs();
1725 }); 1713 });
1726 }, 1714 },
1727 ready: function() { 1715 ready: function() {
1716 calcIBUs();
1728 $('#jqxTabs').jqxTabs('next'); 1717 $('#jqxTabs').jqxTabs('next');
1729 }, 1718 },
1730 columns: [ 1719 columns: [
1731 { text: 'Hop', editable: false, datafield: 'h_name', 1720 { text: 'Hop', datafield: 'h_name',
1732 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { 1721 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
1733 var rowData = $("#hopGrid").jqxGrid('getrowdata', row); 1722 var rowData = $("#hopGrid").jqxGrid('getrowdata', row);
1734 return "<span style='margin: 3px; margin-top: 6px; float: "+ 1723 return "<span style='margin: 3px; margin-top: 6px; float: "+
1735 columnproperties.cellsalign+"'>" +rowData.h_origin+" / "+rowData.h_name+"</span>"; 1724 columnproperties.cellsalign+"'>" +rowData.h_origin+" / "+rowData.h_name+"</span>";
1736 }, 1725 },
1737 }, 1726 },
1738 { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' }, 1727 { text: 'Type', width: 90, datafield: 'h_type',
1739 { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' },
1740 { text: 'Alpha', editable: false, datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
1741 { text: 'Amount', hidden: true, datafield: 'h_amount' },
1742 { text: 'Gewicht gr', datafield: 'h_weight', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f1',
1743 columntype: 'numberinput',
1744 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { 1728 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1745 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(value, "f1") + " gr</div>"; 1729 return "<div style='margin: 4px;'>" + HopTypeData[value].nl + "</div>";
1746 },
1747 initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
1748 editor.jqxNumberInput({
1749 inputMode: 'simple', decimalDigits: 1, min: 0, max: parseFloat(dataRecord.batch_size * 200),
1750 spinButtons: false
1751 });
1752 },
1753 validation: function (cell, value) {
1754 var maxhops = parseFloat(dataRecord.batch_size) * 200;
1755 if (value < 0 || value > maxhops ) {
1756 return { result: false, message: "Gewicht moet tussen 0 en "+maxhops+" gram zijn" };
1757 }
1758 return true;
1759 } 1730 }
1760 }, 1731 },
1761 { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat', columntype: 'dropdownlist', 1732 { text: 'Vorm', width: 90, datafield: 'h_form',
1762 createeditor: function (row, column, editor) { 1733 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1763 var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ]; 1734 return "<div style='margin: 4px;'>" + HopFormData[value].nl + "</div>";
1764 editor.jqxDropDownList({ autoDropDownHeight: true, source: srcUse }); 1735 }
1765 }, 1736 },
1766 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { 1737 { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
1767 if ((newvalue == "Mash") || (newvalue == "First Wort")) { 1738 { text: 'Gebruik', width: 110, datafield: 'h_useat',
1768 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", parseFloat(dataRecord.boil_time)); 1739 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1769 } else if (newvalue == "Aroma") { 1740 return "<div style='margin: 4px;'>" + HopUseData[value].nl + "</div>";
1770 $("#hopGrid").jqxGrid('setcellvalue', row, "h_time", 0);
1771 }
1772 } 1741 }
1773 }, 1742 },
1774 { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0', 1743 { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
1775 columntype: 'numberinput',
1776 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { 1744 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1777 if ((rowdata.h_useat == "Boil") || (rowdata.h_useat == "Dry Hop") || (rowdata.h_useat == "Dry hop")) 1745 if ((rowdata.h_useat == 2) || (rowdata.h_useat == 5)) // Boil or Dry hop
1778 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+"</div>"; 1746 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f0")+"</div>";
1779 else 1747 else
1780 return "<div style='margin: 4px;' class='jqx-right-align'> </div>"; 1748 return "<div style='margin: 4px;' class='jqx-right-align'> </div>";
1781 },
1782 initeditor: function (row, cellvalue, editor, celltext, pressedChar) {
1783 editor.jqxNumberInput({ decimalDigits: 0, digits: 3, min: 0, max: parseFloat(dataRecord.boil_time) });
1784 },
1785 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
1786 var use = $("#hopGrid").jqxGrid('getcellvalue', row, "h_useat");
1787 if ((use == "Mash") || (use == "First Wort") || (use == "First wort") || (use == "Aroma"))
1788 return oldvalue;
1789 },
1790 validation: function (cell, value) {
1791 var high = parseFloat(dataRecord.boil_time);
1792 if (value < 0 || value > high ) {
1793 return { result: false, message: "De tijd moet 0-"+high+" zijn" };
1794 }
1795 return true;
1796 } 1749 }
1797 }, 1750 },
1798 { text: 'IBU', editable: false, datafield: 'ibu', width: 80, align: 'right', 1751 { text: 'IBU', datafield: 'ibu', width: 80, align: 'right',
1799 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { 1752 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1800 var ibu = toIBU(rowdata.h_useat, 1753 var ibu = toIBU(rowdata.h_useat,
1801 rowdata.h_form, 1754 rowdata.h_form,
1802 preboil_sg, 1755 preboil_sg,
1803 parseFloat($("#batch_size").jqxNumberInput('decimal')), 1756 parseFloat($("#batch_size").jqxNumberInput('decimal')),
1804 parseFloat(rowdata.h_amount), 1757 parseFloat(rowdata.h_amount),
1805 parseFloat(rowdata.h_time), 1758 parseFloat(rowdata.h_time),
1806 parseFloat(rowdata.h_alpha), 1759 parseFloat(rowdata.h_alpha),
1807 $("#ibu_method").val() 1760 $("#ibu_method").val()
1808 ); 1761 );
1809 calcIBUs(); 1762 // calcIBUs();
1810 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>"; 1763 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>";
1811 } 1764 }
1765 },
1766 { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right', cellsalign: 'right',
1767 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1768 if (value < 1)
1769 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000, "f1")+" gr</div>";
1770 else
1771 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f1")+" kg</div>";
1772 }
1773 },
1774 { text: 'Voorraad', datafield: 'h_inventory', width: 110, align: 'right', cellsalign: 'right',
1775 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
1776 if (value < 1)
1777 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000, "f1")+" gr</div>";
1778 else
1779 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value, "f1")+" kg</div>";
1780 }
1781 },
1782 { text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () {
1783 return "Wijzig";
1784 }, buttonclick: function (row) {
1785 hopRow = row;
1786 hopData = $("#hopGrid").jqxGrid('getrowdata', hopRow);
1787 $("#wh_name").val(hopData.h_name);
1788 $("#wh_amount").val(hopData.h_amount * 1000);
1789 var ibu = toIBU(hopData.h_useat, hopData.h_form, preboil_sg,
1790 parseFloat($("#batch_size").jqxNumberInput('decimal')),
1791 parseFloat(hopData.h_amount), parseFloat(hopData.h_time),
1792 parseFloat(hopData.h_alpha), $("#ibu_method").val()
1793 );
1794 $("#wh_ibu").val(ibu);
1795 $("#wh_time").val(hopData.h_time);
1796 $("#wh_useat").val(hopData.h_useat);
1797 // show the popup window.
1798 $("#popupHop").jqxWindow('open');
1799 }
1812 } 1800 }
1813 ] 1801 ]
1814 }); 1802 });
1815 $("#hopGrid").on('cellendedit', function (event) {
1816 var args = event.args;
1817 console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
1818 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
1819 if (args.datafield == 'h_weight')
1820 $("#hopGrid").jqxGrid('setcellvalue', args.rowindex, 'h_amount', args.value / 1000);
1821 //$('#hopGrid').jqxGrid('sortby', 'f_amount', 'desc');
1822 });
1823 }; 1803 };
1824 1804
1825 // Inline miscs editor 1805 // Inline miscs editor
1826 var editMisc = function (data) { 1806 var editMisc = function (data) {
1827 var miscSource = { 1807 var miscSource = {
2681 // Tab 3, Hoppen 2661 // Tab 3, Hoppen
2682 $("#est_ibu2").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' }); 2662 $("#est_ibu2").jqxTooltip({ content: 'De bitterheid in IBU. Dit wordt automatisch berekend.' });
2683 $("#est_ibu2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); 2663 $("#est_ibu2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
2684 $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); 2664 $("#hop_flavour").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
2685 $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true }); 2665 $("#hop_aroma").jqxProgressBar({ width: 300, height: 23, theme: theme, showText: true });
2666 $("#popupHop").jqxWindow({
2667 width: 800,
2668 height: 300,
2669 position: { x: 230, y: 100 },
2670 resizable: false,
2671 theme: theme,
2672 isModal: true,
2673 autoOpen: false,
2674 cancelButton: $("#HopReady"),
2675 modalOpacity: 0.40
2676 });
2677 $("#HopReady").jqxButton({ template: "success", width: '90px', theme: theme });
2678 $("#HopReady").click(function () {
2679 $("#hopGrid").jqxGrid('sortby', 'f_amount', 'asc');
2680 calcIBUs();
2681 });
2682 $("#wh_name").jqxInput({ theme: theme, width: 320, height: 23 });
2683 $("#wh_instock").jqxCheckBox({ theme: theme, height: 23 });
2684 $("#wh_instock").on('change', function (event) {
2685 hopinstock = event.args.checked;
2686 hoplist.dataBind();
2687 });
2688 $("#wh_select").jqxDropDownList({
2689 placeHolder: "Kies hop:",
2690 theme: theme,
2691 source: hoplist,
2692 displayMember: "name",
2693 width: 150,
2694 height: 23,
2695 dropDownWidth: 500,
2696 dropDownHeight: 500,
2697 renderer: function (index, label, value) {
2698 var datarecord = hoplist.records[index];
2699 return datarecord.origin+ " / " + datarecord.name + " (" + datarecord.alpha + " % &alpha;)";
2700 }
2701 });
2702 $("#wh_select").on('select', function (event) {
2703 if (event.args) {
2704 var index = event.args.index;
2705 var datarecord = hoplist.records[index];
2706 var rowdata = $("#hopGrid").jqxGrid('getrowdata', hopRow);
2707 $("#wh_name").val(datarecord.name);
2708 rowdata.h_name = datarecord.name;
2709
2710 }
2711 });
2712 $("#wh_amount").jqxNumberInput( Spin1dec1 );
2713 $('#wh_amount').on('change', function (event) {
2714 console.log("amount changed: "+event.args.value);
2715 var amount = parseFloat(event.args.value) / 1000;
2716 var rowdata = $("#hopGrid").jqxGrid('getrowdata', hopRow);
2717
2718 var ibu = toIBU(rowdata.h_useat, rowdata.h_form, preboil_sg,
2719 parseFloat($("#batch_size").jqxNumberInput('decimal')),
2720 amount, parseFloat(rowdata.h_time),
2721 parseFloat(rowdata.h_alpha), $("#ibu_method").val()
2722 );
2723 rowdata.h_amount = amount;
2724 // $("#hopGrid").jqxGrid('setcellvalue', hopRow, 'h_amount', amount);
2725 calcIBUs();
2726 });
2727 $("#wh_ibu").jqxNumberInput( Spin1dec1 );
2728 $("#wh_time").jqxNumberInput( PosInt );
2729 $("#wh_useat").jqxDropDownList({
2730 theme: theme,
2731 source: HopUseAdapter,
2732 valueMember: 'id',
2733 displayMember: 'nl',
2734 width: 180,
2735 height: 23,
2736 autoDropDownHeight: true,
2737 dropDownVerticalAlignment: 'top'
2738 });
2739 $("#wh_useat").on('select', function (event) {
2740 if (event.args) {
2741 var index = event.args.index;
2742 var rowdata = $("#hopGrid").jqxGrid('getrowdata', hopRow);
2743 rowdata.h_useat = index;
2744 if ((index == 0) || (index == 1))
2745 rowdata.h_time = parseFloat(dataRecord.boil_time);
2746 else if (index == 3)
2747 rowdata.h_time = 0;
2748 }
2749 });
2686 2750
2687 // Tab 4, Diversen 2751 // Tab 4, Diversen
2688 2752
2689 // Tab 5, Gist 2753 // Tab 5, Gist
2690 2754

mercurial