diff -r 06df1320327c -r 77f1617b6994 www/js/inv_waters.js --- a/www/js/inv_waters.js Fri Sep 13 16:54:51 2019 +0200 +++ b/www/js/inv_waters.js Fri Sep 13 20:24:31 2019 +0200 @@ -44,9 +44,6 @@ $(document).ready(function () { - var dataRecord = {}; - - var url = "includes/db_inventory_water.php"; // tooltips $("#name").jqxTooltip({ content: 'De unieke naam van dit brouwwater.' }); $("#notes").jqxTooltip({ content: 'Extra opmerkingen over dit water.' }); @@ -61,8 +58,11 @@ $("#total_alkalinity").jqxTooltip({ content: 'Totale alkaliniteit. Berekend meteen de Bicarbonaat.' }); $("#inventory").jqxTooltip({ content: 'Voorraad in liters.' }); $("#cost").jqxTooltip({ content: 'Kostprijs per liter. 5 cijfers achter de comma zodat het kraanwater er ook in kan.' }); + + var dataRecord = {}, + url = 'includes/db_inventory_water.php', // prepare the data - var source = { + source = { datatype: "json", cache: false, datafields: [ @@ -93,8 +93,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); @@ -111,6 +111,7 @@ type: "POST", success: function (data, status, xhr) { commit(true); + location.reload( true ); }, error: function(jqXHR, textStatus, errorThrown) { commit(false); @@ -126,15 +127,18 @@ 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); } }); } - }; + }, + dataAdapter = new $.jqx.dataAdapter(source), + editrow = -1; + // initialize the input fields. $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); @@ -149,8 +153,7 @@ $("#total_alkalinity").jqxNumberInput( Spin1dec ); $("#inventory").jqxNumberInput( Spin1dec ); $("#cost").jqxNumberInput({inputMode: 'simple', theme: theme, width: 110, height: 23, min: 0, decimalDigits: 5, spinButtons: true }); - var dataAdapter = new $.jqx.dataAdapter(source); - var editrow = -1; + // initialize jqxGrid $("#jqxgrid").jqxGrid({ width: 1280, @@ -159,8 +162,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 }); @@ -197,14 +200,15 @@ return "" + amount + ""; } }, - { 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) { // open the popup window when the user clicks a button. editrow = row; $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); // get the clicked row's data and initialize the input fields. - var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); + dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); $("#name").val(dataRecord.name); $("#unlimited_stock").val(dataRecord.unlimited_stock); $("#calcium").val(dataRecord.calcium); @@ -264,11 +268,11 @@ $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); // update the edited row when the user clicks the 'Save' button. $("#Save").click(function () { - var rowID = -1; + var row, rowID = -1; if (editrow >= 0) { - var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); + rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); } - var row = { + row = { record: rowID, name: $("#name").val(), unlimited_stock: $("#unlimited_stock").val(), @@ -290,7 +294,6 @@ $('#jqxgrid').jqxGrid('addrow', null, row); } $("#popupWindow").jqxWindow('hide'); - location.reload( true ); // reload ourself. }); createDelElements(); });