diff -r 9362eb9e9e5b -r b7d44c98d609 www/js/inv_mash_profiles.js --- a/www/js/inv_mash_profiles.js Sat Aug 25 13:07:13 2018 +0200 +++ b/www/js/inv_mash_profiles.js Mon Aug 27 22:58:20 2018 +0200 @@ -26,7 +26,7 @@ theme: theme, position: { x: 490, y: 210 }, width: 300, - height: 145, + height: 175, resizable: false, isModal: true, modalOpacity: 0.4, @@ -52,7 +52,13 @@ { name: 'record', type: 'number' }, { name: 'name', type: 'string' }, { name: 'notes', type: 'string' }, - { name: 'steps', type: 'string' } + { name: 'steps', type: 'array' } + // { name: 'step_name', type: 'string', map: 'steps>step_name' }, + // { name: 'step_type', type: 'string', map: 'steps>step_type' }, + // { name: 'step_temp', type: 'float', map: 'steps>step_temp' }, + // { name: 'step_time', type: 'float', map: 'steps>step_time' }, + // { name: 'tamp_time', type: 'float', map: 'steps>ramp_time' }, + // { name: 'end_temp', type: 'float', map: 'steps>end_temp' } ], id: 'record', url: url, @@ -105,10 +111,107 @@ }); } }; + var dataAdapter = new $.jqx.dataAdapter(source); + + var editsteps = function (data) { + var generaterow = function () { + var row = {}; + row["step_name"] = "Stap 1"; + row["step_type"] = "Infusion"; + row["step_temp"] = 62.0; + row['step_time'] = 20.0; + row['ramp_time'] = 1.0; + row['end_temp'] = 62.0; + return row; + } + var stepSource = { + localdata: data.steps, + datatype: "local", + datafields: [ + { name: 'step_name', type: 'string' }, + { name: 'step_type', type: 'string' }, + { name: 'step_temp', type: 'float' }, + { name: 'step_time', type: 'float' }, + { name: 'ramp_time', type: 'float' }, + { name: 'end_temp', type: 'float' } + ], + addrow: function (rowid, rowdata, position, commit) { + // synchronize with the server - send insert command + // call commit with parameter true if the synchronization with the server is successful + //and with parameter false if the synchronization failed. + // you can pass additional argument to the commit callback which represents the new ID if it is generated from a DB. + commit(true); + }, + deleterow: function (rowid, commit) { + // synchronize with the server - send delete command + // call commit with parameter true if the synchronization with the server is successful + //and with parameter false if the synchronization failed. + commit(true); + }, + updaterow: function (rowid, newdata, commit) { + // synchronize with the server - send update command + // call commit with parameter true if the synchronization with the server is successful + // and with parameter false if the synchronization failed. + commit(true); + } + }; + var stepAdapter = new $.jqx.dataAdapter(stepSource); + $("#grid").jqxGrid({ + width: 640, + height: 330, + source: stepAdapter, + theme: theme, + showtoolbar: true, + rendertoolbar: function (toolbar) { + var me = this; + var container = $("
"); + toolbar.append(container); + container.append(''); + container.append(''); + container.append(''); + $("#addrowbutton").jqxButton({ theme: theme }); + $("#deleterowbutton").jqxButton({ theme: theme }); + $("#updaterowbutton").jqxButton({ theme: theme }); + // update row. + $("#updaterowbutton").on('click', function () { + var datarow = generaterow(); + var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); + var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; + if (selectedrowindex >= 0 && selectedrowindex < rowscount) { + var id = $("#grid").jqxGrid('getrowid', selectedrowindex); + var commit = $("#grid").jqxGrid('updaterow', id, datarow); + $("#grid").jqxGrid('ensurerowvisible', selectedrowindex); + } + }); + // create new row. + $("#addrowbutton").on('click', function () { + var datarow = generaterow(); + var commit = $("#grid").jqxGrid('addrow', null, datarow); + }); + // delete row. + $("#deleterowbutton").on('click', function () { + var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); + var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; + if (selectedrowindex >= 0 && selectedrowindex < rowscount) { + var id = $("#grid").jqxGrid('getrowid', selectedrowindex); + var commit = $("#grid").jqxGrid('deleterow', id); + } + }); + }, + columns: [ + { text: 'Stap naam', datafield: 'step_name' }, + { text: 'Stap type', datafield: 'step_type', width: 100 }, + { text: 'Temperatuur', datafield: 'step_temp', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Eind', datafield: 'end_temp', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, + { text: 'Tijd', datafield: 'step_time', width: 70, align: 'right', cellsalign: 'right' }, + { text: 'Stap', datafield: 'ramp_time', width: 70, align: 'right', cellsalign: 'right' } + ] + }); + }; + // initialize the input fields. $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); - var dataAdapter = new $.jqx.dataAdapter(source); var editrow = -1; // initialize jqxGrid $("#jqxgrid").jqxGrid({ @@ -123,13 +226,14 @@ var addButton = $("