Fri, 13 Sep 2019 20:48:35 +0200
Load new url in database write callback
function createDelElements(){$("#eventWindow").jqxWindow({theme:theme,position:{x:490,y:210},width:300,height:175,resizable:false,isModal:true,modalOpacity:0.4,okButton:$("#delOk"),cancelButton:$("#delCancel"),initContent:function(){$("#delOk").jqxButton({template:"danger",width:"65px",theme:theme});$("#delCancel").jqxButton({template:"success",width:"65px",theme:theme});$("#delCancel").focus()}});$("#eventWindow").jqxWindow("hide")}$(document).ready(function(){function d(h,g){$("#totval").val(h*g)}var b={},a="includes/db_inventory_fermentables.php",e={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"name",type:"string"},{name:"type",type:"int"},{name:"yield",type:"float"},{name:"color",type:"float"},{name:"add_after_boil",type:"int"},{name:"origin",type:"string"},{name:"supplier",type:"string"},{name:"notes",type:"string"},{name:"coarse_fine_diff",type:"float"},{name:"moisture",type:"float"},{name:"diastatic_power",type:"float"},{name:"protein",type:"float"},{name:"dissolved_protein",type:"float"},{name:"max_in_batch",type:"float"},{name:"recommend_mash",type:"int"},{name:"added",type:"int"},{name:"always_on_stock",type:"int"},{name:"di_ph",type:"float"},{name:"acid_to_ph_57",type:"float"},{name:"graintype",type:"int"},{name:"inventory",type:"float"},{name:"cost",type:"float"},{name:"production_date",type:"string"},{name:"tht_date",type:"string"}],id:"record",url:a,deleterow:function(g,i){var h="delete=true&"+$.param({record:g});$.ajax({dataType:"json",url:a,cache:false,data:h,type:"POST",success:function(k,j,l){i(true);location.reload(true)},error:function(j,l,k){i(false)}})},addrow:function(h,k,g,j){var i="insert=true&"+$.param(k);$.ajax({dataType:"json",url:a,cache:false,data:i,type:"POST",success:function(m,l,n){j(true);location.reload(true)},error:function(l,n,m){j(false)}})},updaterow:function(g,j,i){var h="update=true&"+$.param(j);$.ajax({dataType:"json",url:a,cache:false,data:h,type:"POST",success:function(l,k,m){i(true);location.reload(true)},error:function(k,m,l){i(false)}})}},f=new $.jqx.dataAdapter(e),c=-1;$("#name").jqxInput({theme:theme,width:640,height:23});$("#type").jqxDropDownList({theme:theme,source:FermentableTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#yield").jqxNumberInput(Spin1dec);$("#color").jqxNumberInput(Spin1dec);$("#add_after_boil").jqxCheckBox({theme:theme,width:120,height:23});$("#origin").jqxInput({theme:theme,width:250,height:23});$("#supplier").jqxInput({theme:theme,width:250,height:23});$("#notes").jqxInput({theme:theme,width:640,height:100});$("#coarse_fine_diff").jqxNumberInput(Spin1dec);$("#moisture").jqxNumberInput(Spin1dec);$("#diastatic_power").jqxNumberInput(PosInt);$("#protein").jqxNumberInput(Spin1dec);$("#dissolved_protein").jqxNumberInput(Spin1dec);$("#max_in_batch").jqxNumberInput(Perc1dec);$("#recommend_mash").jqxCheckBox({theme:theme,width:120,height:23});$("#added").jqxDropDownList({theme:theme,source:AddedAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#always_on_stock").jqxCheckBox({theme:theme,width:120,height:23});$("#di_ph").jqxNumberInput(Spin2pH);$("#acid_to_ph_57").jqxNumberInput({inputMode:"simple",theme:theme,width:110,height:23,min:-1000,max:1000,decimalDigits:4,spinButtons:true});$("#graintype").jqxDropDownList({theme:theme,source:GrainTypeAdapter,valueMember:"id",displayMember:"nl",width:180,height:23,autoDropDownHeight:true});$("#inventory").jqxNumberInput(Spin3dec);$("#production_date").jqxDateTimeInput(Dateopts);$("#cost").jqxNumberInput(Spin2dec);$("#tht_date").jqxDateTimeInput(Dateopts);$("#totval").jqxNumberInput(Show2dec);$("#jqxgrid").jqxGrid({width:1280,height:630,source:f,theme:theme,showstatusbar:true,renderstatusbar:function(i){var g,h,j;g=$("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");h=$("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");j=$("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");g.append(h);g.append(j);i.append(g);h.jqxButton({theme:theme,width:90,height:20});j.jqxButton({theme:theme,width:90,height:20});h.click(function(k){c=-1;$("#popupWindow").jqxWindow({position:{x:110,y:30}});$("#name").val("Nieuw product");$("#type").val(0);$("#origin").val("");$("#supplier").val("");$("#notes").val("");$("#yield").val(80);$("#color").val(3);$("#coarse_fine_diff").val(3);$("#moisture").val(4);$("#diastatic_power").val(0);$("#protein").val(0);$("#dissolved_protein").val(0);$("#max_in_batch").val(100);$("#recommend_mash").val(1);$("#always_on_stock").val(0);$("#di_ph").val(0);$("#acid_to_ph_57").val(0);$("#graintype").val(0);$("#add_after_boil").val(0);$("#added").val(0);$("#inventory").val(0);$("#cost").val(0);$("#production_date").val("");$("#tht_date").val("");$("#popupWindow").jqxWindow("open")});j.click(function(k){window.location.href="import_ingredients.php?select=fermentables"})},filterable:true,filtermode:"excel",columns:[{text:"Herkomst",datafield:"origin",width:150},{text:"Producent",datafield:"supplier",width:140},{text:"Vergistbaar product",datafield:"name",menu:false},{text:"Soort",width:135,filtertype:"list",datafield:"type",cellsrenderer:function(h,g,k,j,i,l){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+FermentableTypeData[k].nl+"</span>"}},{text:"Graan type",datafield:"graintype",align:"center",cellsalign:"center",width:125,cellsrenderer:function(h,g,k,j,i,l){return"<span style='margin: 3px; margin-top: 6px; float: left;'>"+GrainTypeData[k].nl+"</span>"}},{text:"EBC",datafield:"color",width:60,align:"right",menu:false,cellsalign:"right"},{text:"Opbrengst",datafield:"yield",width:70,align:"right",menu:false,cellsalign:"right",cellsformat:"p1"},{text:"Voorraad",datafield:"inventory",width:100,align:"right",menu:false,cellsrenderer:function(h,g,l,k,j,m){var i="";if(l>0){if(l<1){i=f.formatNumber(l*1000,"f0")+" gr"}else{i=f.formatNumber(l,"f1")+" kg"}}return"<span style='margin: 3px; margin-top: 6px; float: right;'>"+i+"</span>"}},{text:"",datafield:"Edit",width:100,align:"center",menu:false,columntype:"button",cellsrenderer:function(){return"Wijzig"},buttonclick:function(g){c=g;$("#popupWindow").jqxWindow({position:{x:110,y:30}});b=$("#jqxgrid").jqxGrid("getrowdata",c);$("#name").val(b.name);$("#type").val(b.type);$("#yield").val(b.yield);$("#color").val(b.color);$("#add_after_boil").val(b.add_after_boil);$("#origin").val(b.origin);$("#supplier").val(b.supplier);$("#notes").val(b.notes);$("#coarse_fine_diff").val(b.coarse_fine_diff);$("#moisture").val(b.moisture);$("#diastatic_power").val(lintner_to_kolbach(b.diastatic_power));$("#protein").val(b.protein);$("#dissolved_protein").val(b.dissolved_protein);$("#max_in_batch").val(b.max_in_batch);$("#recommend_mash").val(b.recommend_mash);$("#added").val(b.added);$("#always_on_stock").val(b.always_on_stock);$("#di_ph").val(b.di_ph);$("#acid_to_ph_57").val(b.acid_to_ph_57);$("#graintype").val(b.graintype);$("#inventory").val(b.inventory);$("#cost").val(b.cost);$("#production_date").val(b.production_date);$("#tht_date").val(b.tht_date);d(b.cost,b.inventory);$("#popupWindow").jqxWindow("open")}}]});$("#cost").on("change",function(g){b.cost=parseFloat(g.args.value);d(b.cost,b.inventory)});$("#inventory").on("change",function(g){b.inventory=parseFloat(g.args.value);d(b.cost,b.inventory)});$("#popupWindow").jqxWindow({width:1050,height:550,resizable:false,theme:theme,isModal:true,autoOpen:false,cancelButton:$("#Cancel"),modalOpacity:0.4});$("#popupWindow").on("open",function(){$("#name").jqxInput("selectAll")});$("#Delete").jqxButton({template:"danger",width:"90px",theme:theme});$("#Delete").click(function(){if(c>=0){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var g=$("#jqxgrid").jqxGrid("getrowid",c);$("#jqxgrid").jqxGrid("deleterow",g)})}$("#popupWindow").jqxWindow("hide")});$("#Cancel").jqxButton({template:"primary",width:"90px",theme:theme});$("#Clone").jqxButton({template:"warning",width:"90px",theme:theme});$("#Clone").click(function(){var g={record:-1,name:$("#name").val()+" kopie",type:$("#type").val(),yield:parseFloat($("#yield").jqxNumberInput("decimal")),color:parseFloat($("#color").jqxNumberInput("decimal")),add_after_boil:$("#add_after_boil").val(),origin:$("#origin").val(),supplier:$("#supplier").val(),notes:$("#notes").val(),coarse_fine_diff:parseFloat($("#coarse_fine_diff").jqxNumberInput("decimal")),moisture:parseFloat($("#moisture").jqxNumberInput("decimal")),diastatic_power:kolbach_to_lintner(parseFloat($("#diastatic_power").jqxNumberInput("decimal"))),protein:parseFloat($("#protein").jqxNumberInput("decimal")),dissolved_protein:parseFloat($("#dissolved_protein").jqxNumberInput("decimal")),max_in_batch:parseFloat($("#max_in_batch").jqxNumberInput("decimal")),recommend_mash:$("#recommend_mash").val(),added:$("#added").val(),always_on_stock:$("#always_on_stock").val(),di_ph:parseFloat($("#di_ph").jqxNumberInput("decimal")),acid_to_ph_57:parseFloat($("#acid_to_ph_57").jqxNumberInput("decimal")),graintype:$("#graintype").val(),inventory:0,cost:parseFloat($("#cost").jqxNumberInput("decimal")),production_date:"",tht_date:""};$("#jqxgrid").jqxGrid("addrow",null,g);$("#popupWindow").jqxWindow("hide")});$("#Save").jqxButton({template:"success",width:"90px",theme:theme});$("#Save").click(function(){var h,g=-1;if(c>=0){g=$("#jqxgrid").jqxGrid("getrowid",c)}h={record:g,name:$("#name").val(),type:$("#type").val(),yield:parseFloat($("#yield").jqxNumberInput("decimal")),color:parseFloat($("#color").jqxNumberInput("decimal")),add_after_boil:$("#add_after_boil").val(),origin:$("#origin").val(),supplier:$("#supplier").val(),notes:$("#notes").val(),coarse_fine_diff:parseFloat($("#coarse_fine_diff").jqxNumberInput("decimal")),moisture:parseFloat($("#moisture").jqxNumberInput("decimal")),diastatic_power:kolbach_to_lintner(parseFloat($("#diastatic_power").jqxNumberInput("decimal"))),protein:parseFloat($("#protein").jqxNumberInput("decimal")),dissolved_protein:parseFloat($("#dissolved_protein").jqxNumberInput("decimal")),max_in_batch:parseFloat($("#max_in_batch").jqxNumberInput("decimal")),recommend_mash:$("#recommend_mash").val(),added:$("#added").val(),always_on_stock:$("#always_on_stock").val(),di_ph:parseFloat($("#di_ph").jqxNumberInput("decimal")),acid_to_ph_57:parseFloat($("#acid_to_ph_57").jqxNumberInput("decimal")),graintype:$("#graintype").val(),inventory:parseFloat($("#inventory").jqxNumberInput("decimal")),cost:parseFloat($("#cost").jqxNumberInput("decimal")),production_date:$("#production_date").val(),tht_date:$("#tht_date").val(),};if(c>=0){$("#jqxgrid").jqxGrid("updaterow",g,h)}else{$("#jqxgrid").jqxGrid("addrow",null,h)}$("#popupWindow").jqxWindow("hide")});createDelElements()});