www/js/rec_new.js

changeset 812
d286bf289d45
parent 811
4e3409cfd2b1
child 813
752bb80362fb
equal deleted inserted replaced
811:4e3409cfd2b1 812:d286bf289d45
1 /*****************************************************************************
2 * Copyright (C) 2018-2020
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 var recipe_type = 2,
27 style_type = 0,
28
29 //Creating wizard module
30 wizard = (function() {
31
32 //Adding event listeners
33 var _addHandlers = function() {
34 $('#name').on('change', function(event) { wizard.validate(true); });
35 $('#type').on('change', function(event) { wizard.validate(true); });
36 $('#boil_time').on('change', function(event) { wizard.validate(true); });
37 $('#est_og').on('change', function(event) { wizard.validate(true); });
38 $('#efficiency').on('change', function(event) { wizard.validate(true); });
39 $('#styleSelect').on('change', function(event) { wizard.validate(true); });
40 $('#nextButtonCompleted').click(function() {
41 console.log('insert start');
42 var newrow = {
43 record: -1,
44 locked: 0,
45 name: $('#name').val(),
46 notes: $('#notes').val(),
47 st_name: $('#st_name').val(),
48 st_letter: $('#st_style_letter').val(),
49 st_guide: $('#st_style_guide').val(),
50 st_category: $('#st_category').val(),
51 st_category_number: $('#st_category_number').val(),
52 st_type: style_type,
53 st_og_min: parseFloat($('#st_og_min').jqxNumberInput('decimal')),
54 st_og_max: parseFloat($('#st_og_max').jqxNumberInput('decimal')),
55 st_fg_min: parseFloat($('#st_fg_min').jqxNumberInput('decimal')),
56 st_fg_max: parseFloat($('#st_fg_max').jqxNumberInput('decimal')),
57 st_ibu_min: parseFloat($('#st_ibu_min').jqxNumberInput('decimal')),
58 st_ibu_max: parseFloat($('#st_ibu_max').jqxNumberInput('decimal')),
59 st_color_min: parseFloat($('#st_color_min').jqxNumberInput('decimal')),
60 st_color_max: parseFloat($('#st_color_max').jqxNumberInput('decimal')),
61 st_carb_min: parseFloat($('#st_carb_min').jqxNumberInput('decimal')),
62 st_carb_max: parseFloat($('#st_carb_max').jqxNumberInput('decimal')),
63 st_abv_min: parseFloat($('#st_abv_min').jqxNumberInput('decimal')),
64 st_abv_max: parseFloat($('#st_abv_max').jqxNumberInput('decimal')),
65 type: recipe_type,
66 batch_size: 20.0,
67 boil_size: 22.0,
68 boil_time: parseFloat($('#boil_time').jqxNumberInput('decimal')),
69 efficiency: parseFloat($('#efficiency').jqxNumberInput('decimal')),
70 est_og: parseFloat($('#est_og').jqxNumberInput('decimal')),
71 est_fg: 1.000,
72 est_color: 0,
73 est_abv: 0.0,
74 est_carb: 0.0,
75 color_method: 0, // Morey
76 est_ibu: 0,
77 ibu_method: 0, // Tinseth
78 mash_name: '',
79 mash_ph: 5.4,
80 sparge_temp: 85.0,
81 sparge_volume: 12.0,
82 sparge_ph: 5.8,
83 sparge_source: 0, // Source 1
84 sparge_acid_type: 0, // Lactic acid
85 sparge_acid_perc: 80,
86 sparge_acid_amount: 0,
87 calc_acid: 1,
88 w1_name: 'Tap water',
89 w1_amount: 15,
90 w1_calcium: 0,
91 w1_sulfate: 0,
92 w1_chloride: 0,
93 w1_sodium: 0,
94 w1_magnesium: 0,
95 w1_total_alkalinity: 0,
96 w1_ph: 7.0,
97 w1_cost: 0.0,
98 wg_amount: 15,
99 wg_calcium: 0,
100 wg_sulfate: 0,
101 wg_chloride: 0,
102 wg_sodium: 0,
103 wg_magnesium: 0,
104 wg_total_alkalinity: 0,
105 wg_ph: 7.0,
106 wb_calcium: 0,
107 wb_sulfate: 0,
108 wb_sodium: 0,
109 wb_chloride: 0,
110 wb_magnesium: 0,
111 wb_total_alkalinity: 0,
112 wb_ph: 0,
113 wa_acid_name: 0, // Lactic acid
114 wa_acid_perc: 80,
115 wa_base_name: 0
116 },
117 data = 'insert=true&return=' + my_return + '&' + $.param(newrow);
118 $.ajax({
119 dataType: 'json',
120 url: 'includes/db_recipes.php',
121 cache: false,
122 data: data,
123 type: 'POST',
124 success: function(data, status, xhr) {
125 // update command is executed.
126 window.location.href = my_return;
127 },
128 error: function(jqXHR, textStatus, errorThrown) {
129 }
130 });
131 });
132 $('.nextButton').click(function() {
133 wizard.validate(true);
134 $('#jqxTabs').jqxTabs('next');
135 });
136 $('.backButton').click(function() {
137 wizard.validate(true);
138 $('#jqxTabs').jqxTabs('previous');
139 });
140 };
141
142 return {
143 //Initializing the wizzard - creating all elements, adding event handlers and starting the validation
144 init: function() {
145 $('#jqxTabs').jqxTabs({
146 theme: theme,
147 height: 630,
148 width: 1280,
149 autoHeight: false,
150 position: 'top',
151 keyboardNavigation: false
152 });
153 $('#nextButtonBase').jqxButton({ theme: theme, width: 150 });
154 $('#nextButtonStyle').jqxButton({ theme: theme, width: 150});
155 $('#backButtonStyle').jqxButton({ theme: theme, template: 'success', width: 150});
156 $('#nextButtonCompleted').jqxButton({ theme: theme, template: 'success', width: 150});
157 $('#backButtonCompleted').jqxButton({ theme: theme, template: 'success', width: 150});
158 _addHandlers();
159 this.validate();
160 this.showHint('Vul de nodige gegevens in.');
161 },
162
163 //Validating all wizard tabs
164 validate: function(notify) {
165 if (!this.firstTab(notify)) {
166 $('#jqxTabs').jqxTabs('disableAt', 1);
167 $('#jqxTabs').jqxTabs('disableAt', 2);
168 return;
169 } else {
170 $('#jqxTabs').jqxTabs('enableAt', 1);
171 }
172 if (!this.secondTab(notify)) {
173 $('#jqxTabs').jqxTabs('disableAt', 2);
174 return;
175 } else {
176 $('#jqxTabs').jqxTabs('enableAt', 2);
177 }
178 },
179
180 //Displaying message to the user
181 showHint: function(message, selector) {
182 if (typeof selector === 'undefined') {
183 selector = '.hint';
184 }
185 if (message === '') {
186 message = 'Ok, je mag doorgaan.';
187 }
188 $(selector).html('<strong>' + message + '</strong>');
189 },
190
191 //Validating the first tab
192 firstTab: function(notify) {
193 var name = $('#name').val(),
194 type = $('#type').val(),
195 boil_time = parseFloat($('#boil_time').jqxNumberInput('decimal')),
196 est_og = parseFloat($('#est_og').jqxNumberInput('decimal')),
197 efficiency = parseFloat($('#efficiency').jqxNumberInput('decimal')),
198 message = '';
199 if (name.length < 3) {
200 message += 'Je moet een recept naam invullen. <br />';
201 }
202 // Check if name already exists.
203 if (type.length < 1) {
204 message += 'Je moet een brouw type kiezen. <br />';
205 }
206 if ((boil_time < 4) || (boil_time > 360)) {
207 message += 'De kooktijd moet tussen 4 en 360 minuten zijn. <br />';
208 }
209 if ((est_og < 1.010) || (est_og > 1.200)) {
210 message += 'Het OG moet tussen 1.010 en 1.200 zijn. <br />';
211 }
212 if ((efficiency < 35) || (efficiency > 95)) {
213 message += 'Het brouwzaal rendement moet tussen 35 en 95 zijn. <br />';
214 }
215 if (message !== '') {
216 if (notify) {
217 this.showHint(message, '#hintBase');
218 }
219 return false;
220 }
221 this.showHint('Ok, je mag doorgaan.', '#hintBase');
222 $('#nextButtonBase').jqxButton({ template: 'success' });
223 return true;
224 },
225
226 //Validating the second tab
227 secondTab: function(notify) {
228 var stylesel = $('#styleSelect').val(),
229 message = '';
230 if (stylesel.length < 3) {
231 message += 'Je moet een bierstijl kiezen. <br />';
232 }
233 if (message !== '') {
234 if (notify) {
235 this.showHint(message, '#hintStyle');
236 }
237 return false;
238 }
239 this.showHint('Ok, je mag doorgaan.', '#hintStyle');
240 $('#nextButtonStyle').jqxButton({ template: 'success' });
241 return true;
242 }
243 };
244 } ());
245
246 // Tab 1, Base
247 $('#name').jqxTooltip({ content: 'De naam voor dit recept.' });
248 $('#name').jqxInput({ theme: theme, width: 640, height: 23 });
249 $('#notes').jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' });
250 $('#notes').jqxInput({ theme: theme, width: 960, height: 200 });
251 $('#type').jqxDropDownList({
252 theme: theme,
253 source: RecipeTypeAdapter,
254 valueMember: 'id',
255 displayMember: 'nl',
256 width: 180,
257 height: 23,
258 autoDropDownHeight: true
259 });
260 $('#type').jqxDropDownList('selectItem', 2);
261 $('#type').on('select', function(event) {
262 if (event.args) {
263 recipe_type = event.args.index;
264 }
265 });
266 $('#boil_time').jqxNumberInput(PosInt);
267 $('#boil_time').jqxNumberInput({ min: 4, max: 360 });
268 $('#efficiency').jqxNumberInput(Perc0);
269 $('#est_og').jqxNumberInput(SGopts);
270 // Default values.
271 $('#boil_time').val(90);
272 $('#efficiency').val(75);
273 $('#est_og').val(1.052);
274
275 // Tab 2, Style
276 $('#st_name').jqxInput({ theme: theme, width: 250, height: 23 });
277 $('#st_category').jqxInput({ theme: theme, width: 250, height: 23 });
278 $('#st_category_number').jqxInput({ theme: theme, width: 70, height: 23 });
279 $('#st_style_letter').jqxInput({ theme: theme, width: 250, height: 23 });
280 $('#st_style_guide').jqxInput({ theme: theme, width: 250, height: 23 });
281 $('#st_notes').jqxInput({ theme: theme, width: 800, height: 100 });
282 $('#st_type').jqxInput({ theme: theme, width: 250, height: 23 });
283 $('#st_og_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
284 $('#st_og_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
285 $('#st_fg_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
286 $('#st_fg_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
287 $('#st_ibu_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
288 $('#st_ibu_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
289 $('#st_color_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
290 $('#st_color_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 0, readOnly: true });
291 $('#st_carb_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
292 $('#st_carb_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
293 $('#st_abv_min').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
294 $('#st_abv_max').jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
295 $('#st_profile').jqxInput({ theme: theme, width: 800, height: 48 });
296 $('#st_ingredients').jqxInput({ theme: theme, width: 800, height: 23 });
297 $('#st_examples').jqxInput({ theme: theme, width: 800, height: 48 });
298 $('#styleSelect').jqxDropDownList({
299 placeHolder: 'Kies bierstijl:',
300 theme: theme,
301 source: styleslist,
302 displayMember: 'name',
303 width: 250,
304 height: 27,
305 dropDownWidth: 500,
306 dropDownHeight: 500,
307 renderer: function(index, label, value) {
308 var datarecord = styleslist.records[index];
309 return datarecord.style_guide + ' ' + datarecord.style_letter + ' ' + datarecord.name;
310 }
311 });
312 $('#styleSelect').on('select', function(event) {
313 if (event.args) {
314 var datarecord, index = event.args.index;
315 datarecord = styleslist.records[index];
316 $('#st_name').val(datarecord.name);
317 $('#st_category').val(datarecord.category);
318 $('#st_category_number').val(datarecord.category_number);
319 $('#st_style_letter').val(datarecord.style_letter);
320 $('#st_style_guide').val(datarecord.style_guide);
321 style_type = datarecord.type;
322 $('#st_type').val(StyleTypeData[datarecord.type].nl);
323 $('#st_og_min').val(datarecord.og_min);
324 $('#st_og_max').val(datarecord.og_max);
325 $('#st_fg_min').val(datarecord.fg_min);
326 $('#st_fg_max').val(datarecord.fg_max);
327 $('#st_ibu_min').val(datarecord.ibu_min);
328 $('#st_ibu_max').val(datarecord.ibu_max);
329 $('#st_color_min').val(datarecord.color_min);
330 $('#st_color_max').val(datarecord.color_max);
331 $('#st_carb_min').val(datarecord.carb_min);
332 $('#st_carb_max').val(datarecord.carb_max);
333 $('#st_abv_min').val(datarecord.abv_min);
334 $('#st_abv_max').val(datarecord.abv_max);
335 $('#st_notes').val(datarecord.notes);
336 $('#st_profile').val(datarecord.profile);
337 $('#st_ingredients').val(datarecord.ingredients);
338 $('#st_examples').val(datarecord.examples);
339 }
340 });
341
342 //Initializing the wizard
343 wizard.init();
344 });
345

mercurial