www/js/profile_mash.js

changeset 688
0ce464e42d8b
parent 563
acdd54144838
child 701
3ce3df681be0
equal deleted inserted replaced
687:93ea9572c780 688:0ce464e42d8b
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2014-2019 2 * Copyright (C) 2014-2020
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of BrewCloud 6 * This file is part of Brewery Management System
7 * 7 *
8 * This is free software; you can redistribute it and/or modify it 8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any 10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version. 11 * later version.
71 cache: false, 71 cache: false,
72 data: data, 72 data: data,
73 type: 'POST', 73 type: 'POST',
74 success: function(data, status, xhr) { 74 success: function(data, status, xhr) {
75 commit(true); 75 commit(true);
76 console.log('mash deleterow ' + rowid + ' success');
77 location.reload(true); 76 location.reload(true);
78 }, 77 },
79 error: function(jqXHR, textStatus, errorThrown) { 78 error: function(jqXHR, textStatus, errorThrown) {
80 commit(false); 79 commit(false);
81 console.log('mash deleterow ' + textStatus); 80 console.log('mash deleterow ' + textStatus);
90 cache: false, 89 cache: false,
91 data: data, 90 data: data,
92 type: 'POST', 91 type: 'POST',
93 success: function(data, status, xhr) { 92 success: function(data, status, xhr) {
94 commit(true); 93 commit(true);
95 console.log('mash addrow ' + rowid + ' success');
96 location.reload(true); 94 location.reload(true);
97 }, 95 },
98 error: function(jqXHR, textStatus, errorThrown) { 96 error: function(jqXHR, textStatus, errorThrown) {
99 commit(false); 97 commit(false);
100 console.log('mash addrow ' + textStatus); 98 console.log('mash addrow ' + textStatus);
109 cache: false, 107 cache: false,
110 data: data, 108 data: data,
111 type: 'POST', 109 type: 'POST',
112 success: function(data, status, xhr) { 110 success: function(data, status, xhr) {
113 commit(true); 111 commit(true);
114 console.log('mash updaterow ' + rowid + ' success');
115 location.reload(true); 112 location.reload(true);
116 }, 113 },
117 error: function(jqXHR, textStatus, errorThrown) { 114 error: function(jqXHR, textStatus, errorThrown) {
118 commit(false); 115 commit(false);
119 console.log('mash updaterow ' + textStatus); 116 console.log('mash updaterow ' + textStatus);
124 dataAdapter = new $.jqx.dataAdapter(source), 121 dataAdapter = new $.jqx.dataAdapter(source),
125 editrow = -1, 122 editrow = -1,
126 123
127 // Inline steps editor 124 // Inline steps editor
128 editsteps = function(data) { 125 editsteps = function(data) {
129 var generaterow = function() {
130 var row = {};
131 row['step_name'] = 'Stap 1';
132 row['step_type'] = 0;
133 row['step_temp'] = 62.0;
134 row['step_time'] = 20.0;
135 row['ramp_time'] = 1.0;
136 row['end_temp'] = 62.0;
137 return row;
138 };
139 var stepSource = { 126 var stepSource = {
140 localdata: data.steps, 127 localdata: data.steps,
141 datatype: 'local', 128 datatype: 'local',
142 datafields: [ 129 datafields: [
143 { name: 'step_name', type: 'string' }, 130 { name: 'step_name', type: 'string' },
145 { name: 'step_temp', type: 'float' }, 132 { name: 'step_temp', type: 'float' },
146 { name: 'step_time', type: 'float' }, 133 { name: 'step_time', type: 'float' },
147 { name: 'ramp_time', type: 'float' }, 134 { name: 'ramp_time', type: 'float' },
148 { name: 'end_temp', type: 'float' } 135 { name: 'end_temp', type: 'float' }
149 ], 136 ],
150 addrow: function(rowid, rowdata, position, commit) { 137 addrow: function(rowid, rowdata, position, commit) { commit(true); },
151 commit(true); 138 deleterow: function(rowid, commit) { commit(true); }
152 },
153 deleterow: function(rowid, commit) {
154 commit(true);
155 }
156 }, 139 },
157 stepAdapter = new $.jqx.dataAdapter(stepSource); 140 stepAdapter = new $.jqx.dataAdapter(stepSource);
158 141
159 $('#grid').jqxGrid({ 142 $('#grid').jqxGrid({
160 width: 1020, 143 width: 1020,
170 container.append('<input style="margin-left: 450px;" id="deleterowbutton" type="button" value="Verwijder stap" />'); 153 container.append('<input style="margin-left: 450px;" id="deleterowbutton" type="button" value="Verwijder stap" />');
171 $('#addrowbutton').jqxButton({ template: 'primary', theme: theme, width: 150 }); 154 $('#addrowbutton').jqxButton({ template: 'primary', theme: theme, width: 150 });
172 $('#deleterowbutton').jqxButton({ template: 'danger', theme: theme, width: 150 }); 155 $('#deleterowbutton').jqxButton({ template: 'danger', theme: theme, width: 150 });
173 // create new row. 156 // create new row.
174 $('#addrowbutton').on('click', function() { 157 $('#addrowbutton').on('click', function() {
175 var datarow = generaterow(); 158 var row = {}, rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
176 $('#grid').jqxGrid('addrow', null, datarow); 159 var temp = $('#grid').jqxGrid('getcell', rowscount -1, 'step_temp');
160 row['step_name'] = 'Stap ' + (rowscount + 1);
161 if (rowscount > 0) {
162 row['step_type'] = 1;
163 row['step_temp'] = row['end_temp'] = temp.value + 2;
164 } else {
165 row['step_type'] = 0;
166 row['step_temp'] = row['end_temp'] = 62.0;
167 }
168 row['step_time'] = 20.0;
169 row['ramp_time'] = 1.0;
170 $('#grid').jqxGrid('addrow', null, row);
177 }); 171 });
178 // delete row. 172 // delete row.
179 $('#deleterowbutton').on('click', function() { 173 $('#deleterowbutton').on('click', function() {
180 var rowscount, id, selectedrowindex = $('#grid').jqxGrid('getselectedrowindex'); 174 var rowscount, id, selectedrowindex = $('#grid').jqxGrid('getselectedrowindex');
181 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount; 175 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
187 }, 181 },
188 columns: [ 182 columns: [
189 { text: 'Stap naam', datafield: 'step_name' }, 183 { text: 'Stap naam', datafield: 'step_name' },
190 { text: 'Stap type', datafield: 'step_type', width: 150, 184 { text: 'Stap type', datafield: 'step_type', width: 150,
191 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { 185 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
192 return '<div style="margin: 4px;">' + MashStepTypeData[value].nl + '</div>'; 186 return '<span style="margin: 4px; margin-top: 6px; float: left;">' + MashStepTypeData[value].nl + '</span>';
193 } 187 }
194 }, 188 },
195 { text: 'Begin &deg;C', datafield: 'step_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, 189 { text: 'Start &deg;C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
196 { text: 'Eind &deg;C', datafield: 'end_temp', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, 190 { text: 'Eind &deg;C', datafield: 'end_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
197 { text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' }, 191 { text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' },
198 { text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' }, 192 { text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' },
199 { text: '', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', 193 { text: '', columntype: 'button', width: 15, align: 'center',
194 cellsrenderer: function(row) {
195 if (row < 2)
196 return ' ';
197 return '▴';
198 }, buttonclick: function(row) {
199 if (row >= 2) {
200 swapMash(row, row-1);
201 }
202 }
203 },
204 { text: '', columntype: 'button', width: 15, align: 'center',
205 cellsrenderer: function(row) {
206 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
207 if (row < 1 || row > (rowscount -2))
208 return ' ';
209 return '▾';
210 }, buttonclick: function(row) {
211 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
212 if (row >= 1 && row <= (rowscount -2)) {
213 swapMash(row, row+1);
214 }
215 }
216 },
217 { text: '', datafield: 'Edit', columntype: 'button', width: 80, align: 'center',
200 cellsrenderer: function() { 218 cellsrenderer: function() {
201 return 'Wijzig'; 219 return 'Wijzig';
202 }, buttonclick: function(row) { 220 }, buttonclick: function(row) {
203 steprow = row; 221 steprow = row;
204 stepData = $('#grid').jqxGrid('getrowdata', steprow); 222 stepData = $('#grid').jqxGrid('getrowdata', steprow);
245 height: 630, 263 height: 630,
246 source: dataAdapter, 264 source: dataAdapter,
247 theme: theme, 265 theme: theme,
248 showstatusbar: true, 266 showstatusbar: true,
249 renderstatusbar: function(statusbar) { 267 renderstatusbar: function(statusbar) {
250 var addButton, container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); 268 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
251 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' + 269 var addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
252 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Add</span></div>'); 270 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Add</span></div>');
253 expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' + 271 var expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
254 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Export</span></div>'); 272 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Export</span></div>');
255 container.append(addButton); 273 container.append(addButton);
256 container.append(expButton); 274 container.append(expButton);
257 statusbar.append(container); 275 statusbar.append(container);
258 addButton.jqxButton({ theme: theme, width: 90, height: 20 }); 276 addButton.jqxButton({ theme: theme, width: 90, height: 20 });
267 }); 285 });
268 expButton.click(function(event) { 286 expButton.click(function(event) {
269 window.open('export_mashs.php'); 287 window.open('export_mashs.php');
270 }); 288 });
271 }, 289 },
272 filterable: true,
273 filtermode: 'excel',
274 columns: [ 290 columns: [
275 { text: 'Maish schema', datafield: 'name', width: 250 }, 291 { text: 'Maish schema', datafield: 'name', width: 250 },
276 { text: 'Opmerkingen', datafield: 'notes' }, 292 { text: 'Opmerkingen', datafield: 'notes' },
277 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', 293 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button',
278 cellsrenderer: function() { 294 cellsrenderer: function() {
362 } else { 378 } else {
363 $('#jqxgrid').jqxGrid('addrow', null, row); 379 $('#jqxgrid').jqxGrid('addrow', null, row);
364 } 380 }
365 $('#popupWindow').jqxWindow('hide'); 381 $('#popupWindow').jqxWindow('hide');
366 }); 382 });
383
384 function swapMash(r1, r2) {
385
386 console.log('swap mash rows ' + r1 + ' ' + r2);
387 var row1 = $('#grid').jqxGrid('getrowdata', r1);
388 var row2 = $('#grid').jqxGrid('getrowdata', r2);
389 var obj1 = { step_name: row1.step_name, step_type: row1.step_type, step_temp: row1.step_temp, step_time: row1.step_time,
390 ramp_time: row1.ramp_time, end_temp: row1.end_temp };
391 var obj2 = { step_name: row2.step_name, step_type: row2.step_type, step_temp: row2.step_temp, step_time: row2.step_time,
392 ramp_time: row2.ramp_time, end_temp: row2.end_temp };
393 $("#grid").jqxGrid('updaterow', r1, obj2);
394 $("#grid").jqxGrid('updaterow', r2, obj1);
395 }
396
367 createDelElements(); 397 createDelElements();
368 }); 398 });
369 399

mercurial