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 var dataRecord = {}, |
|
48 url = 'includes/db_profile_water.php', |
|
49 source = { |
|
50 datatype: 'json', |
|
51 cache: false, |
|
52 datafields: [ |
|
53 { name: 'record', type: 'number' }, |
|
54 { name: 'uuid', type: 'string' }, |
|
55 { name: 'name', type: 'string' }, |
|
56 { name: 'calcium', type: 'float' }, |
|
57 { name: 'bicarbonate', type: 'float' }, |
|
58 { name: 'sulfate', type: 'float' }, |
|
59 { name: 'chloride', type: 'float' }, |
|
60 { name: 'sodium', type: 'float' }, |
|
61 { name: 'magnesium', type: 'float' }, |
|
62 { name: 'ph', type: 'float' }, |
|
63 { name: 'notes', type: 'string' }, |
|
64 { name: 'total_alkalinity', type: 'float' } |
|
65 ], |
|
66 id: 'record', |
|
67 url: url, |
|
68 deleterow: function(rowid, commit) { |
|
69 // synchronize with the server - send delete command |
|
70 var data = 'delete=true&' + $.param({ record: rowid }); |
|
71 $.ajax({ |
|
72 dataType: 'json', |
|
73 url: url, |
|
74 cache: false, |
|
75 data: data, |
|
76 type: 'POST', |
|
77 success: function(data) { |
|
78 if (data.error) { |
|
79 console.log('delete: ' + data.msg); |
|
80 alert('Fout: ' + data.msg); |
|
81 } else { |
|
82 console.log('delete: success'); |
|
83 } |
|
84 location.reload(true); |
|
85 }, |
|
86 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
87 }); |
|
88 }, |
|
89 addrow: function(rowid, rowdata, position, commit) { |
|
90 var data = 'insert=true&' + $.param(rowdata); |
|
91 $.ajax({ |
|
92 dataType: 'json', |
|
93 url: url, |
|
94 cache: false, |
|
95 data: data, |
|
96 type: 'POST', |
|
97 success: function(data) { |
|
98 if (data.error) { |
|
99 console.log('insert: ' + data.msg); |
|
100 alert('Fout: ' + data.msg); |
|
101 } else { |
|
102 console.log('insert: success'); |
|
103 } |
|
104 location.reload(true); |
|
105 }, |
|
106 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
107 }); |
|
108 }, |
|
109 updaterow: function(rowid, rowdata, commit) { |
|
110 var data = 'update=true&' + $.param(rowdata); |
|
111 $.ajax({ |
|
112 dataType: 'json', |
|
113 url: url, |
|
114 cache: false, |
|
115 data: data, |
|
116 type: 'POST', |
|
117 success: function(data) { |
|
118 if (data.error) { |
|
119 console.log('updaterow: ' + data.msg); |
|
120 alert('Fout: ' + data.msg); |
|
121 } else { |
|
122 console.log('updaterow: success'); |
|
123 } |
|
124 location.reload(true); |
|
125 }, |
|
126 error: function(jqXHR, textStatus, errorThrown) { commit(false); } |
|
127 }); |
|
128 } |
|
129 }, |
|
130 dataAdapter = new $.jqx.dataAdapter(source), |
|
131 editrow = -1; |
|
132 |
|
133 // tooltips |
|
134 $('#name').jqxTooltip({ content: 'De unieke naam van dit water profiel.' }); |
|
135 $('#notes').jqxTooltip({ content: 'Extra opmerkingen over dit water.' }); |
|
136 $('#calcium').jqxTooltip({ content: 'Calcium (Ca).' }); |
|
137 $('#bicarbonate').jqxTooltip({ content: 'Bicarbonaat (HCO3). Berekend meteen de Totale alkaliteit.' }); |
|
138 $('#sulfate').jqxTooltip({ content: 'Calcium Sulfaat (CaSO4).' }); |
|
139 $('#chloride').jqxTooltip({ content: 'Chloride (Cl).' }); |
|
140 $('#sodium').jqxTooltip({ content: 'Natrium, oftewel keukenzout (Na). In berekeningen ook vaak als Sodium.' }); |
|
141 $('#magnesium').jqxTooltip({ content: 'Magnesium (Mg).' }); |
|
142 $('#ph').jqxTooltip({ content: 'De zuurgraad (pH).' }); |
|
143 $('#total_alkalinity').jqxTooltip({ content: 'Totale alkaliniteit. Berekend meteen de Bicarbonaat.' }); |
|
144 $('#balance').jqxTooltip({ content: 'De ionen balans van het water. Ideaal minder dan 0.1 verschil tussen kationen en anionen. Meer dan 0.5 is een fout in het waterraport.' }); |
|
145 |
|
146 // initialize the input fields. |
|
147 $('#name').jqxInput({ theme: theme, width: 640, height: 23 }); |
|
148 $('#notes').jqxInput({ theme: theme, width: 800, height: 100 }); |
|
149 $('#calcium').jqxNumberInput(Spin1dec); |
|
150 $('#bicarbonate').jqxNumberInput(Spin1dec); |
|
151 $('#sulfate').jqxNumberInput(Spin1dec); |
|
152 $('#chloride').jqxNumberInput(Spin1dec); |
|
153 $('#sodium').jqxNumberInput(Spin1dec); |
|
154 $('#magnesium').jqxNumberInput(Spin1dec); |
|
155 $('#ph').jqxNumberInput(Spin2pH); |
|
156 $('#total_alkalinity').jqxNumberInput(Spin1dec); |
|
157 $('#balance').jqxNumberInput(Show2dec); |
|
158 |
|
159 // initialize jqxGrid |
|
160 $('#jqxgrid').jqxGrid({ |
|
161 width: 1280, |
|
162 height: 630, |
|
163 source: dataAdapter, |
|
164 theme: theme, |
|
165 showstatusbar: true, |
|
166 renderstatusbar: function(statusbar) { |
|
167 var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
|
168 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>'); |
|
169 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'), |
|
170 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' + |
|
171 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -4px;">Nieuw</span></div>'); |
|
172 container.append(addButton); |
|
173 statusbar.append(container); |
|
174 addButton.jqxButton({ theme: theme, width: 90, height: 17 }); |
|
175 // add new row. |
|
176 addButton.click(function(event) { |
|
177 editrow = -1; |
|
178 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
179 dataRecord.uuid = ''; |
|
180 $('#name').val(''); |
|
181 $('#calcium').val(0); |
|
182 $('#bicarbonate').val(0); |
|
183 $('#sulfate').val(0); |
|
184 $('#chloride').val(0); |
|
185 $('#sodium').val(0); |
|
186 $('#magnesium').val(0); |
|
187 $('#ph').val(7); |
|
188 $('#notes').val(''); |
|
189 $('#total_alkalinity').val(0); |
|
190 $('#popupWindow').jqxWindow('open'); |
|
191 }); |
|
192 }, |
|
193 filterable: false, |
|
194 filtermode: 'excel', |
|
195 columns: [ |
|
196 { text: 'Water Profiel', datafield: 'name', width: 225 }, |
|
197 { text: 'Opmerkingen', datafield: 'notes' }, |
|
198 { text: 'Ca', datafield: 'calcium', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
199 { text: 'Mg', datafield: 'magnesium', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
200 { text: 'Na', datafield: 'sodium', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
201 { text: 'CaCO3', datafield: 'total_alkalinity', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
202 { text: 'Cl', datafield: 'chloride', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
203 { text: 'SO4', datafield: 'sulfate', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
204 { text: 'pH', datafield: 'ph', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, |
|
205 { text: '', datafield: 'Edit', width: 100, columntype: 'button', |
|
206 cellsrenderer: function() { |
|
207 return 'Wijzig'; |
|
208 }, buttonclick: function(row) { |
|
209 // open the popup window when the user clicks a button. |
|
210 editrow = row; |
|
211 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } }); |
|
212 // get the clicked row's data and initialize the input fields. |
|
213 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow); |
|
214 $('#name').val(dataRecord.name); |
|
215 $('#calcium').val(dataRecord.calcium); |
|
216 $('#bicarbonate').val(dataRecord.bicarbonate); |
|
217 $('#sulfate').val(dataRecord.sulfate); |
|
218 $('#chloride').val(dataRecord.chloride); |
|
219 $('#sodium').val(dataRecord.sodium); |
|
220 $('#magnesium').val(dataRecord.magnesium); |
|
221 $('#ph').val(dataRecord.ph); |
|
222 $('#notes').val(dataRecord.notes); |
|
223 $('#total_alkalinity').val(dataRecord.total_alkalinity); |
|
224 calcBalance(); |
|
225 // show the popup window. |
|
226 $('#popupWindow').jqxWindow('open'); |
|
227 } |
|
228 } |
|
229 ] |
|
230 }); |
|
231 |
|
232 function calcBalance() { |
|
233 var cations = (dataRecord.calcium / 20.039) + (dataRecord.magnesium / 12.1525) + (dataRecord.sodium / 22.989); |
|
234 var anions = (dataRecord.bicarbonate / 61.016) + (dataRecord.sulfate / 48.031) + (dataRecord.chloride / 35.4527); |
|
235 var balance = Round(cations - anions, 2); |
|
236 $('#balance').val(balance); |
|
237 if (balance <= 0.1 && balance >= -0.1) |
|
238 $('#wr_balance').html("<img src='images/dialog-ok-apply.png'>"); |
|
239 else if (balance <= 0.5 && balance >= -0.5) |
|
240 $('#wr_balance').html("<img src='images/dialog-ok.png'>"); |
|
241 else |
|
242 $('#wr_balance').html("<img src='images/dialog-error.png'>"); |
|
243 } |
|
244 |
|
245 $('#calcium').on('change', function(event) { |
|
246 dataRecord.calcium = parseFloat(event.args.value); |
|
247 calcBalance(); |
|
248 }); |
|
249 $('#magnesium').on('change', function(event) { |
|
250 dataRecord.magnesium = parseFloat(event.args.value); |
|
251 calcBalance(); |
|
252 }); |
|
253 $('#sodium').on('change', function(event) { |
|
254 dataRecord.sodium = parseFloat(event.args.value); |
|
255 calcBalance(); |
|
256 }); |
|
257 $('#total_alkalinity').on('change', function(event) { |
|
258 dataRecord.total_alkalinity = parseFloat(event.args.value); |
|
259 dataRecord.bicarbonate = parseFloat(event.args.value) * 1.22; |
|
260 $('#bicarbonate').val(dataRecord.bicarbonate); |
|
261 calcBalance(); |
|
262 }); |
|
263 $('#bicarbonate').on('change', function(event) { |
|
264 dataRecord.bicarbonate = parseFloat(event.args.value); |
|
265 dataRecord.total_alkalinity = parseFloat(event.args.value) * 50 / 61; |
|
266 $('#total_alkalinity').val(dataRecord.total_alkalinity); |
|
267 calcBalance(); |
|
268 }); |
|
269 $('#sulfate').on('change', function(event) { |
|
270 dataRecord.sulfate = parseFloat(event.args.value); |
|
271 calcBalance(); |
|
272 }); |
|
273 $('#chloride').on('change', function(event) { |
|
274 dataRecord.chloride = parseFloat(event.args.value); |
|
275 calcBalance(); |
|
276 }); |
|
277 |
|
278 // initialize the popup window and buttons. |
|
279 $('#popupWindow').jqxWindow({ |
|
280 width: 1050, |
|
281 height: 550, |
|
282 resizable: false, |
|
283 theme: theme, |
|
284 isModal: true, |
|
285 autoOpen: false, |
|
286 cancelButton: $('#Cancel'), |
|
287 modalOpacity: 0.40 |
|
288 }); |
|
289 $('#popupWindow').on('open', function() { |
|
290 $('#name').jqxInput('selectAll'); |
|
291 }); |
|
292 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme }); |
|
293 $('#Delete').click(function() { |
|
294 if (editrow >= 0) { |
|
295 // Open a popup to confirm this action. |
|
296 $('#eventWindow').jqxWindow('open'); |
|
297 $('#delOk').click(function() { |
|
298 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
299 $('#jqxgrid').jqxGrid('deleterow', rowID); |
|
300 }); |
|
301 } |
|
302 $('#popupWindow').jqxWindow('hide'); |
|
303 }); |
|
304 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme }); |
|
305 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme }); |
|
306 // update the edited row when the user clicks the 'Save' button. |
|
307 $('#Save').click(function() { |
|
308 var row, rowID = -1; |
|
309 if (editrow >= 0) { |
|
310 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
311 } |
|
312 row = { |
|
313 record: rowID, |
|
314 uuid: dataRecord.uuid, |
|
315 name: $('#name').val(), |
|
316 calcium: parseFloat($('#calcium').jqxNumberInput('decimal')), |
|
317 bicarbonate: parseFloat($('#bicarbonate').jqxNumberInput('decimal')), |
|
318 sulfate: parseFloat($('#sulfate').jqxNumberInput('decimal')), |
|
319 chloride: parseFloat($('#chloride').jqxNumberInput('decimal')), |
|
320 sodium: parseFloat($('#sodium').jqxNumberInput('decimal')), |
|
321 magnesium: parseFloat($('#magnesium').jqxNumberInput('decimal')), |
|
322 ph: parseFloat($('#ph').jqxNumberInput('decimal')), |
|
323 notes: $('#notes').val(), |
|
324 total_alkalinity: parseFloat($('#total_alkalinity').jqxNumberInput('decimal')) |
|
325 }; |
|
326 if (editrow >= 0) { |
|
327 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
328 } else { |
|
329 $('#jqxgrid').jqxGrid('addrow', null, row); |
|
330 } |
|
331 $('#popupWindow').jqxWindow('hide'); |
|
332 }); |
|
333 createDelElements(); |
|
334 }); |
|
335 |
|