www/js/prod_divide.js

changeset 498
10c6eeee60ce
child 499
4f14a18b581e
equal deleted inserted replaced
497:0fe366d953ab 498:10c6eeee60ce
1 /*****************************************************************************
2 * Copyright (C) 2019
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of BMS
7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * BrewCloud is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23
24 $(document).ready(function () {
25
26 $('#divide_type').jqxDropDownList({
27 theme: theme,
28 source: SplitAdapter,
29 valueMember: 'id',
30 displayMember: 'nl',
31 width: 180,
32 height: 23,
33 autoDropDownHeight: true
34 });
35
36 var dataRecord = {},
37 i,
38 url = 'includes/db_product.php',
39
40 // Prepare the data
41 source = {
42 datatype: 'json',
43 cache: false,
44 datafields: [
45 // From prod_main
46 { name: 'record', type: 'number' },
47 { name: 'uuid', type: 'string' },
48 { name: 'name', type: 'string' },
49 { name: 'code', type: 'string' },
50 { name: 'birth', type: 'string' },
51 { name: 'stage', type: 'int' },
52 { name: 'notes', type: 'string' },
53 { name: 'log_brew', type: 'int' },
54 { name: 'log_fermentation', type: 'int' },
55 { name: 'inventory_reduced', type: 'int' },
56 { name: 'locked', type: 'int' },
57 { name: 'eq_name', type: 'string' },
58 { name: 'eq_boil_size', type: 'float' },
59 { name: 'eq_batch_size', type: 'float' },
60 { name: 'eq_tun_volume', type: 'float' },
61 { name: 'eq_tun_weight', type: 'float' },
62 { name: 'eq_tun_specific_heat', type: 'float' },
63 { name: 'eq_tun_material', type: 'int' },
64 { name: 'eq_tun_height', type: 'float' },
65 { name: 'eq_top_up_water', type: 'float' },
66 { name: 'eq_trub_chiller_loss', type: 'float' },
67 { name: 'eq_evap_rate', type: 'float' },
68 { name: 'eq_boil_time', type: 'float' },
69 { name: 'eq_calc_boil_volume', type: 'int' },
70 { name: 'eq_top_up_kettle', type: 'float' },
71 { name: 'eq_hop_utilization', type: 'float' },
72 { name: 'eq_notes', type: 'string' },
73 { name: 'eq_lauter_volume', type: 'float' },
74 { name: 'eq_lauter_height', type: 'float' },
75 { name: 'eq_lauter_deadspace', type: 'float' },
76 { name: 'eq_kettle_volume', type: 'float' },
77 { name: 'eq_kettle_height', type: 'float' },
78 { name: 'eq_mash_volume', type: 'float' },
79 { name: 'eq_mash_max', type: 'float' },
80 { name: 'eq_efficiency', type: 'float' },
81 { name: 'brew_date_start', type: 'string' },
82 { name: 'brew_mash_ph', type: 'float' },
83 { name: 'brew_mash_sg', type: 'float' },
84 { name: 'brew_mash_efficiency', type: 'float' },
85 { name: 'brew_sparge_est', type: 'float' },
86 { name: 'brew_sparge_ph', type: 'float' },
87 { name: 'brew_preboil_volume', type: 'float' },
88 { name: 'brew_preboil_sg', type: 'float' },
89 { name: 'brew_preboil_ph', type: 'float' },
90 { name: 'brew_preboil_efficiency', type: 'float' },
91 { name: 'brew_aboil_volume', type: 'float' },
92 { name: 'brew_aboil_sg', type: 'float' },
93 { name: 'brew_aboil_ph', type: 'float' },
94 { name: 'brew_aboil_efficiency', type: 'float' },
95 { name: 'brew_cooling_method', type: 'int' },
96 { name: 'brew_cooling_time', type: 'float' },
97 { name: 'brew_cooling_to', type: 'float' },
98 { name: 'brew_whirlpool9', type: 'float' },
99 { name: 'brew_whirlpool7', type: 'float' },
100 { name: 'brew_whirlpool6', type: 'float' },
101 { name: 'brew_whirlpool2', type: 'float' },
102 { name: 'brew_fermenter_volume', type: 'float' },
103 { name: 'brew_fermenter_extrawater', type: 'float' },
104 { name: 'brew_fermenter_tcloss', type: 'float' },
105 { name: 'brew_aeration_time', type: 'float' },
106 { name: 'brew_aeration_speed', type: 'float' },
107 { name: 'brew_aeration_type', type: 'int' },
108 { name: 'brew_fermenter_sg', type: 'float' },
109 { name: 'brew_fermenter_ibu', type: 'float' },
110 { name: 'brew_fermenter_color', type: 'float' },
111 { name: 'brew_date_end', type: 'string' },
112 { name: 'og', type: 'float' },
113 { name: 'fg', type: 'float' },
114 { name: 'primary_start_temp', type: 'float' },
115 { name: 'primary_max_temp', type: 'float' },
116 { name: 'primary_end_temp', type: 'float' },
117 { name: 'primary_end_sg', type: 'float' },
118 { name: 'primary_end_date', type: 'string' },
119 { name: 'secondary_temp', type: 'float' },
120 { name: 'secondary_end_sg', type: 'float' },
121 { name: 'secondary_end_date', type: 'string' },
122 { name: 'tertiary_temp', type: 'float' },
123 { name: 'package_date', type: 'string' },
124 { name: 'package_volume', type: 'float' },
125 { name: 'package_infuse_amount', type: 'float' },
126 { name: 'package_infuse_abv', type: 'float' },
127 { name: 'package_infuse_notes', type: 'string' },
128 { name: 'package_abv', type: 'float' },
129 { name: 'package_ph', type: 'float' },
130 { name: 'bottle_amount', type: 'float' },
131 { name: 'bottle_carbonation', type: 'float' },
132 { name: 'bottle_priming_water', type: 'float' },
133 { name: 'bottle_priming_amount', type: 'float' },
134 { name: 'bottle_carbonation_temp', type: 'float' },
135 { name: 'keg_amount', type: 'float' },
136 { name: 'keg_carbonation', type: 'float' },
137 { name: 'keg_priming_water', type: 'float' },
138 { name: 'keg_priming_amount', type: 'float' },
139 { name: 'keg_carbonation_temp', type: 'float' },
140 { name: 'keg_forced_carb', type: 'int' },
141 { name: 'keg_pressure', type: 'float' },
142 { name: 'taste_notes', type: 'string' },
143 { name: 'taste_rate', type: 'float' },
144 { name: 'taste_date', type: 'string' },
145 { name: 'taste_color', type: 'string' },
146 { name: 'taste_transparency', type: 'string' },
147 { name: 'taste_head', type: 'string' },
148 { name: 'taste_aroma', type: 'string' },
149 { name: 'taste_taste', type: 'string' },
150 { name: 'taste_mouthfeel', type: 'string' },
151 { name: 'taste_aftertaste', type: 'string' },
152 { name: 'st_name', type: 'string' },
153 { name: 'st_letter', type: 'string' },
154 { name: 'st_guide', type: 'string' },
155 { name: 'st_category', type: 'string' },
156 { name: 'st_category_number', type: 'float' },
157 { name: 'st_type', type: 'int' },
158 { name: 'st_og_min', type: 'float' },
159 { name: 'st_og_max', type: 'float' },
160 { name: 'st_fg_min', type: 'float' },
161 { name: 'st_fg_max', type: 'float' },
162 { name: 'st_ibu_min', type: 'float' },
163 { name: 'st_ibu_max', type: 'float' },
164 { name: 'st_color_min', type: 'float' },
165 { name: 'st_color_max', type: 'float' },
166 { name: 'st_carb_min', type: 'float' },
167 { name: 'st_carb_max', type: 'float' },
168 { name: 'st_abv_min', type: 'float' },
169 { name: 'st_abv_max', type: 'float' },
170 { name: 'type', type: 'int' },
171 { name: 'batch_size', type: 'float' },
172 { name: 'boil_size', type: 'float' },
173 { name: 'boil_time', type: 'float' },
174 { name: 'efficiency', type: 'float' },
175 { name: 'est_og', type: 'float' },
176 { name: 'est_fg', type: 'float' },
177 { name: 'est_abv', type: 'float' },
178 { name: 'est_color', type: 'float' },
179 { name: 'color_method', type: 'int' },
180 { name: 'est_ibu', type: 'float' },
181 { name: 'ibu_method', type: 'int' },
182 { name: 'est_carb', type: 'float' },
183 { name: 'sparge_temp', type: 'float' },
184 { name: 'sparge_ph', type: 'float' },
185 { name: 'sparge_volume', type: 'float' },
186 { name: 'sparge_source', type: 'int' },
187 { name: 'sparge_acid_type', type: 'int' },
188 { name: 'sparge_acid_perc', type: 'float' },
189 { name: 'sparge_acid_amount', type: 'float' },
190 { name: 'mash_ph', type: 'float' },
191 { name: 'mash_name', type: 'string' },
192 { name: 'calc_acid', type: 'int' },
193 { name: 'w1_name', type: 'string' },
194 { name: 'w1_amount', type: 'float' },
195 { name: 'w1_calcium', type: 'float' },
196 { name: 'w1_sulfate', type: 'float' },
197 { name: 'w1_chloride', type: 'float' },
198 { name: 'w1_sodium', type: 'float' },
199 { name: 'w1_magnesium', type: 'float' },
200 { name: 'w1_total_alkalinity', type: 'float' },
201 { name: 'w1_ph', type: 'float' },
202 { name: 'w1_cost', type: 'float' },
203 { name: 'w2_name', type: 'string' },
204 { name: 'w2_amount', type: 'float' },
205 { name: 'w2_calcium', type: 'float' },
206 { name: 'w2_sulfate', type: 'float' },
207 { name: 'w2_chloride', type: 'float' },
208 { name: 'w2_sodium', type: 'float' },
209 { name: 'w2_magnesium', type: 'float' },
210 { name: 'w2_total_alkalinity', type: 'float' },
211 { name: 'w2_ph', type: 'float' },
212 { name: 'w2_cost', type: 'float' },
213 { name: 'wg_amount', type: 'float' },
214 { name: 'wg_calcium', type: 'float' },
215 { name: 'wg_sulfate', type: 'float' },
216 { name: 'wg_chloride', type: 'float' },
217 { name: 'wg_sodium', type: 'float' },
218 { name: 'wg_magnesium', type: 'float' },
219 { name: 'wg_total_alkalinity', type: 'float' },
220 { name: 'wg_ph', type: 'float' },
221 { name: 'wb_calcium', type: 'float' },
222 { name: 'wb_sulfate', type: 'float' },
223 { name: 'wb_chloride', type: 'float' },
224 { name: 'wb_sodium', type: 'float' },
225 { name: 'wb_magnesium', type: 'float' },
226 { name: 'wb_total_alkalinity', type: 'float' },
227 { name: 'wb_ph', type: 'float' },
228 { name: 'wa_acid_name', type: 'int' },
229 { name: 'wa_acid_perc', type: 'int' },
230 { name: 'wa_base_name', type: 'int' },
231 { name: 'starter_enable', type: 'int' },
232 { name: 'starter_type', type: 'int' },
233 { name: 'starter_sg', type: 'float' },
234 { name: 'starter_viability', type: 'int' },
235 { name: 'starter_viability', type: 'int' },
236 { name: 'prop1_type', type: 'int' },
237 { name: 'prop1_volume', type: 'float' },
238 { name: 'prop2_type', type: 'int' },
239 { name: 'prop2_volume', type: 'float' },
240 { name: 'prop3_type', type: 'int' },
241 { name: 'prop3_volume', type: 'float' },
242 { name: 'prop4_type', type: 'int' },
243 { name: 'prop4_volume', type: 'float' },
244 { name: 'divide_type', type: 'int' },
245 { name: 'divide_size', type: 'float' },
246 { name: 'divide_parts', type: 'int' },
247 { name: 'divide_from', type: 'string' },
248 { name: 'fermentables', type: 'array' },
249 { name: 'hops', type: 'array' },
250 { name: 'miscs', type: 'array' },
251 { name: 'yeasts', type: 'array' },
252 { name: 'mashs', type: 'array' }
253 ],
254 id: 'record',
255 url: url + '?record=' + my_record
256 },
257
258 // Load data and select one record.
259 dataAdapter = new $.jqx.dataAdapter(source, {
260 loadComplete: function() {
261 var records = dataAdapter.records;
262 dataRecord = records[0];
263 // Hidden record uuid
264 $('#name').val(dataRecord.name);
265 $('#code').val(dataRecord.code);
266 $('#stage').val(StageData[dataRecord.stage].nl);
267 // Disable stages that are already done.
268 for (i = 0; i < SplitData.length; i++) {
269 console.log('i:' + i + ' ok:' + SplitData[i].ok + ' stage:' + dataRecord.stage);
270 if (SplitData[i].ok < dataRecord.stage)
271 $("#divide_type").jqxDropDownList('disableAt', i);
272 }
273 },
274 loadError: function(jqXHR, status, error) {
275 },
276 beforeLoadComplete: function(records) {
277 $('#jqxLoader').jqxLoader('open');
278 }
279 });
280
281 var editSplit = function(data) {
282 var splitSource = {
283 datatype: 'local',
284 cache: false,
285 async: false,
286 datafields: [
287 { name: 'split_name', type: 'string' },
288 { name: 'split_size', type: 'float' }
289 ],
290 addrow: function(rowid, rowdata, position, commit) {
291 console.log('split addrow ' + rowid);
292 commit(true);
293 },
294 deleterow: function(rowid, commit) {
295 console.log('split deleterow ' + rowid);
296 commit(true);
297 }
298 },
299 splitAdapter = new $.jqx.dataAdapter(splitSource, {});
300 $('#splitGrid').jqxGrid({
301 width: 1240,
302 height: 400,
303 source: splitAdapter,
304 theme: theme,
305 selectionmode: 'singlerow',
306 showtoolbar: true,
307 rendertoolbar: function(toolbar) {
308 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
309 toolbar.append(container);
310 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe splitsing" />');
311 container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder splitsing" />');
312 $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, height: 27, width: 150 });
313 $('#saddrowbutton').on('click', function() {
314 var row = {}, rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount;
315 row['split_name'] = dataRecord.name + ' ' + (rowscount + 1);
316 row['split_size'] = 0;
317 $('#splitGrid').jqxGrid('addrow', null, row);
318 });
319 // delete selected split
320 $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, height: 27, width: 150 });
321 $('#sdeleterowbutton').on('click', function() {
322 var rowscount, id, selectedrowindex = $('#splitGrid').jqxGrid('getselectedrowindex');
323 rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount;
324 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
325 id = $('#splitGrid').jqxGrid('getrowid', selectedrowindex);
326 $('#splitGrid').jqxGrid('deleterow', id);
327 }
328 });
329 },
330 columns: [
331 { text: 'Splits naam', datafield: 'split_name' },
332 { text: 'Splits volume', datafield: 'split_size', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'f2' }
333 ]
334 });
335 };
336
337 dataAdapter.dataBind();
338 editSplit(dataRecord);
339
340 // initialize the input fields.
341 $('#name').jqxTooltip({ content: 'De naam voor dit product.' });
342 $('#name').jqxInput({ theme: theme, width: 640, height: 23 });
343 $('#code').jqxTooltip({ content: 'Product code nummer.' });
344 $('#code').jqxInput({ theme: theme, width: 100, height: 23 });
345 $('#stage').jqxTooltip({ content: 'De productie fase van dit product.' });
346 $('#stage').jqxInput({ theme: theme, width: 100, height: 23 });
347 $('#divide_type').val(0);
348 $('#divide_type').on('change', function(event) {
349 dataRecord.divide_type = event.args.index;
350 });
351
352 $('#Cancel').jqxButton({ template: 'primary', width: '80px', theme: theme });
353 $('#Cancel').bind('click', function() {
354 window.location.href = my_return;
355 });
356
357 $('#Save').jqxButton({ template: 'success', width: '80px', theme: theme });
358 $('#Save').bind('click', function() {
359 // saveRecord(1);
360 });
361
362 });

mercurial