www/js/profile_mash.js

changeset 796
6ce2c2e6796e
parent 795
9472106a3143
child 797
d0fedeb32f05
equal deleted inserted replaced
795:9472106a3143 796:6ce2c2e6796e
1 /*****************************************************************************
2 * Copyright (C) 2014-2022
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of Brewery Management System
7 *
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
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * BrewCloud is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23
24 function createDelElements() {
25 $('#eventWindow').jqxWindow({
26 theme: theme,
27 position: { x: 490, y: 210 },
28 width: 300,
29 height: 175,
30 resizable: false,
31 isModal: true,
32 modalOpacity: 0.4,
33 okButton: $('#delOk'),
34 cancelButton: $('#delCancel'),
35 initContent: function() {
36 $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
37 $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
38 $('#delCancel').focus();
39 }
40 });
41 $('#eventWindow').jqxWindow('hide');
42 }
43
44
45 $(document).ready(function() {
46
47 // tooltips
48 $('#name').jqxTooltip({ content: 'De naam voor dit maisch profiel.' });
49 $('#notes').jqxTooltip({ content: 'De uitgebreide opmerkingen over dit maisch profiel.' });
50
51 var steprow = 0,
52 stepData = {},
53 dataRecord = {},
54 url = 'includes/db_profile_mash.php',
55 source = {
56 datatype: 'json',
57 cache: false,
58 datafields: [
59 { name: 'record', type: 'number' },
60 { name: 'name', type: 'string' },
61 { name: 'notes', type: 'string' },
62 { name: 'steps', type: 'array' },
63 { name: 'uuid', type: 'string' }
64 ],
65 id: 'record',
66 url: url,
67 deleterow: function(rowid, commit) {
68 var data = 'delete=true&' + $.param({ record: rowid });
69 $.ajax({
70 dataType: 'json',
71 url: url,
72 cache: false,
73 data: data,
74 type: 'POST',
75 success: function(data) {
76 if (data.error) {
77 console.log('delete: ' + data.msg);
78 alert('Fout: ' + data.msg);
79 } else {
80 console.log('delete: success');
81 }
82 location.reload(true);
83 },
84 error: function(jqXHR, textStatus, errorThrown) {
85 commit(false);
86 console.log('mash deleterow ' + textStatus);
87 }
88 });
89 },
90 addrow: function(rowid, rowdata, position, commit) {
91 var data = 'insert=true&' + $.param(rowdata);
92 $.ajax({
93 dataType: 'json',
94 url: url,
95 cache: false,
96 data: data,
97 type: 'POST',
98 success: function(data) {
99 if (data.error) {
100 console.log('insert: ' + data.msg);
101 alert('Fout: ' + data.msg);
102 } else {
103 console.log('insert: success');
104 }
105 location.reload(true);
106 },
107 error: function(jqXHR, textStatus, errorThrown) {
108 commit(false);
109 console.log('mash addrow ' + textStatus);
110 }
111 });
112 },
113 updaterow: function(rowid, rowdata, commit) {
114 var data = 'update=true&' + $.param(rowdata);
115 $.ajax({
116 dataType: 'json',
117 url: url,
118 cache: false,
119 data: data,
120 type: 'POST',
121 success: function(data) {
122 if (data.error) {
123 console.log('updaterow: ' + data.msg);
124 alert('Fout: ' + data.msg);
125 } else {
126 console.log('updaterow: success');
127 }
128 location.reload(true);
129 },
130 error: function(jqXHR, textStatus, errorThrown) {
131 commit(false);
132 console.log('mash updaterow ' + textStatus);
133 }
134 });
135 }
136 },
137 dataAdapter = new $.jqx.dataAdapter(source),
138 editrow = -1,
139
140 // Inline steps editor
141 editsteps = function(data) {
142 var stepSource = {
143 localdata: data.steps,
144 datatype: 'local',
145 datafields: [
146 { name: 'step_name', type: 'string' },
147 { name: 'step_type', type: 'int' },
148 { name: 'step_temp', type: 'float' },
149 { name: 'step_time', type: 'float' },
150 { name: 'ramp_time', type: 'float' },
151 { name: 'end_temp', type: 'float' }
152 ],
153 addrow: function(rowid, rowdata, position, commit) { commit(true); },
154 deleterow: function(rowid, commit) { commit(true); }
155 },
156 stepAdapter = new $.jqx.dataAdapter(stepSource);
157
158 $('#grid').jqxGrid({
159 width: 1020,
160 height: 330,
161 source: stepAdapter,
162 theme: theme,
163 selectionmode: 'singlerow',
164 showtoolbar: true,
165 rendertoolbar: function(toolbar) {
166 var container = $('<div style="margin: 5px;"></div>');
167 toolbar.append(container);
168 container.append('<input style="margin-left: 100px;" id="addrowbutton" type="button" value="Nieuwe stap" />');
169 container.append('<input style="margin-left: 450px;" id="deleterowbutton" type="button" value="Verwijder stap" />');
170 $('#addrowbutton').jqxButton({ template: 'primary', theme: theme, width: 150 });
171 $('#deleterowbutton').jqxButton({ template: 'danger', theme: theme, width: 150 });
172 // create new row.
173 $('#addrowbutton').on('click', function() {
174 var row = {}, rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
175 var temp = $('#grid').jqxGrid('getcell', rowscount -1, 'step_temp');
176 row['step_name'] = 'Stap ' + (rowscount + 1);
177 if (rowscount > 0) {
178 row['step_type'] = 1;
179 row['step_temp'] = row['end_temp'] = temp.value + 2;
180 } else {
181 row['step_type'] = 0;
182 row['step_temp'] = row['end_temp'] = 62.0;
183 }
184 row['step_time'] = 20.0;
185 row['ramp_time'] = 1.0;
186 $('#grid').jqxGrid('addrow', null, row);
187 });
188 // delete row.
189 $('#deleterowbutton').on('click', function() {
190 var rowscount, id, selectedrowindex = $('#grid').jqxGrid('getselectedrowindex');
191 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
192 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
193 id = $('#grid').jqxGrid('getrowid', selectedrowindex);
194 $('#grid').jqxGrid('deleterow', id);
195 }
196 });
197 },
198 columns: [
199 { text: 'Stap naam', datafield: 'step_name' },
200 { text: 'Stap type', datafield: 'step_type', width: 150,
201 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) {
202 return '<span style="margin: 4px; margin-top: 6px; float: left;">' + MashStepTypeData[value].nl + '</span>';
203 }
204 },
205 { text: 'Start &deg;C', datafield: 'step_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
206 { text: 'Eind &deg;C', datafield: 'end_temp', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
207 { text: 'Rust min.', datafield: 'step_time', width: 90, align: 'right', cellsalign: 'right' },
208 { text: 'Stap min.', datafield: 'ramp_time', width: 90, align: 'right', cellsalign: 'right' },
209 { text: '', columntype: 'button', width: 15, align: 'center',
210 cellsrenderer: function(row) {
211 if (row < 2)
212 return ' ';
213 return '▴';
214 }, buttonclick: function(row) {
215 if (row >= 2) {
216 swapMash(row, row-1);
217 }
218 }
219 },
220 { text: '', columntype: 'button', width: 15, align: 'center',
221 cellsrenderer: function(row) {
222 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
223 if (row < 1 || row > (rowscount -2))
224 return ' ';
225 return '▾';
226 }, buttonclick: function(row) {
227 rowscount = $('#grid').jqxGrid('getdatainformation').rowscount;
228 if (row >= 1 && row <= (rowscount -2)) {
229 swapMash(row, row+1);
230 }
231 }
232 },
233 { text: '', datafield: 'Edit', columntype: 'button', width: 80, align: 'center',
234 cellsrenderer: function() {
235 return 'Wijzig';
236 }, buttonclick: function(row) {
237 steprow = row;
238 stepData = $('#grid').jqxGrid('getrowdata', steprow);
239 $('#m_step_name').val(stepData.step_name);
240 $('#m_step_type').val(stepData.step_type);
241 $('#m_step_temp').val(stepData.step_temp);
242 $('#m_end_temp').val(stepData.end_temp);
243 $('#m_step_time').val(stepData.step_time);
244 $('#m_ramp_time').val(stepData.ramp_time);
245 // show the popup window.
246 $('#popupStep').jqxWindow('open');
247 }
248 }
249 ]
250 });
251 };
252
253 // Initialize the input fields.
254 $('#m_step_name').jqxInput({ theme: theme, width: 320, height: 23 });
255 $('#m_step_type').jqxDropDownList({
256 theme: theme,
257 source: MashStepTypeAdapter,
258 valueMember: 'id',
259 displayMember: 'nl',
260 width: 180,
261 height: 23,
262 autoDropDownHeight: true
263 });
264 $('#m_step_temp').jqxNumberInput(Spin1dec);
265 $('#m_step_temp').jqxNumberInput({ Min: 30, Max: 80 });
266 $('#m_end_temp').jqxNumberInput(Spin1dec);
267 $('#m_end_temp').jqxNumberInput({ Min: 30, Max: 80 });
268 $('#m_step_time').jqxNumberInput(PosInt);
269 $('#m_step_time').jqxNumberInput({ Min: 1, Max: 120 });
270 $('#m_ramp_time').jqxNumberInput(PosInt);
271 $('#m_ramp_time').jqxNumberInput({ Min: 1, Max: 30 });
272
273 // initialize the input fields.
274 $('#name').jqxInput({ theme: theme, width: 480, height: 23 });
275 $('#notes').jqxInput({ theme: theme, width: 800, height: 100 });
276
277 var localizationobj = {};
278 localizationobj.filterchoosestring= "Keuze:";
279
280 // initialize jqxGrid
281 $('#jqxgrid').jqxGrid({
282 width: 1280,
283 height: 630,
284 source: dataAdapter,
285 theme: theme,
286 showstatusbar: true,
287 renderstatusbar: function(statusbar) {
288 var rowCount = $("#jqxgrid").jqxGrid('getrows').length;
289 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>');
290 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
291 var addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
292 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Add</span></div>');
293 var expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
294 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -10px;">Export</span></div>');
295 container.append(addButton);
296 container.append(expButton);
297 statusbar.append(container);
298 addButton.jqxButton({ theme: theme, width: 90, height: 17 });
299 expButton.jqxButton({ theme: theme, width: 90, height: 17 });
300 // add new row.
301 addButton.click(function(event) {
302 editrow = -1;
303 $('#name').val('Nieuw maisch schema');
304 $('#notes').val('');
305 dataRecord.uuid = '';
306 editsteps('');
307 $('#popupWindow').jqxWindow('open');
308 });
309 expButton.click(function(event) {
310 window.open('export_mashs.php');
311 });
312 },
313 ready: function () {
314 $("#jqxgrid").jqxGrid('localizestrings', localizationobj);
315 },
316 filterable: true,
317 showfilterrow: true,
318 columns: [
319 { text: 'Maish schema', datafield: 'name', width: 250, filtertype: 'textbox' },
320 { text: 'Opmerkingen', datafield: 'notes', filtertype: 'textbox' },
321 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', filterable: false,
322 cellsrenderer: function() {
323 return 'Wijzig';
324 }, buttonclick: function(row) {
325 editrow = row;
326 // get the clicked row's data and initialize the input fields.
327 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
328 $('#name').val(dataRecord.name);
329 $('#notes').val(dataRecord.notes);
330 editsteps(dataRecord);
331 // show the popup window.
332 $('#popupWindow').jqxWindow('open');
333 }
334 }
335 ]
336 });
337 // initialize the popup window and buttons.
338 $('#popupWindow').jqxWindow({
339 width: 1050,
340 height: 580,
341 position: { x: 110, y: 30 },
342 resizable: false,
343 theme: theme,
344 isModal: true,
345 autoOpen: false,
346 cancelButton: $('#Cancel'),
347 modalOpacity: 0.40
348 });
349 $('#popupWindow').on('open', function() {
350 $('#name').jqxInput('selectAll');
351 });
352 $('#popupStep').jqxWindow({
353 width: 800,
354 height: 300,
355 position: { x: 230, y: 100 },
356 resizable: false,
357 theme: theme,
358 isModal: true,
359 autoOpen: false,
360 cancelButton: $('#Ready'),
361 modalOpacity: 0.40
362 });
363
364 // step detail popup update values.
365 $('#Ready').jqxButton({ template: 'success', width: '90px', theme: theme });
366 $('#Ready').click(function() {
367 $('#grid').jqxGrid('setcellvalue', steprow, 'step_name', $('#m_step_name').val());
368 $('#grid').jqxGrid('setcellvalue', steprow, 'step_type', $('#m_step_type').val());
369 $('#grid').jqxGrid('setcellvalue', steprow, 'step_temp', $('#m_step_temp').val());
370 $('#grid').jqxGrid('setcellvalue', steprow, 'end_temp', $('#m_end_temp').val());
371 $('#grid').jqxGrid('setcellvalue', steprow, 'step_time', $('#m_step_time').val());
372 $('#grid').jqxGrid('setcellvalue', steprow, 'ramp_time', $('#m_ramp_time').val());
373 $('#grid').jqxGrid('sortby', 'step_temp', 'asc');
374 });
375
376 // mash profile popup.
377 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
378 $('#Delete').click(function() {
379 if (editrow >= 0) {
380 // Open a popup to confirm this action.
381 $('#eventWindow').jqxWindow('open');
382 $('#delOk').click(function() {
383 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
384 $('#jqxgrid').jqxGrid('deleterow', rowID);
385 });
386 }
387 $('#popupWindow').jqxWindow('hide');
388 });
389 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
390 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
391 $('#Save').click(function() {
392 var steprows = $('#grid').jqxGrid('getrows'),
393 rowID = -1,
394 row;
395 if (editrow >= 0) {
396 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
397 }
398 row = {
399 record: rowID,
400 uuid: dataRecord.uuid,
401 name: $('#name').val(),
402 notes: $('#notes').val(),
403 steps: steprows
404 };
405 if (editrow >= 0) {
406 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
407 } else {
408 $('#jqxgrid').jqxGrid('addrow', null, row);
409 }
410 $('#popupWindow').jqxWindow('hide');
411 });
412
413 function swapMash(r1, r2) {
414
415 console.log('swap mash rows ' + r1 + ' ' + r2);
416 var row1 = $('#grid').jqxGrid('getrowdata', r1);
417 var row2 = $('#grid').jqxGrid('getrowdata', r2);
418 var obj1 = { step_name: row1.step_name, step_type: row1.step_type, step_temp: row1.step_temp, step_time: row1.step_time,
419 ramp_time: row1.ramp_time, end_temp: row1.end_temp };
420 var obj2 = { step_name: row2.step_name, step_type: row2.step_type, step_temp: row2.step_temp, step_time: row2.step_time,
421 ramp_time: row2.ramp_time, end_temp: row2.end_temp };
422 $("#grid").jqxGrid('updaterow', r1, obj2);
423 $("#grid").jqxGrid('updaterow', r2, obj1);
424 }
425
426 createDelElements();
427 });
428

mercurial