www/js/prod_edit.js

changeset 112
7ef48396f705
parent 111
8c4ba91adf58
child 114
4935e86b2775
equal deleted inserted replaced
111:8c4ba91adf58 112:7ef48396f705
17 * 17 *
18 * You should have received a copy of the GNU General Public License 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 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. 20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/ 21 *****************************************************************************/
22
23
24 function createDelElements() {
25
26 $('#eventWindow').jqxWindow({
27 theme: theme,
28 position: { x: 490, y: 210 },
29 width: 300,
30 height: 175,
31 resizable: false,
32 isModal: true,
33 modalOpacity: 0.4,
34 okButton: $('#delOk'),
35 cancelButton: $('#delCancel'),
36 initContent: function () {
37 $('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme });
38 $('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme });
39 $('#delCancel').focus();
40 }
41 });
42 $('#eventWindow').jqxWindow('hide');
43 }
44
22 45
23 46
24 $(document).ready(function () { 47 $(document).ready(function () {
25 48
26 console.log("record:" + my_record + " return:" + my_return + " theme:" + theme); 49 console.log("record:" + my_record + " return:" + my_return + " theme:" + theme);
121 $("#eq_kettle_height").val(dataRecord.eq_kettle_height); 144 $("#eq_kettle_height").val(dataRecord.eq_kettle_height);
122 $("#eq_lauter_height").val(dataRecord.eq_lauter_height); 145 $("#eq_lauter_height").val(dataRecord.eq_lauter_height);
123 $("#eq_mash_volume").val(dataRecord.eq_mash_volume); 146 $("#eq_mash_volume").val(dataRecord.eq_mash_volume);
124 $("#eq_efficiency").val(dataRecord.eq_efficiency); 147 $("#eq_efficiency").val(dataRecord.eq_efficiency);
125 148
149 if (dataRecord.stage != "Plan") {
150 // Only allow Delete when in Plan stage.
151 $("#Delete").jqxButton({ disabled: true });
152 }
126 }, 153 },
127 loadError: function (jqXHR, status, error) { 154 loadError: function (jqXHR, status, error) {
128 }, 155 },
129 beforeLoadComplete: function (records) { 156 beforeLoadComplete: function (records) {
130 var filteredRecords = []; 157 var filteredRecords = [];
141 // initialize the input fields. 168 // initialize the input fields.
142 var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ]; 169 var srcMaterial= [ "RVS", "Aluminium", "Kunststof", "Koper" ];
143 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); 170 $("#name").jqxInput({ theme: theme, width: 640, height: 23 });
144 $("#code").jqxInput({ theme: theme, width: 100, height: 23 }); 171 $("#code").jqxInput({ theme: theme, width: 100, height: 23 });
145 $("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' }); 172 $("#birth").jqxDateTimeInput({ theme: theme, width: 150, height: 23, formatString: 'yyyy-MM-dd' });
146 $("#stage").jqxInput({ theme: theme, width: 100, height: 23, disabled: true }); 173 $("#stage").jqxInput({ theme: theme, width: 100, height: 23 });
147 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 }); 174 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
148 $("#eq_name").jqxInput({ theme: theme, width: 250, height: 23 }); 175 $("#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 }); 176 $("#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 }); 177 $("#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 }); 178 $("#eq_tun_volume").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
172 height: 630, 199 height: 630,
173 autoHeight: false, 200 autoHeight: false,
174 position: 'top' 201 position: 'top'
175 }); 202 });
176 203
177 204 // Buttons sidebar
178 205 $("#rec_edit").jqxButton({ template: "primary", width: '110px', theme: theme });
179 /* 206
180 //Creating wizard module 207 // Buttons below
181 var wizard = (function () { 208 $("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
182 209 $("#Delete").click(function () {
183 //Adding event listeners 210 // Open a popup to confirm this action.
184 var _addHandlers = function () { 211 $('#eventWindow').jqxWindow('open');
185 $('#name').on('change', function (event) { wizard.validate(true); }); 212 $("#delOk").click(function () {
186 $('#nextButtonCompleted').click(function () { 213 var data = "delete=true&" + $.param({ record: my_record });
187 console.log("insert start"); 214 $.ajax({
188 var newrow = { 215 dataType: 'json',
189 record: -1, 216 url: url,
190 name: $("#name").val(), 217 cache: false,
191 notes: $("#notes").val(), 218 data: data,
192 st_name: $('#st_name').val(), 219 type: "POST",
193 st_letter: $('#st_style_letter').val(), 220 success: function (data, status, xhr) {
194 mash_ph: 5.4, 221 // delete command is executed.
195 mash_sparge_temp: 78.0 222 window.location.href = my_return;
196 }; 223 },
197 var data = "insert=true&return=" + my_return + "&" + $.param(newrow); 224 error: function (jqXHR, textStatus, errorThrown) {
198 $.ajax({ 225 }
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 }); 226 });
212 $('.nextButton').click(function () { 227 });
213 wizard.validate(true); 228 });
214 $('#jqxTabs').jqxTabs('next'); 229
215 }); 230 $("#Cancel").jqxButton({ template: "primary", width: '80px', theme: theme });
216 $('.backButton').click(function () { 231 $("#Cancel").click(function () {
217 wizard.validate(true); 232 window.location.href = my_return;
218 $('#jqxTabs').jqxTabs('previous'); 233 });
219 }); 234
220 }; 235 createDelElements();
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 }); 236 });
328 237

mercurial