|
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 |
|
30 // editers |
|
31 var srcType = [ "All Grain", "Partial Mash", "Extract" ]; |
|
32 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); |
|
33 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); |
|
34 |
|
35 //Creating wizard module |
|
36 var wizard = (function () { |
|
37 |
|
38 //Adding event listeners |
|
39 var _addHandlers = function () { |
|
40 $('#name').on('change', function (event) { wizard.validate(true); }); |
|
41 $('#nextButtonCompleted').click(function () { |
|
42 console.log("insert start"); |
|
43 var newrow = { |
|
44 record: -1, |
|
45 name: $("#name").val(), |
|
46 notes: $("#notes").val(), |
|
47 }; |
|
48 var data = "insert=true&return=" + my_return + "&" + $.param(newrow); |
|
49 $.ajax({ |
|
50 dataType: 'json', |
|
51 url: "includes/db_product.php", |
|
52 cache: false, |
|
53 data: data, |
|
54 type: "POST", |
|
55 success: function (data, status, xhr) { |
|
56 // update command is executed. |
|
57 window.location.href = my_return; |
|
58 }, |
|
59 error: function(jqXHR, textStatus, errorThrown) { |
|
60 } |
|
61 }); |
|
62 }); |
|
63 $('.nextButton').click(function () { |
|
64 wizard.validate(true); |
|
65 $('#jqxTabs').jqxTabs('next'); |
|
66 }); |
|
67 $('.backButton').click(function () { |
|
68 wizard.validate(true); |
|
69 $('#jqxTabs').jqxTabs('previous'); |
|
70 }); |
|
71 }; |
|
72 |
|
73 return { |
|
74 //Initializing the wizzard - creating all elements, adding event handlers and starting the validation |
|
75 init: function () { |
|
76 $('#jqxTabs').jqxTabs({ |
|
77 theme: theme, |
|
78 height: 630, |
|
79 width: 1280, |
|
80 autoHeight: false, |
|
81 position: 'top', |
|
82 keyboardNavigation: false |
|
83 }); |
|
84 $('#nextButtonBase').jqxButton({ theme: theme, width: 150 }); |
|
85 $('#nextButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
86 $('#backButtonStyle').jqxButton({ theme: theme, width: 150}); |
|
87 $('#nextButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
88 $('#backButtonCompleted').jqxButton({ theme: theme, width: 150}); |
|
89 _addHandlers(); |
|
90 this.validate(); |
|
91 this.showHint('Validation hints.'); |
|
92 }, |
|
93 |
|
94 //Validating all wizard tabs |
|
95 validate: function (notify) { |
|
96 if (!this.firstTab(notify)) { |
|
97 $('#jqxTabs').jqxTabs('disableAt', 1); |
|
98 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
99 return; |
|
100 } else { |
|
101 $('#jqxTabs').jqxTabs('enableAt', 1); |
|
102 } |
|
103 if (!this.secondTab(notify)) { |
|
104 $('#jqxTabs').jqxTabs('disableAt', 2); |
|
105 return; |
|
106 } else { |
|
107 $('#jqxTabs').jqxTabs('enableAt', 2); |
|
108 } |
|
109 }, |
|
110 |
|
111 //Displaying message to the user |
|
112 showHint: function (message, selector) { |
|
113 if (typeof selector === 'undefined') { |
|
114 selector = '.hint'; |
|
115 } |
|
116 if (message === '') { |
|
117 message = 'Ok, je mag doorgaan.'; |
|
118 } |
|
119 $(selector).html('<strong>' + message + '</strong>'); |
|
120 }, |
|
121 |
|
122 //Validating the first tab |
|
123 firstTab: function (notify) { |
|
124 var name = $('#name').val(), |
|
125 message = ''; |
|
126 if (name.length < 3) { |
|
127 message += 'Je moet een recept naam invullen. <br />'; |
|
128 } |
|
129 // Check if name already exists. |
|
130 //if ((boil_time < 4) || (boil_time > 360)) { |
|
131 // message += 'De kooktijd moet tussen 4 en 360 minuten zijn. <br />'; |
|
132 //} |
|
133 //if ((est_og < 1.010) || (est_og > 1.200)) { |
|
134 // message += 'Het OG moet tussen 1.010 en 1.500 zijn. <br />'; |
|
135 //} |
|
136 //if ((efficiency < 35) || (efficiency > 95)) { |
|
137 // message += 'Het brouwzaal rendement moet tussen 35 en 95 zijn. <br />'; |
|
138 //} |
|
139 if (message !== '') { |
|
140 if (notify) { |
|
141 this.showHint(message, '#hintBase'); |
|
142 } |
|
143 return false; |
|
144 } |
|
145 this.showHint('Ok, je mag doorgaan.', '#hintBase'); |
|
146 return true; |
|
147 }, |
|
148 |
|
149 //Validating the second tab |
|
150 secondTab: function (notify) { |
|
151 var stylesel = $('#styleSelect').val(), |
|
152 message = ''; |
|
153 if (stylesel.length < 3) { |
|
154 message += 'Je moet een bierstijl kiezen. <br />'; |
|
155 } |
|
156 if (message !== '') { |
|
157 if (notify) { |
|
158 this.showHint(message, '#hintStyle'); |
|
159 } |
|
160 return false; |
|
161 } |
|
162 this.showHint('Ok, je mag doorgaan.', '#hintStyle'); |
|
163 return true; |
|
164 } |
|
165 } |
|
166 } ()); |
|
167 |
|
168 //Initializing the wizard |
|
169 wizard.init(); |
|
170 }); |
|
171 |