|
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 // tooltips |
|
27 $("#name").jqxTooltip({ content: 'De naam voor dit recept.' }); |
|
28 $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' }); |
|
29 $("#type").jqxTooltip({ content: 'Het brouw type van dit recept.' }); |
|
30 |
|
31 // editers |
|
32 var srcType = [ "All Grain", "Partial Mash", "Extract" ]; |
|
33 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); |
|
34 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); |
|
35 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 125, height: 23, dropDownHeight: 95 }); |
|
36 $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true }); |
|
37 $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' }); |
|
38 $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1.010, max: 1.2, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 }); |
|
39 |
|
40 $("#st_name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
41 $("#st_category").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
42 $("#st_category_number").jqxInput({ theme: theme, width: 70, height: 23 }); |
|
43 $("#st_style_letter").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
44 $("#st_style_guide").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
45 $("#st_notes").jqxInput({ theme: theme, width: 800, height: 100 }); |
|
46 $("#st_type").jqxInput({ theme: theme, width: 90, height: 23 }); |
|
47 $("#st_og_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); |
|
48 $("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); |
|
49 $("#st_fg_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); |
|
50 $("#st_fg_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true }); |
|
51 $("#st_ibu_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); |
|
52 $("#st_ibu_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); |
|
53 $("#st_color_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); |
|
54 $("#st_color_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true }); |
|
55 $("#st_carb_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
|
56 $("#st_carb_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
|
57 $("#st_abv_min").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
|
58 $("#st_abv_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); |
|
59 $("#st_profile").jqxInput({ theme: theme, width: 800, height: 48 }); |
|
60 $("#st_ingredients").jqxInput({ theme: theme, width: 800, height: 23 }); |
|
61 $("#st_examples").jqxInput({ theme: theme, width: 800, height: 48 }); |
|
62 |
|
63 // Default values. |
|
64 $("#type").val('All Grain'); |
|
65 $("#boil_time").val(90); |
|
66 $("#efficiency").val(75); |
|
67 $("#est_og").val(1.052); |
|
68 |
|
69 // Styles dropdown list |
|
70 var stylesUrl = "includes/db_profile_styles.php"; |
|
71 var stylesSource = { |
|
72 datatype: "json", |
|
73 datafields: [ |
|
74 { name: 'record', type: 'number' }, |
|
75 { name: 'name', type: 'string' }, |
|
76 { name: 'category', type: 'string' }, |
|
77 { name: 'category_number', type: 'number' }, |
|
78 { name: 'style_letter', type: 'string' }, |
|
79 { name: 'style_guide', type: 'string' }, |
|
80 { name: 'type', type: 'string' }, |
|
81 { name: 'og_min', type: 'float' }, |
|
82 { name: 'og_max', type: 'float' }, |
|
83 { name: 'fg_min', type: 'float' }, |
|
84 { name: 'fg_max', type: 'float' }, |
|
85 { name: 'ibu_min', type: 'float' }, |
|
86 { name: 'ibu_max', type: 'float' }, |
|
87 { name: 'color_min', type: 'float' }, |
|
88 { name: 'color_max', type: 'float' }, |
|
89 { name: 'carb_min', type: 'float' }, |
|
90 { name: 'carb_max', type: 'float' }, |
|
91 { name: 'abv_min', type: 'float' }, |
|
92 { name: 'abv_max', type: 'float' }, |
|
93 { name: 'notes', type: 'string' }, |
|
94 { name: 'profile', type: 'string' }, |
|
95 { name: 'ingredients', type: 'string' }, |
|
96 { name: 'examples', type: 'string' } |
|
97 ], |
|
98 url: stylesUrl, |
|
99 async: true |
|
100 }; |
|
101 var styleslist = new $.jqx.dataAdapter(stylesSource); |
|
102 |
|
103 $("#styleSelect").jqxDropDownList({ |
|
104 placeHolder: "Kies bierstijl:", |
|
105 theme: theme, |
|
106 source: styleslist, |
|
107 displayMember: "name", |
|
108 width: 150, |
|
109 height: 27, |
|
110 dropDownWidth: 500, |
|
111 dropDownHeight: 500, |
|
112 renderer: function (index, label, value) { |
|
113 var datarecord = styleslist.records[index]; |
|
114 return datarecord.style_guide + " " + datarecord.style_letter+ " " + datarecord.name; |
|
115 } |
|
116 }); |
|
117 $("#styleSelect").on('select', function (event) { |
|
118 if (event.args) { |
|
119 var index = event.args.index; |
|
120 var datarecord = styleslist.records[index]; |
|
121 $("#st_name").val(datarecord.name); |
|
122 $("#st_category").val(datarecord.category); |
|
123 $("#st_category_number").val(datarecord.category_number); |
|
124 $("#st_style_letter").val(datarecord.style_letter); |
|
125 $("#st_style_guide").val(datarecord.style_guide); |
|
126 $("#st_type").val(datarecord.type); |
|
127 $("#st_og_min").val(datarecord.og_min); |
|
128 $("#st_og_max").val(datarecord.og_max); |
|
129 $("#st_fg_min").val(datarecord.fg_min); |
|
130 $("#st_fg_max").val(datarecord.fg_max); |
|
131 $("#st_ibu_min").val(datarecord.ibu_min); |
|
132 $("#st_ibu_max").val(datarecord.ibu_max); |
|
133 $("#st_color_min").val(datarecord.color_min); |
|
134 $("#st_color_max").val(datarecord.color_max); |
|
135 $("#st_carb_min").val(datarecord.carb_min); |
|
136 $("#st_carb_max").val(datarecord.carb_max); |
|
137 $("#st_abv_min").val(datarecord.abv_min); |
|
138 $("#st_abv_max").val(datarecord.abv_max); |
|
139 $("#st_notes").val(datarecord.notes); |
|
140 $("#st_profile").val(datarecord.profile); |
|
141 $("#st_ingredients").val(datarecord.ingredients); |
|
142 $("#st_examples").val(datarecord.examples); |
|
143 } |
|
144 }); |
|
145 |
|
146 //Creating wizard module |
|
147 var wizard = (function () { |
|
148 |
|
149 //Adding event listeners |
|
150 var _addHandlers = function () { |
|
151 $('#name').on('change', function (event) { wizard.validate(true); }); |
|
152 $('#type').on('change', function (event) { wizard.validate(true); }); |
|
153 $('#boil_time').on('change', function (event) { wizard.validate(true); }); |
|
154 $('#est_og').on('change', function (event) { wizard.validate(true); }); |
|
155 $('#efficiency').on('change', function (event) { wizard.validate(true); }); |
|
156 $('#styleSelect').on('change', function (event) { wizard.validate(true); }); |
|
157 $('#nextButtonCompleted').click(function () { |
|
158 console.log("insert start"); |
|
159 var newrow = { |
|
160 record: -1, |
|
161 name: $("#name").val(), |
|
162 notes: $("#notes").val(), |
|
163 st_name: $('#st_name').val(), |
|
164 st_letter: $('#st_style_letter').val(), |
|
165 st_guide: $('#st_style_guide').val(), |
|
166 st_category: $('#st_category').val(), |
|
167 st_category_number: $('#st_category_number').val(), |
|
168 st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')), |
|
169 st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')), |
|
170 st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')), |
|
171 st_fg_max: parseFloat($("#st_fg_max").jqxNumberInput('decimal')), |
|
172 st_ibu_min: parseFloat($("#st_ibu_min").jqxNumberInput('decimal')), |
|
173 st_ibu_max: parseFloat($("#st_ibu_max").jqxNumberInput('decimal')), |
|
174 st_color_min: parseFloat($("#st_color_min").jqxNumberInput('decimal')), |
|
175 st_color_max: parseFloat($("#st_color_max").jqxNumberInput('decimal')), |
|
176 st_carb_min: parseFloat($("#st_carb_min").jqxNumberInput('decimal')), |
|
177 st_carb_max: parseFloat($("#st_carb_max").jqxNumberInput('decimal')), |
|
178 st_abv_min: parseFloat($("#st_abv_min").jqxNumberInput('decimal')), |
|
179 st_abv_max: parseFloat($("#st_abv_max").jqxNumberInput('decimal')), |
|
180 st_type: $("#st_type").val(), |
|
181 type: $("#type").val(), |
|
182 batch_size: 20.0, |
|
183 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), |
|
184 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')), |
|
185 est_og: parseFloat($("#est_og").jqxNumberInput('decimal')), |
|
186 est_fg: 1.000, |
|
187 est_color: 0, |
|
188 color_method: "Morey", |
|
189 est_ibu: 0, |
|
190 ibu_method: "Tinseth", |
|
191 mash_name: "", |
|
192 mash_ph: 5.4, |
|
193 mash_sparge_temp: 78.0 |
|
194 }; |
|
195 var data = "insert=true&return=" + my_return + "&" + $.param(newrow); |
|
196 $.ajax({ |
|
197 dataType: 'json', |
|
198 url: "includes/db_recipes.php", |
|
199 cache: false, |
|
200 data: data, |
|
201 type: "POST", |
|
202 success: function (data, status, xhr) { |
|
203 // update command is executed. |
|
204 window.location.href = my_return; |
|
205 }, |
|
206 error: function(jqXHR, textStatus, errorThrown) { |
|
207 } |
|
208 }); |
|
209 }); |
|
210 $('.nextButton').click(function () { |
|
211 wizard.validate(true); |
|
212 $('#jqxTabs').jqxTabs('next'); |
|
213 }); |
|
214 $('.backButton').click(function () { |
|
215 wizard.validate(true); |
|
216 $('#jqxTabs').jqxTabs('previous'); |
|
217 }); |
|
218 }; |
|
219 |
|
220 return { |
|
221 //Initializing the wizzard - creating all elements, adding event handlers and starting the validation |
|
222 init: function () { |
|
223 $('#jqxTabs').jqxTabs({ |
|
224 theme: theme, |
|
225 height: 630, |
|
226 width: 1280, |
|
227 autoHeight: false, |
|
228 position: 'top', |
|
229 keyboardNavigation: false |
|
230 }); |
|
231 $('#nextButtonBase').jqxButton({ theme: theme, width: 150 }); |
|
232 $('#nextButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
233 $('#backButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
234 $('#nextButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
235 $('#backButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
236 _addHandlers(); |
|
237 this.validate(); |
|
238 this.showHint('Validation hints.'); |
|
239 }, |
|
240 |
|
241 //Validating all wizard tabs |
|
242 validate: function (notify) { |
|
243 if (!this.firstTab(notify)) { |
|
244 $('#jqxTabs').jqxTabs('disableAt', 1); |
|
245 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
246 return; |
|
247 } else { |
|
248 $('#jqxTabs').jqxTabs('enableAt', 1); |
|
249 } |
|
250 if (!this.secondTab(notify)) { |
|
251 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
252 return; |
|
253 } else { |
|
254 $('#jqxTabs').jqxTabs('enableAt', 2); |
|
255 } |
|
256 }, |
|
257 |
|
258 //Displaying message to the user |
|
259 showHint: function (message, selector) { |
|
260 if (typeof selector === 'undefined') { |
|
261 selector = '.hint'; |
|
262 } |
|
263 if (message === '') { |
|
264 message = 'Ok, je mag doorgaan.'; |
|
265 } |
|
266 $(selector).html('<strong>' + message + '</strong>'); |
|
267 }, |
|
268 |
|
269 //Validating the first tab |
|
270 firstTab: function (notify) { |
|
271 var name = $('#name').val(), |
|
272 type = $('#type').val(), |
|
273 boil_time = parseFloat($("#boil_time").jqxNumberInput('decimal')), |
|
274 est_og = parseFloat($("#est_og").jqxNumberInput('decimal')), |
|
275 efficiency = parseFloat($("#efficiency").jqxNumberInput('decimal')), |
|
276 message = ''; |
|
277 if (name.length < 3) { |
|
278 message += 'Je moet een recept naam invullen. <br />'; |
|
279 } |
|
280 // Check if name already exists. |
|
281 if (type.length < 1) { |
|
282 message += 'Je moet een brouw type kiezen. <br />'; |
|
283 } |
|
284 if ((boil_time < 4) || (boil_time > 360)) { |
|
285 message += 'De kooktijd moet tussen 4 en 360 minuten zijn. <br />'; |
|
286 } |
|
287 if ((est_og < 1.010) || (est_og > 1.200)) { |
|
288 message += 'Het OG moet tussen 1.010 en 1.500 zijn. <br />'; |
|
289 } |
|
290 if ((efficiency < 35) || (efficiency > 95)) { |
|
291 message += 'Het brouwzaal rendement moet tussen 35 en 95 zijn. <br />'; |
|
292 } |
|
293 if (message !== '') { |
|
294 if (notify) { |
|
295 this.showHint(message, '#hintBase'); |
|
296 } |
|
297 return false; |
|
298 } |
|
299 this.showHint('Ok, je mag doorgaan.', '#hintBase'); |
|
300 return true; |
|
301 }, |
|
302 |
|
303 //Validating the second tab |
|
304 secondTab: function (notify) { |
|
305 var stylesel = $('#styleSelect').val(), |
|
306 message = ''; |
|
307 if (stylesel.length < 3) { |
|
308 message += 'Je moet een bierstijl kiezen. <br />'; |
|
309 } |
|
310 if (message !== '') { |
|
311 if (notify) { |
|
312 this.showHint(message, '#hintStyle'); |
|
313 } |
|
314 return false; |
|
315 } |
|
316 this.showHint('Ok, je mag doorgaan.', '#hintStyle'); |
|
317 return true; |
|
318 } |
|
319 } |
|
320 } ()); |
|
321 |
|
322 //Initializing the wizard |
|
323 wizard.init(); |
|
324 }); |
|
325 |