www/js/recipes.js

changeset 74
595fee82e063
parent 73
454fc4558609
child 75
1a3c6480e057
equal deleted inserted replaced
73:454fc4558609 74:595fee82e063
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 function createDelElements() {
25 $('#eventWindow').jqxWindow({
26 theme: theme,
27 position: { x: 490, y: 210 },
28 width: 300,
29 height: 175,
30 resizable: false,
31 isModal: true,
32 modalOpacity: 0.4,
33 okButton: $('#delOk'),
34 cancelButton: $('#delCancel'),
35 initContent: function () {
36 $('#delOk').jqxButton({ width: '65px', theme: theme });
37 $('#delCancel').jqxButton({ width: '65px', theme: theme });
38 $('#delCancel').focus();
39 }
40 });
41 $('#eventWindow').jqxWindow('hide');
42 }
43
44
45 $(document).ready(function () {
46 var url = "includes/db_recipes.php";
47 // tooltips
48 $("#name").jqxTooltip({ content: 'De naam voor dit recept.' });
49 $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit recept.' });
50 $("#st_name").jqxTooltip({ content: 'De bierstijl naam voor dit recept.'});
51 $("#type").jqxTooltip({ content: 'Het brouw type van dit recept.' });
52 // prepare the data
53 var source = {
54 datatype: "json",
55 cache: false,
56 datafields: [
57 { name: 'record', type: 'number' },
58 { name: 'st_name', type: 'string' },
59 { name: 'st_letter', type: 'string' },
60 { name: 'st_guide', type: 'string' },
61 { name: 'st_og_min', type: 'float' },
62 { name: 'st_og_max', type: 'float' },
63 { name: 'st_fg_min', type: 'float' },
64 { name: 'st_fg_max', type: 'float' },
65 { name: 'st_ibu_min', type: 'float' },
66 { name: 'st_ibu_max', type: 'float' },
67 { name: 'st_color_min', type: 'float' },
68 { name: 'st_color_max', type: 'float' },
69 { name: 'st_carb_min', type: 'float' },
70 { name: 'st_carb_max', type: 'float' },
71 { name: 'st_abv_min', type: 'float' },
72 { name: 'st_abv_max', type: 'float' },
73 { name: 'name', type: 'string' },
74 { name: 'notes', type: 'string' },
75 { name: 'type', type: 'number' },
76 { name: 'batch_size', type: 'float' },
77 { name: 'boil_time', type: 'float' },
78 { name: 'efficiency', type: 'float' },
79 { name: 'est_og', type: 'float' },
80 { name: 'est_fg', type: 'float' },
81 { name: 'est_color', type: 'float' },
82 { name: 'color_method', type: 'string' },
83 { name: 'est_ibu', type: 'float' },
84 { name: 'ibu_method', type: 'string' },
85 { name: 'mash_sparge_temp', type: 'float' },
86 { name: 'mash_ph', type: 'float' },
87 { name: 'mash_name', type: 'string' },
88 { name: 'fermentables', type: 'string' },
89 { name: 'hops', type: 'string' },
90 { name: 'miscs', type: 'string' },
91 { name: 'yeasts', type: 'string' },
92 { name: 'waters', type: 'array' },
93 { name: 'mashs', type: 'string' }
94 ],
95 id: 'record',
96 url: url,
97 deleterow: function (rowid, commit) {
98 // synchronize with the server - send delete command
99 var data = "delete=true&" + $.param({ record: rowid });
100 $.ajax({
101 dataType: 'json',
102 url: url,
103 cache: false,
104 data: data,
105 type: "POST",
106 success: function (data, status, xhr) {
107 // delete command is executed.
108 commit(true);
109 },
110 error: function (jqXHR, textStatus, errorThrown) {
111 commit(false);
112 }
113 });
114 },
115 addrow: function (rowid, rowdata, position, commit) {
116 var data = "insert=true&" + $.param(rowdata);
117 $.ajax({
118 dataType: 'json',
119 url: url,
120 cache: false,
121 data: data,
122 type: "POST",
123 success: function (data, status, xhr) {
124 commit(true);
125 },
126 error: function(jqXHR, textStatus, errorThrown) {
127 commit(false);
128 }
129 });
130 },
131 updaterow: function (rowid, rowdata, commit) {
132 var data = "update=true&" + $.param(rowdata);
133 $.ajax({
134 dataType: 'json',
135 url: url,
136 cache: false,
137 data: data,
138 type: "POST",
139 success: function (data, status, xhr) {
140 // update command is executed.
141 commit(true);
142 },
143 error: function(jqXHR, textStatus, errorThrown) {
144 commit(false);
145 }
146 });
147 }
148 };
149 var dataAdapter = new $.jqx.dataAdapter(source);
150
151 // Inline fermentables editor
152 var editFermentable = function (data) {
153 var fermentableSource = {
154 localdata: data.fermentables,
155 datatype: "local",
156 datafields: [
157 { name: 'f_name', type: 'string' },
158 { name: 'f_origin', type: 'string' },
159 { name: 'f_supplier', type: 'string' },
160 { name: 'f_amount', type: 'float' },
161 { name: 'f_cost', type: 'float' },
162 { name: 'f_type', type: 'string' },
163 { name: 'f_yield', type: 'float' },
164 { name: 'f_color', type: 'float' },
165 { name: 'f_coarse_fine_diff', type: 'float' },
166 { name: 'f_moisture', type: 'float' },
167 { name: 'f_diastatic_power', type: 'float' },
168 { name: 'f_protein', type: 'float' },
169 { name: 'f_max_in_batch', type: 'float' },
170 { name: 'f_graintype', type: 'string' },
171 { name: 'f_added', type: 'string' },
172 { name: 'f_dissolved_protein', type: 'float' },
173 { name: 'f_recommend_mash', type: 'bool' },
174 { name: 'f_add_after_boil', type: 'bool' },
175 { name: 'f_adjust_to_total_100', type: 'bool' },
176 { name: 'f_percentage', type: 'float' },
177 { name: 'f_di_ph', type: 'float' }
178 ],
179 addrow: function (rowid, rowdata, position, commit) {
180 commit(true);
181 },
182 deleterow: function (rowid, commit) {
183 commit(true);
184 }
185 };
186 var fermentableAdapter = new $.jqx.dataAdapter(fermentableSource);
187 // dropdownlist datasource from inventory_fermentables
188 var fermentableUrl = "getfermentablesources.php";
189 var fermentableInvSource = {
190 datatype: "json",
191 datafields: [
192 { name: 'record', type: 'number' },
193 { name: 'name', type: 'string' },
194 { name: 'type', type: 'string' },
195 { name: 'yield', type: 'float' },
196 { name: 'color', type: 'float' },
197 { name: 'add_after_boil', type: 'bool' },
198 { name: 'origin', type: 'string' },
199 { name: 'supplier', type: 'string' },
200 { name: 'coarse_fine_diff', type: 'float' },
201 { name: 'moisture', type: 'float' },
202 { name: 'diastatic_power', type: 'float' },
203 { name: 'protein', type: 'float' },
204 { name: 'max_in_batch', type: 'float' },
205 { name: 'recommend_mash', type: 'bool' },
206 { name: 'graintype', type: 'string' },
207 { name: 'di_ph', type: 'float' },
208 { name: 'inventory', type: 'float' },
209 { name: 'cost', type: 'float' }
210 ],
211 url: fermentableUrl,
212 async: true
213 };
214 var fermentablelist = new $.jqx.dataAdapter(fermentableInvSource);
215
216 $("#fermentableGrid").jqxGrid({
217 width: 960,
218 height: 400,
219 source: fermentableAdapter,
220 theme: theme,
221 selectionmode: 'singlerow',
222 editmode: 'selectedrow',
223 editable: true,
224 localization: getLocalization(),
225 showtoolbar: true,
226 rendertoolbar: function (toolbar) {
227 var me = this;
228 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
229 toolbar.append(container);
230 container.append('<div style="float: left; margin-left: 165px;" id="faddrowbutton"></div>');
231 container.append('<input style="float: left; margin-left: 230px;" id="fdeleterowbutton" type="button" value="Verwijder mout" />');
232 // add fermentable from dropdownlist.
233 $("#faddrowbutton").jqxDropDownList({
234 placeHolder: "Kies mout:",
235 theme: theme,
236 source: fermentablelist,
237 displayMember: "name",
238 width: 150,
239 height: 27,
240 dropDownWidth: 500,
241 dropDownHeight: 500,
242 renderer: function (index, label, value) {
243 var datarecord = fermentablelist.records[index];
244 return datarecord.supplier+ " / " + datarecord.name + " (" + datarecord.color + " EBC)";
245 }
246 });
247 $("#faddrowbutton").on('select', function (event) {
248 if (event.args) {
249 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
250 var index = event.args.index;
251 var datarecord = fermentablelist.records[index];
252 var row = {};
253 row["f_name"] = datarecord.name;
254 row["f_origin"] = datarecord.origin;
255 row["f_supplier"] = datarecord.supplier;
256 row["f_amount"] = 0;
257 row["f_cost"] = datarecord.cost;
258 row["f_type"] = datarecord.type;
259 row["f_yield"] = datarecord.yield;
260 row["f_color"] = datarecord.color;
261 row["f_coarse_fine_diff"] = datarecord.coarse_fine_diff;
262 row["f_moisture"] = datarecord.moisture;
263 row["f_diastatic_power"] = datarecord.diastatic_power;
264 row["f_protein"] = datarecord.protein;
265 row["f_max_in_batch"] = datarecord.max_in_batch;
266 row["f_graintype"] = datarecord.graintype;
267 if (datarecord.type == "Sugar") {
268 row["f_added"] = "Boil";
269 } else {
270 row["f_added"] = "Mash";
271 }
272 row["f_dissolved_protein"] = 0;
273 row["f_recommend_mash"] = datarecord.recommend_mash;
274 row["f_add_after_boil"] = datarecord.add_after_boil;
275 if (rowscount == 0) {
276 // The first fermentable
277 row["f_adjust_to_total_100"] = 1;
278 row["f_percentage"] = 100;
279 } else {
280 row["f_adjust_to_total_100"] = 0;
281 row["f_percentage"] = 0;
282 }
283 row["f_di_ph"] = datarecord.di_ph;
284 var commit = $("#fermentableGrid").jqxGrid('addrow', null, row);
285 }
286 });
287
288 // delete selected fermentable.
289 // Precentage aanpassen basis mout.
290 $("#fdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
291 $("#fdeleterowbutton").on('click', function () {
292 var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
293 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
294 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
295 var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex);
296 var commit = $("#fermentableGrid").jqxGrid('deleterow', id);
297 }
298 });
299 },
300 columns: [
301 { text: 'Mout/suiker', editable: false, datafield: 'f_name',
302 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
303 var rowData = $("#fermentableGrid").jqxGrid('getrowdata', row);
304 return rowData.f_name + " (" + rowData.f_color + " EBC)";
305 }
306 },
307 { text: 'Type', editable: false, width: 100, datafield: 'f_type' },
308 { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
309 { text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
310 columntype: 'numberinput',
311 validation: function (cell, value) {
312 // Maximum weight is the batch_size, just a simple check.
313 var maxmout = parseFloat($("#batch_size").jqxNumberInput('decimal'));
314 if (value < 0 || value > maxmout) {
315 return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" };
316 }
317 return true;
318 },
319 initeditor: function (row, cellvalue, editor) {
320 editor.jqxNumberInput({ decimalDigits: 3 });
321 }
322 },
323 { text: 'Procent', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1',
324 columntype: 'numberinput',
325 validation: function (cell, value) {
326 if (value < 0 || value > 100) {
327 return { result: false, message: "Percentage moet 0-100 zijn" };
328 }
329 return true;
330 },
331 initeditor: function (row, cellvalue, editor) {
332 editor.jqxNumberInput({ decimalDigits: 1 });
333 }
334 },
335 { text: '100%', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80 }
336 ]
337 });
338 $("#fermentableGrid").on('cellendedit', function (event) {
339 $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');
340 });
341 };
342
343 // Inline hops editor
344 var editHop = function (data) {
345 var hopSource = {
346 localdata: data.hops,
347 datatype: "local",
348 cache: false,
349 datafields: [
350 { name: 'h_name', type: 'string' },
351 { name: 'h_origin', type: 'string' },
352 { name: 'h_amount', type: 'float' },
353 { name: 'h_cost', type: 'float' },
354 { name: 'h_type', type: 'string' },
355 { name: 'h_form', type: 'string' },
356 { name: 'h_useat', type: 'string' },
357 { name: 'h_time', type: 'float' },
358 { name: 'h_alpha', type: 'float' },
359 { name: 'h_beta', type: 'float' },
360 { name: 'h_hsi', type: 'float' },
361 { name: 'h_humulene', type: 'float' },
362 { name: 'h_carophyllene', type: 'float' },
363 { name: 'h_cohumulone', type: 'float' },
364 { name: 'h_myrcene', type: 'float' },
365 { name: 'h_total_oil', type: 'float' }
366 ],
367 addrow: function (rowid, rowdata, position, commit) {
368 commit(true);
369 },
370 deleterow: function (rowid, commit) {
371 commit(true);
372 }
373 };
374 var hopAdapter = new $.jqx.dataAdapter(hopSource);
375 // dropdownlist datasource from inventory_hops
376 var hopUrl = "gethopsources.php";
377 var hopInvSource = {
378 datatype: "json",
379 datafields: [
380 { name: 'record', type: 'number' },
381 { name: 'name', type: 'string' },
382 { name: 'origin', type: 'string' },
383 { name: 'type', type: 'string' },
384 { name: 'alpha', type: 'float' },
385 { name: 'beta', type: 'float' },
386 { name: 'humulene', type: 'float' },
387 { name: 'caryophyllene', type: 'float' },
388 { name: 'cohumulone', type: 'float' },
389 { name: 'myrcene', type: 'float' },
390 { name: 'hsi', type: 'float' },
391 { name: 'useat', type: 'string' },
392 { name: 'form', type: 'string' },
393 { name: 'total_oil', type: 'float' },
394 { name: 'cost', type: 'float' }
395 ],
396 url: hopUrl,
397 async: true
398 };
399 var hoplist = new $.jqx.dataAdapter(hopInvSource);
400
401 $("#hopGrid").jqxGrid({
402 width: 960,
403 height: 400,
404 source: hopAdapter,
405 theme: theme,
406 selectionmode: 'singlerow',
407 editmode: 'selectedrow',
408 editable: true,
409 localization: getLocalization(),
410 showtoolbar: true,
411 rendertoolbar: function (toolbar) {
412 var me = this;
413 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
414 toolbar.append(container);
415 container.append('<div style="float: left; margin-left: 165px;" id="haddrowbutton"></div>');
416 container.append('<input style="float: left; margin-left: 230px;" id="hdeleterowbutton" type="button" value="Verwijder hop" />');
417 // add hop from dropdownlist.
418 $("#haddrowbutton").jqxDropDownList({
419 placeHolder: "Kies hop:",
420 theme: theme,
421 source: hoplist,
422 displayMember: "name",
423 width: 150,
424 height: 27,
425 dropDownWidth: 300
426 });
427 $("#haddrowbutton").on('select', function (event) {
428 if (event.args) {
429 var index = event.args.index;
430 var datarecord = hoplist.records[index];
431 var row = {};
432 row["h_name"] = datarecord.name;
433 row["h_origin"] = datarecord.origin;
434 row["h_amount"] = 0;
435 row["h_cost"] = datarecord.cost;
436 row["h_type"] = datarecord.type;
437 row["h_form"] = datarecord.form;
438 row["h_useat"] = datarecord.useat;
439 row["h_time"] = 0;
440 row["h_alpha"] = datarecord.alpha;
441 row["h_beta"] = datarecord.beta;
442 row["h_hsi"] = datarecord.hsi;
443 row["h_humulene"] = datarecord.humulene;
444 row["h_carophyllene"] = datarecord.carophyllene;
445 row["h_cohumulone"] = datarecord.cohumulone;
446 row["h_myrcene"] = datarecord.myrcene;
447 row["h_total_oil"] = datarecord.total_oil;
448 var commit = $("#hopGrid").jqxGrid('addrow', null, row);
449 }
450 });
451
452 // delete selected hop.
453 $("#hdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
454 $("#hdeleterowbutton").on('click', function () {
455 var selectedrowindex = $("#hopGrid").jqxGrid('getselectedrowindex');
456 var rowscount = $("#hopGrid").jqxGrid('getdatainformation').rowscount;
457 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
458 var id = $("#hopGrid").jqxGrid('getrowid', selectedrowindex);
459 var commit = $("#hopGrid").jqxGrid('deleterow', id);
460 }
461 });
462 },
463 columns: [
464 { text: 'Hop', editable: false, datafield: 'h_name' },
465 { text: 'Type', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_type' },
466 { text: 'Vorm', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'h_form' },
467 { text: 'Alpha', datafield: 'h_alpha', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
468 { text: 'Gewicht', datafield: 'h_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
469 columntype: 'numberinput',
470 validation: function (cell, value) {
471 if (value < 0 || value > 100000000000 ) {
472 return { result: false, message: "Volume moet 0-~ zijn" };
473 }
474 return true;
475 }
476 },
477 { text: 'Gebruik', width: 110, align: 'center', cellsalign: 'center', datafield: 'h_useat' },
478 { text: 'Tijd', datafield: 'h_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
479 columntype: 'numberinput',
480 validation: function (cell, value) {
481 if (value < 0 || value > 100000000000 ) {
482 return { result: false, message: "De tijd moet 0-~ zijn" };
483 }
484 return true;
485 } // TODO: Only enable editing if Boil, else use fixed values.
486 },
487 { text: 'IBU', editable: false, datafield: 'ibu', width: 80, align: 'right',
488 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
489 var ibu = toIBU(rowdata.h_useat,
490 rowdata.h_form,
491 parseFloat($("#est_og").jqxNumberInput('decimal')),
492 parseFloat($("#batch_size").jqxNumberInput('decimal')),
493 parseFloat(rowdata.h_amount),
494 parseFloat(rowdata.h_time),
495 parseFloat(rowdata.h_alpha),
496 $("#ibu_method").val()
497 );
498 return "<div style='margin: 4px;' class='jqx-right-align'>" + dataAdapter.formatNumber(ibu, "f1") + "</div>";
499 }
500 }
501 ]
502 })
503 };
504
505 // Inline miscs editor
506 var editMisc = function (data) {
507 var miscSource = {
508 localdata: data.miscs,
509 datatype: "local",
510 cache: false,
511 datafields: [
512 { name: 'm_name', type: 'string' },
513 { name: 'm_amount', type: 'float' },
514 { name: 'm_cost', type: 'float' },
515 { name: 'm_type', type: 'string' },
516 { name: 'm_use_use', type: 'string' },
517 { name: 'm_time', type: 'float' },
518 { name: 'm_amount_is_weight', type: 'bool' }
519 ],
520 addrow: function (rowid, rowdata, position, commit) {
521 commit(true);
522 },
523 deleterow: function (rowid, commit) {
524 commit(true);
525 }
526 };
527 var miscAdapter = new $.jqx.dataAdapter(miscSource);
528 // dropdownlist datasource from inventory_miscs
529 var miscUrl = "getmiscsources.php";
530 var miscInvSource = {
531 datatype: "json",
532 datafields: [
533 { name: 'record', type: 'number' },
534 { name: 'name', type: 'string' },
535 { name: 'type', type: 'string' },
536 { name: 'use_use', type: 'string' },
537 { name: 'amount_is_weight', type: 'bool' },
538 { name: 'time', type: 'float' },
539 { name: 'cost', type: 'float' }
540 ],
541 url: miscUrl,
542 async: true
543 };
544 var misclist = new $.jqx.dataAdapter(miscInvSource);
545
546 $("#miscGrid").jqxGrid({
547 width: 960,
548 height: 400,
549 source: miscAdapter,
550 theme: theme,
551 selectionmode: 'singlerow',
552 editmode: 'selectedrow',
553 editable: true,
554 localization: getLocalization(),
555 showtoolbar: true,
556 rendertoolbar: function (toolbar) {
557 var me = this;
558 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
559 toolbar.append(container);
560 container.append('<div style="float: left; margin-left: 165px;" id="maddrowbutton"></div>');
561 container.append('<input style="float: left; margin-left: 230px;" id="mdeleterowbutton" type="button" value="Verwijder ingredient" />');
562 // add misc from dropdownlist.
563 $("#maddrowbutton").jqxDropDownList({
564 placeHolder: "Kies ingredient:",
565 theme: theme,
566 source: misclist,
567 displayMember: "name",
568 width: 150,
569 height: 27,
570 dropDownWidth: 300
571 });
572 $("#maddrowbutton").on('select', function (event) {
573 if (event.args) {
574 var index = event.args.index;
575 var datarecord = misclist.records[index];
576 var row = {};
577 row["m_name"] = datarecord.name;
578 row["m_amount"] = 0;
579 row["m_cost"] = datarecord.cost;
580 row["m_type"] = datarecord.type;
581 row["m_use_use"] = datarecord.use_use;
582 row["m_time"] = 0;
583 row["m_amount_is_weight"] = datarecord.amount_is_weight;
584 var commit = $("#miscGrid").jqxGrid('addrow', null, row);
585 }
586 });
587 // delete selected misc.
588 $("#mdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
589 $("#mdeleterowbutton").on('click', function () {
590 var selectedrowindex = $("#miscGrid").jqxGrid('getselectedrowindex');
591 var rowscount = $("#miscGrid").jqxGrid('getdatainformation').rowscount;
592 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
593 var id = $("#miscGrid").jqxGrid('getrowid', selectedrowindex);
594 var commit = $("#miscGrid").jqxGrid('deleterow', id);
595 }
596 });
597 },
598 columns: [
599 { text: 'Ingredient', editable: false, datafield: 'm_name' },
600 { text: 'Type', editable: false, width: 120, align: 'center', cellsalign: 'center', datafield: 'm_type' },
601 { text: 'Gebruik', editable: false, width: 90, align: 'center', cellsalign: 'center', datafield: 'm_use_use' },
602 { text: 'Gewicht', datafield: 'm_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f5',
603 columntype: 'numberinput',
604 validation: function (cell, value) {
605 if (value < 0 || value > 100000000000 ) {
606 return { result: false, message: "Volume moet 0-~ zijn" };
607 }
608 return true;
609 }
610 },
611 { text: 'Tijd', datafield: 'm_time', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'f0',
612 columntype: 'numberinput',
613 validation: function (cell, value) {
614 if (value < 0 || value > 100000000000 ) {
615 return { result: false, message: "De tijd moet 0-~ zijn" };
616 }
617 return true;
618 }
619 }
620 ]
621 })
622 };
623
624 // Inline yeasts editor
625 var editYeast = function (data) {
626 var yeastSource = {
627 localdata: data.yeasts,
628 datatype: "local",
629 cache: false,
630 datafields: [
631 { name: 'y_name', type: 'string' },
632 { name: 'y_laboratory', type: 'string' },
633 { name: 'y_product_id', type: 'string' },
634 { name: 'y_amount', type: 'float' },
635 { name: 'y_cost', type: 'float' },
636 { name: 'y_type', type: 'string' },
637 { name: 'y_form', type: 'string' },
638 { name: 'y_time', type: 'float' },
639 { name: 'y_min_temperature', type: 'float' },
640 { name: 'y_max_temperature', type: 'float' },
641 { name: 'y_attenuation', type: 'float' },
642 { name: 'y_amount_is_weight', type: 'bool' },
643 { name: 'y_use', type: 'string' }
644 ],
645 addrow: function (rowid, rowdata, position, commit) {
646 commit(true);
647 },
648 deleterow: function (rowid, commit) {
649 commit(true);
650 }
651 };
652 var yeastAdapter = new $.jqx.dataAdapter(yeastSource);
653 // dropdownlist datasource from inventory_yeasts
654 var yeastUrl = "getyeastsources.php";
655 var yeastInvSource = {
656 datatype: "json",
657 datafields: [
658 { name: 'record', type: 'number' },
659 { name: 'name', type: 'string' },
660 { name: 'type', type: 'string' },
661 { name: 'form', type: 'string' },
662 { name: 'laboratory', type: 'string' },
663 { name: 'product_id', type: 'string' },
664 { name: 'min_temperature', type: 'float' },
665 { name: 'max_temperature', type: 'float' },
666 { name: 'attenuation', type: 'float' },
667 { name: 'cost', type: 'float' }
668 ],
669 url: yeastUrl,
670 async: true
671 };
672 var yeastlist = new $.jqx.dataAdapter(yeastInvSource);
673
674 $("#yeastGrid").jqxGrid({
675 width: 1050,
676 height: 300,
677 source: yeastAdapter,
678 theme: theme,
679 selectionmode: 'singlerow',
680 editmode: 'selectedrow',
681 editable: true,
682 localization: getLocalization(),
683 showtoolbar: true,
684 rendertoolbar: function (toolbar) {
685 var me = this;
686 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
687 toolbar.append(container);
688 container.append('<div style="float: left; margin-left: 165px;" id="yaddrowbutton"></div>');
689 container.append('<input style="float: left; margin-left: 230px;" id="ydeleterowbutton" type="button" value="Verwijder gist" />');
690 // add yeast from dropdownlist.
691 $("#yaddrowbutton").jqxDropDownList({
692 placeHolder: "Kies gist:",
693 theme: theme,
694 source: yeastlist,
695 displayMember: "name",
696 width: 150,
697 height: 27,
698 dropDownWidth: 300
699 });
700 $("#yaddrowbutton").on('select', function (event) {
701 if (event.args) {
702 var index = event.args.index;
703 var datarecord = yeastlist.records[index];
704 var row = {};
705 row["y_name"] = datarecord.name;
706 row["y_laboratory"] = datarecord.laboratory;
707 row["y_product_id"] = datarecord.product_id;
708 row["y_type"] = datarecord.type;
709 row["y_form"] = datarecord.form;
710 row["y_amount"] = 0;
711 row["y_cost"] = datarecord.cost;
712 row["y_use"] = "Primary";
713 row["y_time"] = 0;
714 if (datarecord.form == "Dry") {
715 row["y_amount_is_weight"] = 1;
716 } else {
717 row["y_amount_is_weight"] = 0;
718 }
719 row["y_min_temperature"] = datarecord.min_temperature;
720 row["y_max_temperature"] = datarecord.max_temperature;
721 row["y_attenuation"] = datarecord.attenuation;
722 var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
723 }
724 });
725 // delete selected yeast.
726 $("#ydeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
727 $("#ydeleterowbutton").on('click', function () {
728 var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
729 var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
730 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
731 var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex);
732 var commit = $("#yeastGrid").jqxGrid('deleterow', id);
733 }
734 });
735 },
736 columns: [
737 { text: 'Gist', editable: false, datafield: 'y_name' },
738 { text: 'Laboratorium', editable: false, width: 150, datafield: 'y_laboratory' },
739 { text: 'Code', editable: false, width: 90, datafield: 'y_product_id' },
740 { text: 'Soort', editable: false, width: 80, align: 'center', cellsalign: 'center', datafield: 'y_form' },
741 { text: 'Min.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_min_temperature' },
742 { text: 'Max.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_max_temperature' },
743 { text: 'Attn.', editable: false, width: 70, align: 'right', cellsalign: 'right', datafield: 'y_attenuation', cellsformat: 'f1' },
744 { text: 'Voor', editable: false, width: 80, align: 'center', cellsalign: 'center', datafield: 'y_use' },
745 { text: 'Hoeveel', datafield: 'y_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f5',
746 columntype: 'numberinput',
747 validation: function (cell, value) {
748 if (value < 0 || value > 100000000000 ) {
749 return { result: false, message: "Volume moet 0-~ zijn" };
750 }
751 return true;
752 }
753 }
754 ]
755 })
756 };
757
758 // Inline waters editor
759 var editWater = function (data) {
760 var waterSource = {
761 localdata: data.waters,
762 datatype: "local",
763 datafields: [
764 { name: 'w_name', type: 'string' },
765 { name: 'w_amount', type: 'float' },
766 { name: 'w_calcium', type: 'float' },
767 { name: 'w_sulfate', type: 'float' },
768 { name: 'w_chloride', type: 'float' },
769 { name: 'w_sodium', type: 'float' },
770 { name: 'w_magnesium', type: 'float' },
771 { name: 'w_ph', type: 'float' },
772 { name: 'w_total_alkalinity', type: 'float' },
773 { name: 'w_cost', type: 'float' },
774 { name: 'w_default_water', type: 'bool' }
775 ],
776 addrow: function (rowid, rowdata, position, commit) {
777 commit(true);
778 },
779 deleterow: function (rowid, commit) {
780 commit(true);
781 }
782 };
783 var waterAdapter = new $.jqx.dataAdapter(waterSource);
784 // dropdownlist datasource from inventory_waters
785 var waterUrl = "getwatersources.php";
786 var waterInvSource = {
787 datatype: "json",
788 datafields: [
789 { name: 'record', type: 'number' },
790 { name: 'name', type: 'string' },
791 { name: 'unlimited_stock', type: 'bool' },
792 { name: 'calcium', type: 'float' },
793 { name: 'sulfate', type: 'float' },
794 { name: 'chloride', type: 'float' },
795 { name: 'sodium', type: 'float' },
796 { name: 'magnesium', type: 'float' },
797 { name: 'ph', type: 'float' },
798 { name: 'total_alkalinity', type: 'float' },
799 { name: 'cost', type: 'float' },
800 { name: 'default_water', type: 'bool' }
801 ],
802 url: waterUrl,
803 async: true
804 };
805 var waterlist = new $.jqx.dataAdapter(waterInvSource);
806
807 $("#waterGrid").jqxGrid({
808 width: 960,
809 height: 200,
810 source: waterAdapter,
811 theme: theme,
812 selectionmode: 'singlerow',
813 editmode: 'selectedrow',
814 editable: true,
815 localization: getLocalization(),
816 showtoolbar: true,
817 rendertoolbar: function (toolbar) {
818 var me = this;
819 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
820 toolbar.append(container);
821 container.append('<div style="float: left; margin-left: 165px;" id="waddrowbutton"></div>');
822 container.append('<input style="float: left; margin-left: 230px;" id="wdeleterowbutton" type="button" value="Verwijder water" />');
823 // add water from dropdownlist.
824 $("#waddrowbutton").jqxDropDownList({
825 placeHolder: "Kies water:",
826 theme: theme,
827 source: waterlist,
828 displayMember: "name",
829 width: 150,
830 height: 27,
831 dropDownWidth: 300
832 });
833 $("#waddrowbutton").on('select', function (event) {
834 if (event.args) {
835 var index = event.args.index;
836 var datarecord = waterlist.records[index];
837 var row = {};
838 row["w_name"] = datarecord.name;
839 row["w_amount"] = 0;
840 row["w_calcium"] = datarecord.calcium;
841 row["w_sulfate"] = datarecord.sulfate;
842 row["w_chloride"] = datarecord.chloride;
843 row["w_sodium"] = datarecord.sodium;
844 row["w_magnesium"] = datarecord.magnesium;
845 row["w_ph"] = datarecord.ph;
846 row["w_total_alkalinity"] = datarecord.total_alkalinity;
847 row["w_default_water"] = datarecord.default_water;
848 row["w_cost"] = datarecord.cost;
849 var commit = $("#waterGrid").jqxGrid('addrow', null, row);
850 }
851 });
852
853 // delete selected water.
854 // Overgebleven waters in volume verhogen met het verwijderde water.
855 $("#wdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
856 $("#wdeleterowbutton").on('click', function () {
857 var selectedrowindex = $("#waterGrid").jqxGrid('getselectedrowindex');
858 var rowscount = $("#waterGrid").jqxGrid('getdatainformation').rowscount;
859 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
860 var id = $("#waterGrid").jqxGrid('getrowid', selectedrowindex);
861 var commit = $("#waterGrid").jqxGrid('deleterow', id);
862 }
863 });
864 },
865 columns: [
866 { text: 'Water bron', editable: false, datafield: 'w_name' },
867 { text: 'Volume', datafield: 'w_amount', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1',
868 columntype: 'numberinput',
869 validation: function (cell, value) {
870 if (value < 0 || value > 100000000000 ) {
871 return { result: false, message: "Volume moet 0-~ zijn" };
872 }
873 return true;
874 }
875 },
876 // TODO: validator test max is hoeveelheid maischwater. Dan water verdelen voor totaal.
877 { text: 'Ca', editable: false, datafield: 'w_calcium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
878 { text: 'Mg', editable: false, datafield: 'w_magnesium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
879 { text: 'Na', editable: false, datafield: 'w_sodium', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
880 { text: 'Tot Alk', editable: false, datafield: 'w_total_alkalinity', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
881 { text: 'CaSO4', editable: false, datafield: 'w_sulfate', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
882 { text: 'Cl', editable: false, datafield: 'w_chloride', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' },
883 { text: 'pH', editable: false, datafield: 'w_ph', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1' }
884 ]
885 });
886 }; // editWater = function (data) {
887
888 // inline mash editor
889 var editMash = function (data) {
890 var generaterow = function () {
891 var row = {};
892 row["step_name"] = "Stap 1";
893 row["step_type"] = "Infusion";
894 row["step_infuse_amount"] = 15;
895 row["step_temp"] = 62.0;
896 row['step_time'] = 20.0;
897 row['ramp_time'] = 1.0;
898 row['end_temp'] = 62.0;
899 return row;
900 }
901 var mashSource = {
902 localdata: data.mashs,
903 datatype: "local",
904 cache: false,
905 datafields: [
906 { name: 'step_name', type: 'string' },
907 { name: 'step_type', type: 'string' },
908 { name: 'step_infuse_amount', type: 'float' },
909 { name: 'step_temp', type: 'float' },
910 { name: 'step_time', type: 'float' },
911 { name: 'ramp_time', type: 'float' },
912 { name: 'end_temp', type: 'float' }
913 ],
914 addrow: function (rowid, rowdata, position, commit) {
915 commit(true);
916 },
917 deleterow: function (rowid, commit) {
918 commit(true);
919 }
920 };
921 var mashAdapter = new $.jqx.dataAdapter(mashSource);
922 // dropdownlist datasource from profile_mash
923 var mashUrl = "include/db_profile_mash.php";
924 var mashInvSource = {
925 datatype: "json",
926 datafields: [
927 { name: 'record', type: 'number' },
928 { name: 'name', type: 'string' },
929 { name: 'steps', type: 'array' }
930 ],
931 url: mashUrl,
932 async: true
933 };
934 var mashlist = new $.jqx.dataAdapter(mashInvSource);
935
936 $("#mashGrid").jqxGrid({
937 width: 960,
938 height: 400,
939 source: mashAdapter,
940 theme: theme,
941 selectionmode: 'singlerow',
942 editmode: 'selectedrow',
943 editable: true,
944 localization: getLocalization(),
945 showtoolbar: true,
946 rendertoolbar: function (toolbar) {
947 var me = this;
948 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
949 toolbar.append(container);
950 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe stap" />');
951 container.append('<input style="float: left; margin-left: 230px;" id="sdeleterowbutton" type="button" value="Verwijder stap" />');
952 $("#saddrowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
953 $("#saddrowbutton").on('click', function () {
954 var datarow = generaterow();
955 var commit = $("#mashGrid").jqxGrid('addrow', null, datarow);
956 });
957 // delete selected yeast.
958 $("#sdeleterowbutton").jqxButton({ theme: theme, height: 27, width: 150 });
959 $("#sdeleterowbutton").on('click', function () {
960 var selectedrowindex = $("#mashGrid").jqxGrid('getselectedrowindex');
961 var rowscount = $("#mashGrid").jqxGrid('getdatainformation').rowscount;
962 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
963 var id = $("#mashGrid").jqxGrid('getrowid', selectedrowindex);
964 var commit = $("#mashGrid").jqxGrid('deleterow', id);
965 }
966 });
967 },
968 columns: [
969 { text: 'Stap naam', datafield: 'step_name' },
970 { text: 'Stap type', datafield: 'step_type', width: 110, columntype: 'dropdownlist',
971 createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
972 var dataSource = [ "Infusion", "Temperature", "Decoction" ];
973 editor.jqxDropDownList({ source: dataSource, dropDownHeight: 105 });
974 }
975 },
976 { text: 'Temperatuur', datafield: 'step_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1',
977 validation: function (cell, value) {
978 if (value < 35 || value > 80) {
979 return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." };
980 }
981 return true;
982 }
983 },
984 { text: 'Eind', datafield: 'end_temp', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'f1',
985 validation: function (cell, value) {
986 if (value < 35 || value > 80) {
987 return { result: false, message: "De temperatuur moet tussen 35 en 80 zijn." };
988 }
989 return true;
990 }
991 },
992 { text: 'Tijd', datafield: 'step_time', width: 70, align: 'right', cellsalign: 'right',
993 validation: function (cell, value) {
994 if (value < 1 || value > 360) {
995 return { result: false, message: "De tijd moet tussen 1 en 360 zijn." };
996 }
997 return true;
998 }
999 },
1000 { text: 'Stap', datafield: 'ramp_time', width: 70, align: 'right', cellsalign: 'right',
1001 validation: function (cell, value) {
1002 if (value < 1 || value > 60) {
1003 return { result: false, message: "De tijd moet tussen 1 en 60 zijn." };
1004 }
1005 return true;
1006 }
1007 },
1008 { text: 'Infuse', datafield: 'step_infuse_amount', width: 70, align: 'right', cellsalign: 'right',
1009 validation: function (cell, value) {
1010 if (value < 0 || value > 60) {
1011 return { result: false, message: "De waarde moet tussen 0 en 60 zijn." };
1012 }
1013 return true;
1014 }
1015 }
1016 ]
1017 });
1018 $("#mashGrid").on('cellendedit', function (event) {
1019 $('#mashGrid').jqxGrid('sortby', 'step_temp', 'asc');
1020 });
1021 };
1022
1023 // initialize the input fields.
1024 var srcType = [ "All Grain", "Partial Mash", "Extract" ];
1025 var srcColor = [ "Morey", "Mosher", "Daniels" ];
1026 var srcIBU = [ "Tinseth", "Rager", "Garetz", "Daniels", "Mosher", "Noonan" ];
1027 $("#name").jqxInput({ theme: theme, width: 640, height: 23 });
1028 $("#notes").jqxInput({ theme: theme, width: 960, height: 200 });
1029 $("#st_name").jqxInput({ theme: theme, width: 250, height: 23 });
1030 $("#st_letter").jqxInput({ theme: theme, width: 100, height: 23 });
1031 $("#st_guide").jqxInput({ theme: theme, width: 250, height: 23 });
1032 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 125, height: 23, dropDownHeight: 95 });
1033 $("#batch_size").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1, symbol: 'L', symbolPosition: 'right' });
1034 $("#boil_time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', template: "success", theme: theme, width: 100, height: 23, min: 4, max: 360, decimalDigits: 0, spinButtons: true });
1035 $("#efficiency").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 40, max: 100, decimalDigits: 0, spinButtons: true, symbol: '%', symbolPosition: 'right' });
1036 $("#est_og").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1, max: 1.9, decimalDigits: 3, spinButtons: true, spinButtonsStep: 0.001 });
1037 $("#st_og_min").jqxNumberInput({ disabled: true, inputMode: 'simple', width: 50, height: 23, decimalDigits: 3, readOnly: true });
1038 $("#st_og_max").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 3, readOnly: true });
1039 $("#est_fg").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 100, height: 23, min: 0.980, max: 1.040, decimalDigits: 3, readOnly: true });
1040 $("#est_color").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 1, max: 200, decimalDigits: 0, spinButtons: true });
1041 $("#color_method").jqxDropDownList({ theme: theme, source: srcColor, width: 125, height: 23, dropDownHeight: 95 });
1042 $("#est_ibu").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 0, max: 200, decimalDigits: 0, spinButtons: true });
1043 $("#ibu_method").jqxDropDownList({ theme: theme, source: srcIBU, width: 125, height: 23, dropDownHeight: 180 });
1044 $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 });
1045 $("#mash_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 4, max: 8, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.1 });
1046 $("#mash_sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 100, height: 23, min: 70, max: 98, decimalDigits: 1, spinButtons: true, spinButtonsStep: 0.5 });
1047 var editrow = -1;
1048 // initialize jqxGrid
1049 $("#jqxgrid").jqxGrid({
1050 width: 1280,
1051 height: 630,
1052 source: dataAdapter,
1053 groupable: true,
1054 theme: theme,
1055 showstatusbar: true,
1056 localization: getLocalization(),
1057 renderstatusbar: function (statusbar) {
1058 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
1059 var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Add</span></div>");
1060 container.append(addButton);
1061 statusbar.append(container);
1062 addButton.jqxButton({ theme: theme, width: 120, height: 20 });
1063 // add new row.
1064 addButton.click(function (event) {
1065 editrow = -1;
1066 $("#popupWindow").jqxWindow({ position: { x: 40, y: 20 } });
1067 $("#name").val('');
1068 $("#notes").val('');
1069 $("#st_name").val('');
1070 $("#st_letter").val('');
1071 $("#st_guide").val('BKG 2015');
1072 $("#type").val('All Grain');
1073 $("#batch_size").val(20);
1074 $("#boil_time").val(90);
1075 $("#efficiency").val(75);
1076 $("#est_og").val(1.052);
1077 $("#est_fg").val(1.000);
1078 $("#est_color").val(20);
1079 $("#color_method").val('Morey');
1080 $("#est_ibu").val(40);
1081 $("#ibu_method").val('Tinseth');
1082 $("#mash_sparge_temp").val(78);
1083 $("#mash_ph").val(5.4);
1084 $("#mash_name").val('');
1085 editFermentable('');
1086 editHop('');
1087 editMisc('');
1088 editYeast('');
1089 editWater('');
1090 editMash('');
1091 $("#popupWindow").jqxWindow('open');
1092 });
1093 },
1094 filterable: true,
1095 filtermode: 'excel',
1096 columns: [
1097 { text: 'Stijlgids', datafield: 'st_guide', width: 120 },
1098 { text: 'Letter', datafield: 'st_letter', width: 60 },
1099 { text: 'Stijl', datafield: 'st_name', width: 150 },
1100 { text: 'Naam', datafield: 'name' },
1101 { text: 'OG', datafield: 'est_og', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f3' },
1102 { text: 'EBC', datafield: 'est_color', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f0' },
1103 { text: 'IBU', datafield: 'est_ibu', width: 60, align: 'right', cellsalign: 'right', cellsformat: 'f0' },
1104 { text: 'Wijzig', datafield: 'Edit', width: 120, align: 'center', columntype: 'button', cellsrenderer: function () {
1105 return "Wijzig";
1106 }, buttonclick: function (row) {
1107 // open the popup window when the user clicks a button.
1108 editrow = row;
1109 $("#popupWindow").jqxWindow({ position: { x: 40, y: 20 } });
1110 // get the clicked row's data and initialize the input fields.
1111 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
1112 $("#name").val(dataRecord.name);
1113 $("#notes").val(dataRecord.notes);
1114 $("#st_name").val(dataRecord.st_name);
1115 $("#st_letter").val(dataRecord.st_letter);
1116 $("#st_guide").val(dataRecord.st_guide);
1117 $("#type").val(dataRecord.type);
1118 $("#batch_size").val(dataRecord.batch_size);
1119 $("#boil_time").val(dataRecord.boil_time);
1120 $("#efficiency").val(dataRecord.efficiency);
1121 $("#est_og").val(dataRecord.est_og);
1122 $("#st_og_min").val(dataRecord.st_og_min);
1123 $("#st_og_max").val(dataRecord.st_og_max);
1124 $("#est_fg").val(dataRecord.est_fg);
1125 $("#est_color").val(dataRecord.est_color);
1126 $("#color_method").val(dataRecord.color_method);
1127 $("#est_ibu").val(dataRecord.est_ibu);
1128 $("#ibu_method").val(dataRecord.ibu_method);
1129 $("#mash_name").val(dataRecord.mash_name);
1130 $("#mash_ph").val(dataRecord.mash_ph);
1131 $("#mash_sparge_temp").val(dataRecord.mash_sparge_temp);
1132 editFermentable(dataRecord);
1133 editHop(dataRecord);
1134 editMisc(dataRecord);
1135 editYeast(dataRecord);
1136 editWater(dataRecord);
1137 editMash(dataRecord);
1138 // show the popup window.
1139 $("#popupWindow").jqxWindow('open');
1140 }
1141 }
1142 ],
1143 groups: ['st_guide','st_letter' ]
1144 });
1145
1146 // initialize the popup window and buttons.
1147 $("#popupWindow").jqxWindow({
1148 width: 1202,
1149 height: 622,
1150 resizable: false,
1151 theme: theme,
1152 isModal: true,
1153 autoOpen: false,
1154 cancelButton: $("#Cancel"),
1155 modalOpacity: 0.40
1156 });
1157 // Tabs inside the popup window.
1158 $('#jqxTabs').jqxTabs({
1159 theme: theme,
1160 autoHeight: false,
1161 height: 580,
1162 position: 'top'
1163 });
1164 $("#popupWindow").on('open', function () {
1165 $("#name").jqxInput('selectAll');
1166 });
1167
1168 $("#Delete").jqxButton({ width: '90px', theme: theme });
1169 $("#Delete").click(function () {
1170 if (editrow >= 0) {
1171 // Open a popup to confirm this action.
1172 $('#eventWindow').jqxWindow('open');
1173 $("#delOk").click(function () {
1174 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
1175 $("#jqxgrid").jqxGrid('deleterow', rowID);
1176 });
1177 }
1178 $("#popupWindow").jqxWindow('hide');
1179 });
1180
1181 $("#Cancel").jqxButton({ width: '90px', theme: theme });
1182 $("#Save").jqxButton({ width: '90px', theme: theme });
1183 // update the edited row when the user clicks the 'Save' button.
1184 $("#Save").click(function () {
1185 var fermentablerow = $('#fermentableGrid').jqxGrid('getrows');
1186 var hoprow = $('#hopGrid').jqxGrid('getrows');
1187 var miscrow = $('#miscGrid').jqxGrid('getrows');
1188 var yeastrow = $('#yeastGrid').jqxGrid('getrows');
1189 var waterrow = $('#waterGrid').jqxGrid('getrows');
1190 var mashrow = $('#mashGrid').jqxGrid('getrows');
1191 if (editrow >= 0) {
1192 var rowRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
1193 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
1194 var row = {
1195 record: rowID,
1196 name: $("#name").val(),
1197 notes: $("#notes").val(),
1198 st_name: $('#st_name').val(),
1199 st_letter: $('#st_letter').val(),
1200 st_guide: $('#st_guide').val(),
1201 st_og_min: rowRecord.st_og_min,
1202 st_og_max: rowRecord.st_og_max,
1203 st_fg_min: rowRecord.st_fg_min,
1204 st_fg_max: rowRecord.st_fg_max,
1205 st_ibu_min: rowRecord.st_ibu_min,
1206 st_ibu_max: rowRecord.st_ibu_max,
1207 st_color_min: rowRecord.st_color_min,
1208 st_color_max: rowRecord.st_color_max,
1209 st_carb_min: rowRecord.st_carb_min,
1210 st_carb_max: rowRecord.st_carb_max,
1211 st_abv_min: rowRecord.st_abv_min,
1212 st_abv_max: rowRecord.st_abv_max,
1213 type: $("#type").val(),
1214 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')),
1215 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),
1216 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')),
1217 est_og: parseFloat($("#est_og").jqxNumberInput('decimal')),
1218 est_fg: parseFloat($("#est_fg").jqxNumberInput('decimal')),
1219 est_color: parseFloat($("#est_color").jqxNumberInput('decimal')),
1220 color_method: $("#color_method").val(),
1221 est_ibu: parseFloat($("#est_ibu").jqxNumberInput('decimal')),
1222 ibu_method: $("#ibu_method").val(),
1223 mash_name: $("#mash_name").val(),
1224 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
1225 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
1226 fermentables: fermentablerow,
1227 hops: hoprow,
1228 miscs: miscrow,
1229 yeasts: yeastrow,
1230 waters: waterrow,
1231 mashs: mashrow
1232 };
1233 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
1234 } else {
1235 // Insert a record
1236 var newrow = {
1237 record: -1,
1238 name: $("#name").val(),
1239 notes: $("#notes").val(),
1240 st_name: $('#st_name').val(),
1241 st_letter: $('#st_letter').val(),
1242 st_guide: $('#st_guide').val(),
1243 st_og_min: 1.025,
1244 st_og_max: 1.110,
1245 st_fg_min: 1.000,
1246 st_fg_max: 1.025,
1247 st_ibu_min: 15,
1248 st_ibu_max: 150,
1249 st_color_min: 5,
1250 st_color_max: 50,
1251 st_carb_min: 1,
1252 st_carb_max: 3,
1253 st_abv_min: 2,
1254 st_abv_max: 14,
1255 type: $("#type").val(),
1256 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')),
1257 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),
1258 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')),
1259 est_og: parseFloat($("#est_og").jqxNumberInput('decimal')),
1260 est_fg: parseFloat($("#est_fg").jqxNumberInput('decimal')),
1261 est_color: parseFloat($("#est_color").jqxNumberInput('decimal')),
1262 color_method: $("#color_method").val(),
1263 est_ibu: parseFloat($("#est_ibu").jqxNumberInput('decimal')),
1264 ibu_method: $("#ibu_method").val(),
1265 mash_name: $("#mash_name").val(),
1266 mash_ph: parseFloat($("#mash_ph").jqxNumberInput('decimal')),
1267 mash_sparge_temp: parseFloat($("#mash_sparge_temp").jqxNumberInput('decimal')),
1268 fermentables: fermentablerow,
1269 hops: hoprow,
1270 miscs: miscrow,
1271 yeasts: yeastrow,
1272 waters: waterrow,
1273 mashs: mashrow
1274 };
1275 $('#jqxgrid').jqxGrid('addrow', null, newrow);
1276 }
1277 $("#popupWindow").jqxWindow('hide');
1278 });
1279 createDelElements();
1280 });
1281

mercurial