|
1 /***************************************************************************** |
|
2 * Copyright (C) 2014-2018 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BrewCloud |
|
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: 145, |
|
30 resizable: false, |
|
31 isModal: true, |
|
32 modalOpacity: 0.4, |
|
33 okButton: $('#delOk'), |
|
34 cancelButton: $('#delCancel'), |
|
35 initContent: function () { |
|
36 $('#delOk').jqxButton({ width: '65px', theme: theme }); |
|
37 $('#delCancel').jqxButton({ width: '65px', theme: theme }); |
|
38 $('#delCancel').focus(); |
|
39 } |
|
40 }); |
|
41 $('#eventWindow').jqxWindow('hide'); |
|
42 } |
|
43 |
|
44 |
|
45 $(document).ready(function () { |
|
46 var url = "includes/db_inventory_equipments.php"; |
|
47 // tooltips |
|
48 $("#name").jqxTooltip({ content: 'The unique name of this brew equipment.' }); |
|
49 $("#notes").jqxTooltip({ content: 'Some notes about the equipment.' }); |
|
50 $("#tun_volume").jqxTooltip({ content: 'Mash TUN volume.' }); |
|
51 $("#tun_height").jqxTooltip({ content: 'Mash TUN height in cm.' }); |
|
52 $("#tun_weight").jqxTooltip({ content: 'Mash TUN weight in Kg.' }); |
|
53 $("#tun_material").jqxTooltip({ content: 'Mash TUN material. Needed to calculate the right strike temperature.' }); |
|
54 $("#mash_volume").jqxTooltip({ content: 'Mash water for the first step.' }); |
|
55 $("#lauter_volume").jqxTooltip({ content: 'Total lauter volume.' }); |
|
56 $("#lauter_height").jqxTooltip({ content: 'Height of the lauter TUN in cm.' }); |
|
57 $("#lauter_deadspace").jqxTooltip({ content: 'Volume loss in the lauter TUN.' }); |
|
58 $("#efficiency").jqxTooltip({ content: 'Average efficiency.' }); |
|
59 $("#kettle_volume").jqxTooltip({ content: 'Boil kettle volume in liters.' }); |
|
60 $("#kettle_height").jqxTooltip({ content: 'Boil kettle height in cm.' }); |
|
61 $("#boil_size").jqxTooltip({ content: 'Normal boil volume in liters' }); |
|
62 $("#evap_rate").jqxTooltip({ content: 'Evaporation in liters per hour.' }); |
|
63 $("#boil_time").jqxTooltip({ content: 'Normal boil time in minutes.' }); |
|
64 $("#top_up_kettle").jqxTooltip({ content: 'Extra water added to the boil.' }); |
|
65 $("#hop_utilization").jqxTooltip({ content: '100% for smaller installations, higher for large breweries.' }); |
|
66 $("#batch_size").jqxTooltip({ content: 'Calculated batch size, liters at end of the boil.' }); |
|
67 $("#trub_chiller_loss").jqxTooltip({ content: 'Standard loss in liters during transfer to the fermenter.' }); |
|
68 |
|
69 // prepare the data |
|
70 var source = { |
|
71 datatype: "json", |
|
72 cache: false, |
|
73 datafields: [ |
|
74 { name: 'record', type: 'number' }, |
|
75 { name: 'name', type: 'string' }, |
|
76 { name: 'boil_size', type: 'float' }, |
|
77 { name: 'batch_size', type: 'float' }, |
|
78 { name: 'tun_volume', type: 'float' }, |
|
79 { name: 'tun_weight', type: 'float' }, |
|
80 { name: 'trub_chiller_loss', type: 'float' }, |
|
81 { name: 'evap_rate', type: 'float' }, |
|
82 { name: 'boil_time', type: 'float' }, |
|
83 { name: 'lauter_deadspace', type: 'float' }, |
|
84 { name: 'top_up_kettle', type: 'float' }, |
|
85 { name: 'hop_utilization', type: 'float' }, |
|
86 { name: 'notes', type: 'string' }, |
|
87 { name: 'lauter_volume', type: 'float' }, |
|
88 { name: 'kettle_volume', type: 'float' }, |
|
89 { name: 'tun_material', type: 'string' }, |
|
90 { name: 'tun_height', type: 'float' }, |
|
91 { name: 'kettle_height', type: 'float' }, |
|
92 { name: 'lauter_height', type: 'float' }, |
|
93 { name: 'mash_volume', type: 'float' }, |
|
94 { name: 'efficiency', type: 'float' } |
|
95 ], |
|
96 id: 'record', |
|
97 url: url, |
|
98 deleterow: function (rowid, commit) { |
|
99 // synchronize with the server - send delete command |
|
100 var data = "delete=true&" + $.param({ record: rowid }); |
|
101 $.ajax({ |
|
102 dataType: 'json', |
|
103 url: url, |
|
104 cache: false, |
|
105 data: data, |
|
106 success: function (data, status, xhr) { |
|
107 // delete command is executed. |
|
108 commit(true); |
|
109 }, |
|
110 error: function (jqXHR, textStatus, errorThrown) { |
|
111 commit(false); |
|
112 } |
|
113 }); |
|
114 }, |
|
115 addrow: function (rowid, rowdata, position, commit) { |
|
116 var data = "insert=true&" + $.param(rowdata); |
|
117 $.ajax({ |
|
118 dataType: 'json', |
|
119 url: url, |
|
120 cache: false, |
|
121 data: data, |
|
122 success: function (data, status, xhr) { |
|
123 commit(true); |
|
124 }, |
|
125 error: function(jqXHR, textStatus, errorThrown) { |
|
126 commit(false); |
|
127 } |
|
128 }); |
|
129 }, |
|
130 updaterow: function (rowid, rowdata, commit) { |
|
131 var data = "update=true&" + $.param(rowdata); |
|
132 $.ajax({ |
|
133 dataType: 'json', |
|
134 url: url, |
|
135 cache: false, |
|
136 data: data, |
|
137 success: function (data, status, xhr) { |
|
138 // update command is executed. |
|
139 commit(true); |
|
140 }, |
|
141 error: function(jqXHR, textStatus, errorThrown) { |
|
142 commit(false); |
|
143 } |
|
144 }); |
|
145 } |
|
146 }; |
|
147 // initialize the input fields. |
|
148 var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ]; |
|
149 |
|
150 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
151 $("#boil_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
152 $("#batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: 'true', theme: theme, width: 50, height: 23, min: 0, decimalDigits: 1 }); |
|
153 $("#tun_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
154 $("#tun_weight").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); |
|
155 $("#trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
156 $("#evap_rate").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 }); |
|
157 $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true }); |
|
158 $("#lauter_deadspace").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
159 $("#top_up_kettle").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
160 $("#hop_utilization").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true }); |
|
161 $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); |
|
162 $("#lauter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
163 $("#kettle_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
164 $("#tun_material").jqxDropDownList({ theme: theme, source: srcMaterial, selectedIndex: 0, width: 110, height: 23, dropDownHeight: 130 }); |
|
165 $("#tun_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
166 $("#kettle_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
167 $("#lauter_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
168 $("#mash_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
169 $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
170 var dataAdapter = new $.jqx.dataAdapter(source); |
|
171 var editrow = -1; |
|
172 // initialize jqxGrid |
|
173 $("#jqxgrid").jqxGrid({ |
|
174 width: 1280, |
|
175 height: 630, |
|
176 source: dataAdapter, |
|
177 theme: theme, |
|
178 showstatusbar: true, |
|
179 localization: getLocalization(), |
|
180 renderstatusbar: function (statusbar) { |
|
181 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
182 var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Add</span></div>"); |
|
183 container.append(addButton); |
|
184 statusbar.append(container); |
|
185 addButton.jqxButton({ width: 60, height: 20 }); |
|
186 // add new row. |
|
187 addButton.click(function (event) { |
|
188 editrow = -1; |
|
189 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
190 $("#name").val(''); |
|
191 $("#boil_size").val('18'); |
|
192 $("#batch_size").val('15.3'); |
|
193 $("#tun_volume").val('20'); |
|
194 $("#tun_weight").val('2'); |
|
195 $("#trub_chiller_loss").val('0.5'); |
|
196 $("#evap_rate").val('1.8'); |
|
197 $("#boil_time").val('90'); |
|
198 $("#lauter_deadspace").val('0.5'); |
|
199 $("#top_up_kettle").val('0'); |
|
200 $("#hop_utilization").val('100'); |
|
201 $("#notes").val(''); |
|
202 $("#lauter_volume").val('20'); |
|
203 $("#kettle_volume").val('20'); |
|
204 $("#tun_material").val('RVS'); |
|
205 $("#tun_height").val('20'); |
|
206 $("#kettle_height").val('20'); |
|
207 $("#lauter_height").val('20'); |
|
208 $("#mash_volume").val('18'); |
|
209 $("#efficiency").val('75'); |
|
210 $("#popupWindow").jqxWindow('open'); |
|
211 }); |
|
212 }, |
|
213 filterable: true, |
|
214 filtermode: 'excel', |
|
215 columns: [ |
|
216 { text: 'Equipment Name', datafield: 'name', width: 250 }, |
|
217 { text: 'Boil Size', datafield: 'boil_size', width: 90, cellsalign: 'right', cellsformat: 'f1' }, |
|
218 { text: 'Batch Size', datafield: 'batch_size', width: 90, cellsalign: 'right', cellsformat: 'f1' }, |
|
219 { text: 'Notes', datafield: 'notes' }, |
|
220 { text: 'Edit', datafield: 'Edit', width: 80, columntype: 'button', cellsrenderer: function () { |
|
221 return "Edit"; |
|
222 }, buttonclick: function (row) { |
|
223 // open the popup window when the user clicks a button. |
|
224 editrow = row; |
|
225 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
226 // get the clicked row's data and initialize the input fields. |
|
227 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
|
228 $("#name").val(dataRecord.name); |
|
229 $("#boil_size").val(dataRecord.boil_size); |
|
230 $("#batch_size").val(dataRecord.batch_size); |
|
231 $("#tun_volume").val(dataRecord.tun_volume); |
|
232 $("#tun_weight").val(dataRecord.tun_weight); |
|
233 $("#trub_chiller_loss").val(dataRecord.trub_chiller_loss); |
|
234 $("#evap_rate").val(dataRecord.evap_rate); |
|
235 $("#boil_time").val(dataRecord.boil_time); |
|
236 $("#lauter_deadspace").val(dataRecord.lauter_deadspace); |
|
237 $("#top_up_kettle").val(dataRecord.top_up_kettle); |
|
238 $("#hop_utilization").val(dataRecord.hop_utilization); |
|
239 $("#notes").val(dataRecord.notes); |
|
240 $("#lauter_volume").val(dataRecord.lauter_volume); |
|
241 $("#kettle_volume").val(dataRecord.kettle_volume); |
|
242 $("#tun_material").val(dataRecord.tun_material); |
|
243 $("#tun_height").val(dataRecord.tun_height); |
|
244 $("#kettle_height").val(dataRecord.kettle_height); |
|
245 $("#lauter_height").val(dataRecord.lauter_height); |
|
246 $("#mash_volume").val(dataRecord.mash_volume); |
|
247 $("#efficiency").val(dataRecord.efficiency); |
|
248 // show the popup window. |
|
249 $("#popupWindow").jqxWindow('open'); |
|
250 } |
|
251 } |
|
252 ] |
|
253 }); |
|
254 // initialize the popup window and buttons. |
|
255 $("#popupWindow").jqxWindow({ |
|
256 width: 800, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 |
|
257 }); |
|
258 $("#popupWindow").on('open', function () { |
|
259 $("#name").jqxInput('selectAll'); |
|
260 }); |
|
261 $("#Delete").jqxButton({ theme: theme }); |
|
262 $("#Delete").click(function () { |
|
263 if (editrow >= 0) { |
|
264 // Open a popup to confirm this action. |
|
265 $('#eventWindow').jqxWindow('open'); |
|
266 $("#delOk").click(function () { |
|
267 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
268 $("#jqxgrid").jqxGrid('deleterow', rowID); |
|
269 }); |
|
270 } |
|
271 $("#popupWindow").jqxWindow('hide'); |
|
272 }); |
|
273 $("#Cancel").jqxButton({ theme: theme }); |
|
274 $("#Save").jqxButton({ theme: theme }); |
|
275 // update the edited row when the user clicks the 'Save' button. |
|
276 $("#Save").click(function () { |
|
277 if (editrow >= 0) { |
|
278 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
279 var row = { |
|
280 record: rowID, |
|
281 name: $("#name").val(), |
|
282 boil_size: parseFloat($("#boil_size").jqxNumberInput('decimal')), |
|
283 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), |
|
284 tun_volume: parseFloat($("#tun_volume").jqxNumberInput('decimal')), |
|
285 tun_weight: parseFloat($("#tun_weight").jqxNumberInput('decimal')), |
|
286 trub_chiller_loss: parseFloat($("#trub_chiller_loss").jqxNumberInput('decimal')), |
|
287 evap_rate: parseFloat($("#evap_rate").jqxNumberInput('decimal')), |
|
288 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), |
|
289 lauter_deadspace: parseFloat($("#lauter_deadspace").jqxNumberInput('decimal')), |
|
290 top_up_kettle: parseFloat($("#top_up_kettle").jqxNumberInput('decimal')), |
|
291 hop_utilization: parseFloat($("#hop_utilization").jqxNumberInput('decimal')), |
|
292 notes: $("#notes").val(), |
|
293 lauter_volume: parseFloat($("#lauter_volume").jqxNumberInput('decimal')), |
|
294 kettle_volume: parseFloat($("#kettle_volume").jqxNumberInput('decimal')), |
|
295 tun_material: $("#tun_material").val(), |
|
296 tun_height: parseFloat($("#tun_height").jqxNumberInput('decimal')), |
|
297 kettle_height: parseFloat($("#kettle_height").jqxNumberInput('decimal')), |
|
298 lauter_height: parseFloat($("#lauter_height").jqxNumberInput('decimal')), |
|
299 mash_volume: parseFloat($("#mash_volume").jqxNumberInput('decimal')), |
|
300 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')) |
|
301 }; |
|
302 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
303 $("#popupWindow").jqxWindow('hide'); |
|
304 } else { |
|
305 // Insert a record |
|
306 var newrow = { |
|
307 record: -1, |
|
308 name: $("#name").val(), |
|
309 boil_size: parseFloat($("#boil_size").jqxNumberInput('decimal')), |
|
310 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), |
|
311 tun_volume: parseFloat($("#tun_volume").jqxNumberInput('decimal')), |
|
312 tun_weight: parseFloat($("#tun_weight").jqxNumberInput('decimal')), |
|
313 trub_chiller_loss: parseFloat($("#trub_chiller_loss").jqxNumberInput('decimal')), |
|
314 evap_rate: parseFloat($("#evap_rate").jqxNumberInput('decimal')), |
|
315 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), |
|
316 lauter_deadspace: parseFloat($("#lauter_deadspace").jqxNumberInput('decimal')), |
|
317 top_up_kettle: parseFloat($("#top_up_kettle").jqxNumberInput('decimal')), |
|
318 hop_utilization: parseFloat($("#hop_utilization").jqxNumberInput('decimal')), |
|
319 notes: $("#notes").val(), |
|
320 lauter_volume: parseFloat($("#lauter_volume").jqxNumberInput('decimal')), |
|
321 kettle_volume: parseFloat($("#kettle_volume").jqxNumberInput('decimal')), |
|
322 tun_material: $("#tun_material").val(), |
|
323 tun_height: parseFloat($("#tun_height").jqxNumberInput('decimal')), |
|
324 kettle_height: parseFloat($("#kettle_height").jqxNumberInput('decimal')), |
|
325 lauter_height: parseFloat($("#lauter_height").jqxNumberInput('decimal')), |
|
326 mash_volume: parseFloat($("#mash_volume").jqxNumberInput('decimal')), |
|
327 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')) |
|
328 }; |
|
329 $('#jqxgrid').jqxGrid('addrow', null, newrow); |
|
330 $("#popupWindow").jqxWindow('hide'); |
|
331 } |
|
332 }); |
|
333 createDelElements(); |
|
334 }); |
|
335 |