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