|
1 /***************************************************************************** |
|
2 * Copyright (C) 2018 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BMS |
|
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 $(document).ready(function () { |
|
25 |
|
26 console.log("record:" + my_record + " return:" + my_return + " theme:" + theme); |
|
27 |
|
28 var dataReecord = {}; |
|
29 var url = "includes/db_product.php"; |
|
30 // tooltips |
|
31 $("#name").jqxTooltip({ content: 'De naam voor dit product.' }); |
|
32 $("#code").jqxTooltip({ content: 'Product code nummer.' }); |
|
33 $("#birth").jqxTooltip({ content: 'De ontwerp datum van dit product.' }); |
|
34 $("#stage").jqxTooltip({ content: 'De productie fase van dit product.' }); |
|
35 $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit product.' }); |
|
36 $("#eq_name").jqxTooltip({ content: 'The unique name of this brew equipment.' }); |
|
37 $("#eq_notes").jqxTooltip({ content: 'Some notes about the equipment.' }); |
|
38 $("#eq_tun_volume").jqxTooltip({ content: 'Mash TUN volume.' }); |
|
39 $("#eq_tun_height").jqxTooltip({ content: 'Mash TUN height in cm.' }); |
|
40 $("#eq_tun_weight").jqxTooltip({ content: 'Mash TUN weight in Kg.' }); |
|
41 $("#eq_tun_material").jqxTooltip({ content: 'Mash TUN material. Needed to calculate the right strike temperature.' }); |
|
42 $("#eq_mash_volume").jqxTooltip({ content: 'Mash water for the first step.' }); |
|
43 $("#eq_lauter_volume").jqxTooltip({ content: 'Total lauter volume.' }); |
|
44 $("#eq_lauter_height").jqxTooltip({ content: 'Height of the lauter TUN in cm.' }); |
|
45 $("#eq_lauter_deadspace").jqxTooltip({ content: 'Volume loss in the lauter TUN.' }); |
|
46 $("#eq_efficiency").jqxTooltip({ content: 'Average efficiency.' }); |
|
47 $("#eq_kettle_volume").jqxTooltip({ content: 'Boil kettle volume in liters.' }); |
|
48 $("#eq_kettle_height").jqxTooltip({ content: 'Boil kettle height in cm.' }); |
|
49 $("#eq_boil_size").jqxTooltip({ content: 'Normal boil volume in liters' }); |
|
50 $("#eq_evap_rate").jqxTooltip({ content: 'Evaporation in liters per hour.' }); |
|
51 $("#eq_boil_time").jqxTooltip({ content: 'Normal boil time in minutes.' }); |
|
52 $("#eq_top_up_kettle").jqxTooltip({ content: 'Extra water added to the boil.' }); |
|
53 $("#eq_hop_utilization").jqxTooltip({ content: '100% for smaller installations, higher for large breweries.' }); |
|
54 $("#eq_batch_size").jqxTooltip({ content: 'Calculated batch size, liters at end of the boil.' }); |
|
55 $("#eq_trub_chiller_loss").jqxTooltip({ content: 'Standard loss in liters during transfer to the fermenter.' }); |
|
56 |
|
57 |
|
58 // Prepare the data |
|
59 var source = { |
|
60 datatype: "json", |
|
61 cache: false, |
|
62 datafields: [ |
|
63 { name: 'record', type: 'number' }, |
|
64 { name: 'uuid', type: 'string' }, |
|
65 { name: 'name', type: 'string' }, |
|
66 { name: 'code', type: 'string' }, |
|
67 { name: 'birth', type: 'string' }, |
|
68 { name: 'stage', type: 'string' }, |
|
69 { name: 'notes', type: 'string' }, |
|
70 { name: 'eq_name', type: 'string' }, |
|
71 { name: 'eq_boil_size', type: 'float' }, |
|
72 { name: 'eq_batch_size', type: 'float' }, |
|
73 { name: 'eq_tun_volume', type: 'float' }, |
|
74 { name: 'eq_tun_weight', type: 'float' }, |
|
75 { name: 'eq_trub_chiller_loss', type: 'float' }, |
|
76 { name: 'eq_evap_rate', type: 'float' }, |
|
77 { name: 'eq_boil_time', type: 'float' }, |
|
78 { name: 'eq_lauter_deadspace', type: 'float' }, |
|
79 { name: 'eq_top_up_kettle', type: 'float' }, |
|
80 { name: 'eq_hop_utilization', type: 'float' }, |
|
81 { name: 'eq_notes', type: 'string' }, |
|
82 { name: 'eq_lauter_volume', type: 'float' }, |
|
83 { name: 'eq_kettle_volume', type: 'float' }, |
|
84 { name: 'eq_tun_material', type: 'string' }, |
|
85 { name: 'eq_tun_height', type: 'float' }, |
|
86 { name: 'eq_kettle_height', type: 'float' }, |
|
87 { name: 'eq_lauter_height', type: 'float' }, |
|
88 { name: 'eq_mash_volume', type: 'float' }, |
|
89 { name: 'eq_efficiency', type: 'float' } |
|
90 ], |
|
91 id: 'record', |
|
92 url: url |
|
93 }; |
|
94 // Load data and select one record. |
|
95 var dataAdapter = new $.jqx.dataAdapter(source, { |
|
96 loadComplete: function () { |
|
97 var records = dataAdapter.records; |
|
98 dataRecord = records[0]; |
|
99 // Hidden record uuid |
|
100 $("#name").val(dataRecord.name); |
|
101 $("#code").val(dataRecord.code); |
|
102 $("#birth").val(dataRecord.birth); |
|
103 $("#stage").val(dataRecord.stage); |
|
104 $("#notes").val(dataRecord.notes); |
|
105 $("#eq_name").val(dataRecord.eq_name); |
|
106 $("#eq_boil_size").val(dataRecord.eq_boil_size); |
|
107 $("#eq_batch_size").val(dataRecord.eq_batch_size); |
|
108 $("#eq_tun_volume").val(dataRecord.eq_tun_volume); |
|
109 $("#eq_tun_weight").val(dataRecord.eq_tun_weight); |
|
110 $("#eq_trub_chiller_loss").val(dataRecord.eq_trub_chiller_loss); |
|
111 $("#eq_evap_rate").val(dataRecord.eq_evap_rate); |
|
112 $("#eq_boil_time").val(dataRecord.eq_boil_time); |
|
113 $("#eq_lauter_deadspace").val(dataRecord.eq_lauter_deadspace); |
|
114 $("#eq_top_up_kettle").val(dataRecord.eq_top_up_kettle); |
|
115 $("#eq_hop_utilization").val(dataRecord.eq_hop_utilization); |
|
116 $("#eq_notes").val(dataRecord.eq_notes); |
|
117 $("#eq_lauter_volume").val(dataRecord.eq_lauter_volume); |
|
118 $("#eq_kettle_volume").val(dataRecord.eq_kettle_volume); |
|
119 $("#eq_tun_material").val(dataRecord.eq_tun_material); |
|
120 $("#eq_tun_height").val(dataRecord.eq_tun_height); |
|
121 $("#eq_kettle_height").val(dataRecord.eq_kettle_height); |
|
122 $("#eq_lauter_height").val(dataRecord.eq_lauter_height); |
|
123 $("#eq_mash_volume").val(dataRecord.eq_mash_volume); |
|
124 $("#eq_efficiency").val(dataRecord.eq_efficiency); |
|
125 |
|
126 }, |
|
127 loadError: function (jqXHR, status, error) { |
|
128 }, |
|
129 beforeLoadComplete: function (records) { |
|
130 var filteredRecords = []; |
|
131 for (var i = 0; i < records.length; i++) { |
|
132 if (records[i].record == my_record) { |
|
133 filteredRecords.push(records[i]); |
|
134 } |
|
135 } |
|
136 return filteredRecords; |
|
137 } |
|
138 }); |
|
139 dataAdapter.dataBind(); |
|
140 |
|
141 // initialize the input fields. |
|
142 var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ]; |
|
143 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); |
|
144 $("#code").jqxInput({ theme: theme, width: 100, height: 23 }); |
|
145 $("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' }); |
|
146 $("#stage").jqxInput({ theme: theme, width: 100, height: 23, disabled: true }); |
|
147 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); |
|
148 $("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
149 $("#eq_boil_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
150 $("#eq_batch_size").jqxNumberInput({ inputMode: 'simple', readOnly: 'true', theme: theme, width: 50, height: 23, min: 0, decimalDigits: 1 }); |
|
151 $("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
152 $("#eq_tun_weight").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); |
|
153 $("#eq_trub_chiller_loss").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
154 $("#eq_evap_rate").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true, spinButtonsStep: 0.05 }); |
|
155 $("#eq_boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true }); |
|
156 $("#eq_lauter_deadspace").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
157 $("#eq_top_up_kettle").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 }); |
|
158 $("#eq_hop_utilization").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 0, spinButtons: true }); |
|
159 $("#eq_notes").jqxInput({ theme: theme, width: 640, height: 100 }); |
|
160 $("#eq_lauter_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
161 $("#eq_kettle_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
162 $("#eq_tun_material").jqxDropDownList({ theme: theme, source: srcMaterial, selectedIndex: 0, width: 110, height: 23, dropDownHeight: 130 }); |
|
163 $("#eq_tun_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
164 $("#eq_kettle_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
165 $("#eq_lauter_height").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
166 $("#eq_mash_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 }); |
|
167 $("#eq_efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
168 |
|
169 $('#jqxTabs').jqxTabs({ |
|
170 theme: theme, |
|
171 width: 1280, |
|
172 height: 630, |
|
173 autoHeight: false, |
|
174 position: 'top' |
|
175 }); |
|
176 |
|
177 |
|
178 |
|
179 /* |
|
180 //Creating wizard module |
|
181 var wizard = (function () { |
|
182 |
|
183 //Adding event listeners |
|
184 var _addHandlers = function () { |
|
185 $('#name').on('change', function (event) { wizard.validate(true); }); |
|
186 $('#nextButtonCompleted').click(function () { |
|
187 console.log("insert start"); |
|
188 var newrow = { |
|
189 record: -1, |
|
190 name: $("#name").val(), |
|
191 notes: $("#notes").val(), |
|
192 st_name: $('#st_name').val(), |
|
193 st_letter: $('#st_style_letter').val(), |
|
194 mash_ph: 5.4, |
|
195 mash_sparge_temp: 78.0 |
|
196 }; |
|
197 var data = "insert=true&return=" + my_return + "&" + $.param(newrow); |
|
198 $.ajax({ |
|
199 dataType: 'json', |
|
200 url: "includes/db_recipes.php", |
|
201 cache: false, |
|
202 data: data, |
|
203 type: "POST", |
|
204 success: function (data, status, xhr) { |
|
205 // update command is executed. |
|
206 window.location.href = my_return; |
|
207 }, |
|
208 error: function(jqXHR, textStatus, errorThrown) { |
|
209 } |
|
210 }); |
|
211 }); |
|
212 $('.nextButton').click(function () { |
|
213 wizard.validate(true); |
|
214 $('#jqxTabs').jqxTabs('next'); |
|
215 }); |
|
216 $('.backButton').click(function () { |
|
217 wizard.validate(true); |
|
218 $('#jqxTabs').jqxTabs('previous'); |
|
219 }); |
|
220 }; |
|
221 |
|
222 return { |
|
223 //Initializing the wizzard - creating all elements, adding event handlers and starting the validation |
|
224 init: function () { |
|
225 $('#jqxTabs').jqxTabs({ |
|
226 theme: theme, |
|
227 height: 630, |
|
228 width: 1280, |
|
229 autoHeight: false, |
|
230 position: 'top', |
|
231 keyboardNavigation: false |
|
232 }); |
|
233 $('#nextButtonBase').jqxButton({ theme: theme, width: 150 }); |
|
234 $('#nextButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
235 $('#backButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
236 $('#nextButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
237 $('#backButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
238 _addHandlers(); |
|
239 this.validate(); |
|
240 this.showHint('Validation hints.'); |
|
241 }, |
|
242 |
|
243 //Validating all wizard tabs |
|
244 validate: function (notify) { |
|
245 if (!this.firstTab(notify)) { |
|
246 $('#jqxTabs').jqxTabs('disableAt', 1); |
|
247 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
248 return; |
|
249 } else { |
|
250 $('#jqxTabs').jqxTabs('enableAt', 1); |
|
251 } |
|
252 if (!this.secondTab(notify)) { |
|
253 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
254 return; |
|
255 } else { |
|
256 $('#jqxTabs').jqxTabs('enableAt', 2); |
|
257 } |
|
258 }, |
|
259 |
|
260 //Displaying message to the user |
|
261 showHint: function (message, selector) { |
|
262 if (typeof selector === 'undefined') { |
|
263 selector = '.hint'; |
|
264 } |
|
265 if (message === '') { |
|
266 message = 'Ok, je mag doorgaan.'; |
|
267 } |
|
268 $(selector).html('<strong>' + message + '</strong>'); |
|
269 }, |
|
270 |
|
271 //Validating the first tab |
|
272 firstTab: function (notify) { |
|
273 var name = $('#name').val(), |
|
274 type = $('#type').val(), |
|
275 boil_time = parseFloat($("#boil_time").jqxNumberInput('decimal')), |
|
276 est_og = parseFloat($("#est_og").jqxNumberInput('decimal')), |
|
277 efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal')), |
|
278 message = ''; |
|
279 if (name.length < 3) { |
|
280 message += 'Je moet een recept naam invullen. <br />'; |
|
281 } |
|
282 // Check if name already exists. |
|
283 if (type.length < 1) { |
|
284 message += 'Je moet een brouw type kiezen. <br />'; |
|
285 } |
|
286 if ((boil_time < 4) || (boil_time > 360)) { |
|
287 message += 'De kooktijd moet tussen 4 en 360 minuten zijn. <br />'; |
|
288 } |
|
289 if ((est_og < 1.010) || (est_og > 1.200)) { |
|
290 message += 'Het OG moet tussen 1.010 en 1.500 zijn. <br />'; |
|
291 } |
|
292 if ((efficiency < 35) || (efficiency > 95)) { |
|
293 message += 'Het brouwzaal rendement moet tussen 35 en 95 zijn. <br />'; |
|
294 } |
|
295 if (message !== '') { |
|
296 if (notify) { |
|
297 this.showHint(message, '#hintBase'); |
|
298 } |
|
299 return false; |
|
300 } |
|
301 this.showHint('Ok, je mag doorgaan.', '#hintBase'); |
|
302 return true; |
|
303 }, |
|
304 |
|
305 //Validating the second tab |
|
306 secondTab: function (notify) { |
|
307 var stylesel = $('#styleSelect').val(), |
|
308 message = ''; |
|
309 if (stylesel.length < 3) { |
|
310 message += 'Je moet een bierstijl kiezen. <br />'; |
|
311 } |
|
312 if (message !== '') { |
|
313 if (notify) { |
|
314 this.showHint(message, '#hintStyle'); |
|
315 } |
|
316 return false; |
|
317 } |
|
318 this.showHint('Ok, je mag doorgaan.', '#hintStyle'); |
|
319 return true; |
|
320 } |
|
321 } |
|
322 } ()); |
|
323 */ |
|
324 //Initializing the wizard |
|
325 // wizard.init(); |
|
326 |
|
327 }); |
|
328 |