# HG changeset patch # User Michiel Broek # Date 1568386491 -7200 # Node ID 06df1320327c9350c2e31c3681f410bfb67e9986 # Parent e17155b3086a9c6094b2ae15434eef200d0b6990 Fixed style profiles race condition diff -r e17155b3086a -r 06df1320327c www/js/profile_fermentation-min.js --- a/www/js/profile_fermentation-min.js Fri Sep 13 16:15:51 2019 +0200 +++ b/www/js/profile_fermentation-min.js Fri Sep 13 16:54:51 2019 +0200 @@ -1,1 +1,1 @@ -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(){var c={};var b="includes/db_profile_fermentation.php";$("#name").jqxTooltip({content:"De naam voor dit vergisting profiel."});$("#inittemp_lo").jqxTooltip({content:"De minimale begin temperatuur van dit profiel."});$("#inittemp_hi").jqxTooltip({content:"De maximale begin temperatuur van dit profiel."});var e={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"name",type:"string"},{name:"inittemp_lo",type:"float"},{name:"inittemp_hi",type:"float"},{name:"fridgemode",type:"int"},{name:"totalsteps",type:"int"},{name:"duration",type:"int"},{name:"steps",type:"array"}],id:"record",url:b,deleterow:function(g,i){var h="delete=true&"+$.param({record:g});$.ajax({dataType:"json",url:b,cache:false,data:h,type:"POST",success:function(k,j,l){i(true)},error:function(j,l,k){i(false)}})},addrow:function(h,k,g,j){var i="insert=true&"+$.param(k);$.ajax({dataType:"json",url:b,cache:false,data:i,type:"POST",success:function(m,l,n){j(true)},error:function(l,n,m){j(false)}})},updaterow:function(g,j,i){var h="update=true&"+$.param(j);$.ajax({dataType:"json",url:b,cache:false,data:h,type:"POST",success:function(l,k,m){i(true)},error:function(k,m,l){i(false)}})}};var f=new $.jqx.dataAdapter(e);var a=function(j){var i=function(){var k={};k.name="Stap 1";k.steptime=12;k.resttime=24;k.target_lo=22;k.target_hi=23;k.fridgemode=0;return k};var h={localdata:j.steps,datatype:"local",datafields:[{name:"name",type:"string"},{name:"steptime",type:"float"},{name:"resttime",type:"float"},{name:"target_lo",type:"float"},{name:"target_hi",type:"float"},{name:"fridgemode",type:"int"}],addrow:function(l,n,k,m){m(true)},deleterow:function(k,l){l(true)}};var g=new $.jqx.dataAdapter(h);$("#grid").jqxGrid({width:800,height:330,source:g,theme:theme,selectionmode:"singlerow",editmode:"selectedcell",editable:true,showtoolbar:true,rendertoolbar:function(m){var l=this;var k=$("
");m.append(k);k.append('');k.append('');$("#addrowbutton").jqxButton({template:"primary",theme:theme,width:150});$("#deleterowbutton").jqxButton({template:"danger",theme:theme,width:150});$("#addrowbutton").on("click",function(){var n=i();var o=$("#grid").jqxGrid("addrow",null,n)});$("#deleterowbutton").on("click",function(){var n=$("#grid").jqxGrid("getselectedrowindex");var q=$("#grid").jqxGrid("getdatainformation").rowscount;if(n>=0&&n40){return{result:false,message:"De temperatuur moet tussen 0 en 40 zijn."}}return true}},{text:"Max. °C",datafield:"target_hi",width:100,align:"right",cellsalign:"right",cellsformat:"f1",validation:function(k,l){if(l<0||l>40){return{result:false,message:"De temperatuur moet tussen 0 en 40 zijn."}}return true}},{text:"Koelkast",datafield:"fridgemode",columntype:"checkbox",width:80},{text:"Stap tijd",datafield:"steptime",width:80,align:"right",cellsalign:"right",validation:function(k,l){if(l<0||l>14400){return{result:false,message:"De tijd moet tussen 0 en 14400 zijn."}}return true}},{text:"Rust tijd",datafield:"resttime",width:80,align:"right",cellsalign:"right",validation:function(k,l){if(l<0||l>14400){return{result:false,message:"De tijd moet tussen 0 en 14400 zijn."}}return true}}]})};$("#name").jqxInput({theme:theme,width:640,height:23});$("#inittemp_lo").jqxNumberInput(Spin1dec);$("#inittemp_lo").jqxNumberInput({max:40});$("#inittemp_hi").jqxNumberInput(Spin1dec);$("#inittemp_hi").jqxNumberInput({max:40});$("#fridgemode").jqxCheckBox({theme:theme,height:23,enableContainerClick:false});var d=-1;$("#jqxgrid").jqxGrid({width:1280,height:630,source:f,theme:theme,showstatusbar:true,renderstatusbar:function(i){var g=$("
");var h=$("
Nieuw
");g.append(h);i.append(g);h.jqxButton({theme:theme,width:90,height:20});h.click(function(j){d=-1;$("#name").val("Nieuw vergist profiel");c.uuid="";$("#inittemp_lo").val(20);$("#inittemp_hi").val(20);$("#fridgemode").val(0);c.totalsteps=0;c.duration=0;a("");$("#popupWindow").jqxWindow("open")})},filterable:false,columns:[{text:"Vergisting profiel",datafield:"name"},{text:"Min. start °C",datafield:"inittemp_lo",width:150,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Max. start °C",datafield:"inittemp_hi",width:150,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Stappen",datafield:"totalsteps",width:80,align:"right",cellsalign:"right"},{text:"Tijdsduur",datafield:"duration",width:150,align:"right",cellsrenderer:function(m,j,l,i,k){if(l<24){var h=l+" uur"}else{var n=Math.floor(l/24);var g=l%24;if(n==1){var h=n+" dag, "+g+" uur"}else{var h=n+" dagen, "+g+" uur"}}return""+h+""}},{text:"",datafield:"Edit",width:100,align:"center",columntype:"button",cellsrenderer:function(){return"Wijzig"},buttonclick:function(g){d=g;c=$("#jqxgrid").jqxGrid("getrowdata",d);$("#name").val(c.name);$("#inittemp_lo").val(parseFloat(c.inittemp_lo));$("#inittemp_hi").val(parseFloat(c.inittemp_hi));$("#fridgemode").val(parseFloat(c.fridgemode));a(c);$("#popupWindow").jqxWindow("open")}}]});$("#popupWindow").jqxWindow({width:1050,height:550,position:{x:110,y:30},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(d>=0){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var g=$("#jqxgrid").jqxGrid("getrowid",d);$("#jqxgrid").jqxGrid("deleterow",g)})}$("#popupWindow").jqxWindow("hide")});$("#Cancel").jqxButton({template:"primary",width:"90px",theme:theme});$("#Save").jqxButton({template:"success",width:"90px",theme:theme});$("#Save").click(function(){var g=$("#grid").jqxGrid("getrows");var h=-1;if(d>=0){var h=$("#jqxgrid").jqxGrid("getrowid",d)}var i={record:h,uuid:c.uuid,name:$("#name").val(),inittemp_lo:parseFloat($("#inittemp_lo").jqxNumberInput("decimal")),inittemp_hi:parseFloat($("#inittemp_hi").jqxNumberInput("decimal")),fridgemode:$("#fridgemode").val(),steps:g};if(d>=0){$("#jqxgrid").jqxGrid("updaterow",h,i)}else{$("#jqxgrid").jqxGrid("addrow",null,i)}$("#popupWindow").jqxWindow("hide");location.reload(true)});createDelElements()}); \ No newline at end of file +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(){$("#name").jqxTooltip({content:"De naam voor dit vergisting profiel."});$("#inittemp_lo").jqxTooltip({content:"De minimale begin temperatuur van dit profiel."});$("#inittemp_hi").jqxTooltip({content:"De maximale begin temperatuur van dit profiel."});var c={},b="includes/db_profile_fermentation.php",e={datatype:"json",cache:false,datafields:[{name:"record",type:"number"},{name:"uuid",type:"string"},{name:"name",type:"string"},{name:"inittemp_lo",type:"float"},{name:"inittemp_hi",type:"float"},{name:"fridgemode",type:"int"},{name:"totalsteps",type:"int"},{name:"duration",type:"int"},{name:"steps",type:"array"}],id:"record",url:b,deleterow:function(g,i){var h="delete=true&"+$.param({record:g});$.ajax({dataType:"json",url:b,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:b,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:b,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);var a=function(j){var i=function(){var k={};k.name="Stap 1";k.steptime=12;k.resttime=24;k.target_lo=22;k.target_hi=23;k.fridgemode=0;return k};var h={localdata:j.steps,datatype:"local",datafields:[{name:"name",type:"string"},{name:"steptime",type:"float"},{name:"resttime",type:"float"},{name:"target_lo",type:"float"},{name:"target_hi",type:"float"},{name:"fridgemode",type:"int"}],addrow:function(l,n,k,m){m(true)},deleterow:function(k,l){l(true)}},g=new $.jqx.dataAdapter(h);$("#grid").jqxGrid({width:800,height:330,source:g,theme:theme,selectionmode:"singlerow",editmode:"selectedcell",editable:true,showtoolbar:true,rendertoolbar:function(l){var k=$("
");l.append(k);k.append('');k.append('');$("#addrowbutton").jqxButton({template:"primary",theme:theme,width:150});$("#deleterowbutton").jqxButton({template:"danger",theme:theme,width:150});$("#addrowbutton").on("click",function(){var m=i();$("#grid").jqxGrid("addrow",null,m)});$("#deleterowbutton").on("click",function(){var m=$("#grid").jqxGrid("getselectedrowindex");var o=$("#grid").jqxGrid("getdatainformation").rowscount;if(m>=0&&m40){return{result:false,message:"De temperatuur moet tussen 0 en 40 zijn."}}return true}},{text:"Max. °C",datafield:"target_hi",width:100,align:"right",cellsalign:"right",cellsformat:"f1",validation:function(k,l){if(l<0||l>40){return{result:false,message:"De temperatuur moet tussen 0 en 40 zijn."}}return true}},{text:"Koelkast",datafield:"fridgemode",columntype:"checkbox",width:80},{text:"Stap tijd",datafield:"steptime",width:80,align:"right",cellsalign:"right",validation:function(k,l){if(l<0||l>14400){return{result:false,message:"De tijd moet tussen 0 en 14400 zijn."}}return true}},{text:"Rust tijd",datafield:"resttime",width:80,align:"right",cellsalign:"right",validation:function(k,l){if(l<0||l>14400){return{result:false,message:"De tijd moet tussen 0 en 14400 zijn."}}return true}}]})};$("#name").jqxInput({theme:theme,width:640,height:23});$("#inittemp_lo").jqxNumberInput(Spin1dec);$("#inittemp_lo").jqxNumberInput({max:40});$("#inittemp_hi").jqxNumberInput(Spin1dec);$("#inittemp_hi").jqxNumberInput({max:40});$("#fridgemode").jqxCheckBox({theme:theme,height:23,enableContainerClick:false});var d=-1;$("#jqxgrid").jqxGrid({width:1280,height:630,source:f,theme:theme,showstatusbar:true,renderstatusbar:function(i){var h,g=$("
");h=$("
Nieuw
");g.append(h);i.append(g);h.jqxButton({theme:theme,width:90,height:20});h.click(function(j){d=-1;$("#name").val("Nieuw vergist profiel");c.uuid="";$("#inittemp_lo").val(20);$("#inittemp_hi").val(20);$("#fridgemode").val(0);c.totalsteps=0;c.duration=0;a("");$("#popupWindow").jqxWindow("open")})},filterable:false,columns:[{text:"Vergisting profiel",datafield:"name"},{text:"Min. start °C",datafield:"inittemp_lo",width:150,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Max. start °C",datafield:"inittemp_hi",width:150,align:"right",cellsalign:"right",cellsformat:"f1"},{text:"Stappen",datafield:"totalsteps",width:80,align:"right",cellsalign:"right"},{text:"Tijdsduur",datafield:"duration",width:150,align:"right",cellsrenderer:function(m,j,l,i,k){var h,n,g;if(l<24){h=l+" uur"}else{n=Math.floor(l/24);g=l%24;if(n==1){h=n+" dag, "+g+" uur"}else{h=n+" dagen, "+g+" uur"}}return""+h+""}},{text:"",datafield:"Edit",width:100,align:"center",columntype:"button",cellsrenderer:function(){return"Wijzig"},buttonclick:function(g){d=g;c=$("#jqxgrid").jqxGrid("getrowdata",d);$("#name").val(c.name);$("#inittemp_lo").val(parseFloat(c.inittemp_lo));$("#inittemp_hi").val(parseFloat(c.inittemp_hi));$("#fridgemode").val(parseFloat(c.fridgemode));a(c);$("#popupWindow").jqxWindow("open")}}]});$("#popupWindow").jqxWindow({width:1050,height:550,position:{x:110,y:30},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(d>=0){$("#eventWindow").jqxWindow("open");$("#delOk").click(function(){var g=$("#jqxgrid").jqxGrid("getrowid",d);$("#jqxgrid").jqxGrid("deleterow",g)})}$("#popupWindow").jqxWindow("hide")});$("#Cancel").jqxButton({template:"primary",width:"90px",theme:theme});$("#Save").jqxButton({template:"success",width:"90px",theme:theme});$("#Save").click(function(){var i,h=-1,g=$("#grid").jqxGrid("getrows");if(d>=0){h=$("#jqxgrid").jqxGrid("getrowid",d)}i={record:h,uuid:c.uuid,name:$("#name").val(),inittemp_lo:parseFloat($("#inittemp_lo").jqxNumberInput("decimal")),inittemp_hi:parseFloat($("#inittemp_hi").jqxNumberInput("decimal")),fridgemode:$("#fridgemode").val(),steps:g};if(d>=0){$("#jqxgrid").jqxGrid("updaterow",h,i)}else{$("#jqxgrid").jqxGrid("addrow",null,i)}$("#popupWindow").jqxWindow("hide")});createDelElements()}); \ No newline at end of file diff -r e17155b3086a -r 06df1320327c www/js/profile_fermentation.js --- a/www/js/profile_fermentation.js Fri Sep 13 16:15:51 2019 +0200 +++ b/www/js/profile_fermentation.js Fri Sep 13 16:54:51 2019 +0200 @@ -44,14 +44,15 @@ $(document).ready(function () { - var dataRecord = {}; - var url = "includes/db_profile_fermentation.php"; // tooltips $("#name").jqxTooltip({ content: 'De naam voor dit vergisting profiel.' }); $("#inittemp_lo").jqxTooltip({ content: 'De minimale begin temperatuur van dit profiel.' }); $("#inittemp_hi").jqxTooltip({ content: 'De maximale begin temperatuur van dit profiel.' }); + + var dataRecord = {}, + url = 'includes/db_profile_fermentation.php', // prepare the data - var source = { + source = { datatype: "json", cache: false, datafields: [ @@ -77,8 +78,8 @@ data: data, type: "POST", success: function (data, status, xhr) { - // delete command is executed. commit(true); + location.reload( true ); }, error: function (jqXHR, textStatus, errorThrown) { commit(false); @@ -95,6 +96,7 @@ type: "POST", success: function (data, status, xhr) { commit(true); + location.reload( true ); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); @@ -110,16 +112,16 @@ data: data, type: "POST", success: function (data, status, xhr) { - // update command is executed. commit(true); + location.reload( true ); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); } }); } - }; - var dataAdapter = new $.jqx.dataAdapter(source); + }, + dataAdapter = new $.jqx.dataAdapter(source); // Inline steps editor var editsteps = function (data) { @@ -150,8 +152,8 @@ deleterow: function (rowid, commit) { commit(true); } - }; - var stepAdapter = new $.jqx.dataAdapter(stepSource); + }, + stepAdapter = new $.jqx.dataAdapter(stepSource); $("#grid").jqxGrid({ width: 800, height: 330, @@ -162,7 +164,6 @@ editable: true, showtoolbar: true, rendertoolbar: function (toolbar) { - var me = this; var container = $("
"); toolbar.append(container); container.append(''); @@ -172,7 +173,7 @@ // create new row. $("#addrowbutton").on('click', function () { var datarow = generaterow(); - var commit = $("#grid").jqxGrid('addrow', null, datarow); + $("#grid").jqxGrid('addrow', null, datarow); }); // delete row. $("#deleterowbutton").on('click', function () { @@ -180,7 +181,7 @@ var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; if (selectedrowindex >= 0 && selectedrowindex < rowscount) { var id = $("#grid").jqxGrid('getrowid', selectedrowindex); - var commit = $("#grid").jqxGrid('deleterow', id); + $("#grid").jqxGrid('deleterow', id); } }); }, @@ -240,8 +241,8 @@ theme: theme, showstatusbar: true, renderstatusbar: function (statusbar) { - var container = $("
"); - var addButton = $("
Nieuw
"); + var addButton, container = $("
"); + addButton = $("
Nieuw
"); container.append(addButton); statusbar.append(container); addButton.jqxButton({ theme: theme, width: 90, height: 20 }); @@ -267,21 +268,23 @@ { text: 'Stappen', datafield: 'totalsteps', width: 80, align: 'right', cellsalign: 'right' }, { text: 'Tijdsduur', datafield: 'duration', width: 150, align: 'right', cellsrenderer: function (row, columnfield, value, defaulthtml, column) { + var show, days, hours; if (value < 24) { - var show = value+" uur"; + show = value + ' uur'; } else { - var days = Math.floor(value / 24); - var hours = value % 24; + days = Math.floor(value / 24); + hours = value % 24; if (days == 1) - var show = days+" dag, "+hours+" uur"; + show = days + ' dag, ' + hours + ' uur'; else - var show = days+" dagen, "+hours+" uur"; + show = days + ' dagen, ' + hours + ' uur'; } - return ""+show+""; + return "" + show + ""; } }, - { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () { - return "Wijzig"; + { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: + function () { + return "Wijzig"; }, buttonclick: function (row) { editrow = row; // get the clicked row's data and initialize the input fields. @@ -328,12 +331,11 @@ $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); // update the edited row when the user clicks the 'Save' button. $("#Save").click(function () { - var steprows = $('#grid').jqxGrid('getrows'); - var rowID = -1; + var row, rowID = -1, steprows = $('#grid').jqxGrid('getrows'); if (editrow >= 0) { - var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); + rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); } - var row = { + row = { record: rowID, uuid: dataRecord.uuid, name: $("#name").val(), @@ -348,7 +350,6 @@ $('#jqxgrid').jqxGrid('addrow', null, row); } $("#popupWindow").jqxWindow('hide'); - location.reload( true ); // reload ourself. }); createDelElements(); });