www/js/rec_edit.js

changeset 73
454fc4558609
parent 72
93a0be4f5be3
child 79
f3adf543f698
equal deleted inserted replaced
72:93a0be4f5be3 73:454fc4558609
48 48
49 // $("#jqxNotification").jqxNotification({ width: "auto", position: "top-right", opacity: 0.9, 49 // $("#jqxNotification").jqxNotification({ width: "auto", position: "top-right", opacity: 0.9,
50 // autoOpen: false, closeOnClick: true, autoClose: true, template: "info", blink: false, 50 // autoOpen: false, closeOnClick: true, autoClose: true, template: "info", blink: false,
51 // icon: { width: 25, height: 25, url: '../../images/smiley.png', padding: 5 } 51 // icon: { width: 25, height: 25, url: '../../images/smiley.png', padding: 5 }
52 // }); 52 // });
53
54 function calcFermentables (resize) {
55 console.log("calcFermentables(" + resize + ")");
56 // recalc grid percentages.
57 var t_amount = 0;
58 var rows = $('#fermentableGrid').jqxGrid('getboundrows');
59 for (var i = 0; i < rows.length; i++) {
60 var row = rows[i];
61 t_amount += row.f_amount;
62 console.log ("loop: " + i + " kg:" + row.f_amount + " pct:" + row.f_percentage + " adjust:" + row.f_adjust_to_total_100);
63 }
64 console.log("total:" + t_amount);
65 for (var i = 0; i < rows.length; i++) {
66 var row = rows[i];
67 row.f_percentage = (row.f_amount / t_amount) * 100.0;
68 }
69 // if resize == true resize the malts bill.
70 // if recalc grid malts
71 $('#est_og').val(0);
72 };
73
74 function calcInit () {
75 console.log("calc.init()");
76 $('#est_og').on('change', function (event) { calcFermentables(true); });
77 $('#efficiency').on('change', function (event) { calcFermentables(true); });
78 $('#batch_size').on('change', function (event) { calcFermentables(true); });
79 $('#boil_time').on('change', function (event) { calcFermentables(true); });
80 $('#fermentableGrid').on('change', function (event) { calcFermentables(false); });
81 };
82
83 // Styles dropdown list
84 var stylesUrl = "includes/db_profile_styles.php";
85 var stylesSource = {
86 datatype: "json",
87 datafields: [
88 { name: 'record', type: 'number' },
89 { name: 'name', type: 'string' },
90 { name: 'category', type: 'string' },
91 { name: 'category_number', type: 'number' },
92 { name: 'style_letter', type: 'string' },
93 { name: 'style_guide', type: 'string' },
94 { name: 'type', type: 'string' },
95 { name: 'og_min', type: 'float' },
96 { name: 'og_max', type: 'float' },
97 { name: 'fg_min', type: 'float' },
98 { name: 'fg_max', type: 'float' },
99 { name: 'ibu_min', type: 'float' },
100 { name: 'ibu_max', type: 'float' },
101 { name: 'color_min', type: 'float' },
102 { name: 'color_max', type: 'float' },
103 { name: 'carb_min', type: 'float' },
104 { name: 'carb_max', type: 'float' },
105 { name: 'abv_min', type: 'float' },
106 { name: 'abv_max', type: 'float' },
107 { name: 'notes', type: 'string' },
108 { name: 'profile', type: 'string' },
109 { name: 'ingredients', type: 'string' },
110 { name: 'examples', type: 'string' }
111 ],
112 url: stylesUrl,
113 async: true
114 };
115 var styleslist = new $.jqx.dataAdapter(stylesSource);
116 $("#styleSelect").jqxDropDownList({
117 placeHolder: "Kies bierstijl:",
118 theme: theme,
119 source: styleslist,
120 displayMember: "name",
121 width: 150,
122 height: 27,
123 dropDownVerticalAlignment: 'top',
124 dropDownWidth: 500,
125 dropDownHeight: 380,
126 renderer: function (index, label, value) {
127 var datarecord = styleslist.records[index];
128 return datarecord.style_guide + " " + datarecord.style_letter+ " " + datarecord.name;
129 }
130 });
131 $("#styleSelect").on('select', function (event) {
132 if (event.args) {
133 var index = event.args.index;
134 var datarecord = styleslist.records[index];
135 $("#st_name").val(datarecord.name);
136 $("#st_category").val(datarecord.category);
137 $("#st_category_number").val(datarecord.category_number);
138 $("#st_letter").val(datarecord.style_letter);
139 $("#st_guide").val(datarecord.style_guide);
140 $("#st_type").val(datarecord.type);
141 $("#st_og_min").val(datarecord.og_min);
142 $("#st_og_max").val(datarecord.og_max);
143 $("#st_fg_min").val(datarecord.fg_min);
144 $("#st_fg_max").val(datarecord.fg_max);
145 $("#st_ibu_min").val(datarecord.ibu_min);
146 $("#st_ibu_max").val(datarecord.ibu_max);
147 $("#st_color_min").val(datarecord.color_min);
148 $("#st_color_max").val(datarecord.color_max);
149 $("#st_carb_min").val(datarecord.carb_min);
150 $("#st_carb_max").val(datarecord.carb_max);
151 $("#st_abv_min").val(datarecord.abv_min);
152 $("#st_abv_max").val(datarecord.abv_max);
153 }
154 });
53 155
54 var dataReecord = {}; 156 var dataReecord = {};
55 var url = "includes/db_recipes.php"; 157 var url = "includes/db_recipes.php";
56 // tooltips 158 // tooltips
57 $("#name").jqxTooltip({ content: 'De naam voor dit recept.' }); 159 $("#name").jqxTooltip({ content: 'De naam voor dit recept.' });
259 async: true 361 async: true
260 }; 362 };
261 var fermentablelist = new $.jqx.dataAdapter(fermentableInvSource); 363 var fermentablelist = new $.jqx.dataAdapter(fermentableInvSource);
262 364
263 $("#fermentableGrid").jqxGrid({ 365 $("#fermentableGrid").jqxGrid({
264 width: 960, 366 width: 1050,
265 height: 400, 367 height: 400,
266 source: fermentableAdapter, 368 source: fermentableAdapter,
267 theme: theme, 369 theme: theme,
268 selectionmode: 'singlerow', 370 selectionmode: 'singlerow',
269 editmode: 'selectedrow', 371 editmode: 'selectedrow',
309 row["f_moisture"] = datarecord.moisture; 411 row["f_moisture"] = datarecord.moisture;
310 row["f_diastatic_power"] = datarecord.diastatic_power; 412 row["f_diastatic_power"] = datarecord.diastatic_power;
311 row["f_protein"] = datarecord.protein; 413 row["f_protein"] = datarecord.protein;
312 row["f_max_in_batch"] = datarecord.max_in_batch; 414 row["f_max_in_batch"] = datarecord.max_in_batch;
313 row["f_graintype"] = datarecord.graintype; 415 row["f_graintype"] = datarecord.graintype;
314 if (datarecord.type == "Sugar") { 416 if (datarecord.add_after_boil) {
417 row["f_added"] = "Primary";
418 } else if ((datarecord.type == "Sugar") || (datarecord.type == "Adjunct")) {
315 row["f_added"] = "Boil"; 419 row["f_added"] = "Boil";
316 } else { 420 } else {
317 row["f_added"] = "Mash"; 421 row["f_added"] = "Mash";
318 } 422 }
319 row["f_dissolved_protein"] = 0; 423 row["f_dissolved_protein"] = 0;
346 }, 450 },
347 columns: [ 451 columns: [
348 { text: 'Mout/suiker', editable: false, datafield: 'f_name', 452 { text: 'Mout/suiker', editable: false, datafield: 'f_name',
349 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) { 453 cellsrenderer: function (row, columnfield, value, defaulthtml, columnproperties) {
350 var rowData = $("#fermentableGrid").jqxGrid('getrowdata', row); 454 var rowData = $("#fermentableGrid").jqxGrid('getrowdata', row);
351 return rowData.f_name + " (" + rowData.f_color + " EBC)"; 455 return "<span style='margin: 3px; margin-top: 6px; float: "+columnproperties.cellsalign+"'>" +rowData.f_name + " (" + rowData.f_color + " EBC)</span>";
352 } 456 }
353 }, 457 },
354 { text: 'Type', editable: false, width: 100, datafield: 'f_type' }, 458 { text: 'Type', editable: false, width: 100, datafield: 'f_type' },
459 { text: 'Moment', editable: false, width: 100, datafield: 'f_added' },
355 { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, 460 { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 80, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
356 { text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3', 461 { text: 'Gewicht', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3',
357 columntype: 'numberinput', 462 columntype: 'numberinput',
358 validation: function (cell, value) { 463 validation: function (cell, value) {
359 // Maximum weight is the batch_size, just a simple check. 464 // Maximum weight is the batch_size, just a simple check.
362 return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" }; 467 return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" };
363 } 468 }
364 return true; 469 return true;
365 }, 470 },
366 initeditor: function (row, cellvalue, editor) { 471 initeditor: function (row, cellvalue, editor) {
367 editor.jqxNumberInput({ decimalDigits: 3 }); 472 editor.jqxNumberInput({ inputMode: 'simple', decimalDigits: 3 });
368 } 473 }
369 }, 474 },
370 { text: 'Procent', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1', 475 { text: 'Procent', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1',
371 columntype: 'numberinput', 476 columntype: 'numberinput',
372 validation: function (cell, value) { 477 validation: function (cell, value) {
381 }, 486 },
382 { text: '100%', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80 } 487 { text: '100%', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80 }
383 ] 488 ]
384 }); 489 });
385 $("#fermentableGrid").on('cellendedit', function (event) { 490 $("#fermentableGrid").on('cellendedit', function (event) {
491 calcFermentables(false);
386 $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc'); 492 $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');
387 }); 493 });
388 }; 494 };
389 495
390 // Inline hops editor 496 // Inline hops editor
1126 height: 630, 1232 height: 630,
1127 autoHeight: false, 1233 autoHeight: false,
1128 position: 'top' 1234 position: 'top'
1129 }); 1235 });
1130 1236
1237 calcInit();
1238
1131 $("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme }); 1239 $("#Delete").jqxButton({ template: "danger", width: '80px', theme: theme });
1132 $("#Delete").click(function () { 1240 $("#Delete").click(function () {
1133 // Open a popup to confirm this action. 1241 // Open a popup to confirm this action.
1134 $('#eventWindow').jqxWindow('open'); 1242 $('#eventWindow').jqxWindow('open');
1135 $("#delOk").click(function () { 1243 $("#delOk").click(function () {
1171 st_letter: $('#st_letter').val(), 1279 st_letter: $('#st_letter').val(),
1172 st_guide: $('#st_guide').val(), 1280 st_guide: $('#st_guide').val(),
1173 st_type: $('#st_type').val(), 1281 st_type: $('#st_type').val(),
1174 st_category: $('#st_category').val(), 1282 st_category: $('#st_category').val(),
1175 st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')), 1283 st_category_number: parseFloat($("#st_category_number").jqxNumberInput('decimal')),
1176 st_og_min: dataRecord.st_og_min, 1284 st_og_min: parseFloat($("#st_og_min").jqxNumberInput('decimal')),
1177 st_og_max: dataRecord.st_og_max, 1285 st_og_max: parseFloat($("#st_og_max").jqxNumberInput('decimal')),
1178 st_fg_min: dataRecord.st_fg_min, 1286 st_fg_min: parseFloat($("#st_fg_min").jqxNumberInput('decimal')),
1179 st_fg_max: dataRecord.st_fg_max, 1287 st_fg_max: parseFloat($("#st_fg_max").jqxNumberInput('decimal')),
1180 st_ibu_min: dataRecord.st_ibu_min, 1288 st_ibu_min: parseFloat($("#st_ibu_min").jqxNumberInput('decimal')),
1181 st_ibu_max: dataRecord.st_ibu_max, 1289 st_ibu_max: parseFloat($("#st_ibu_max").jqxNumberInput('decimal')),
1182 st_color_min: dataRecord.st_color_min, 1290 st_color_min: parseFloat($("#st_color_min").jqxNumberInput('decimal')),
1183 st_color_max: dataRecord.st_color_max, 1291 st_color_max: parseFloat($("#st_color_max").jqxNumberInput('decimal')),
1184 st_carb_min: dataRecord.st_carb_min, 1292 st_carb_min: parseFloat($("#st_carb_min").jqxNumberInput('decimal')),
1185 st_carb_max: dataRecord.st_carb_max, 1293 st_carb_max: parseFloat($("#st_carb_max").jqxNumberInput('decimal')),
1186 st_abv_min: dataRecord.st_abv_min, 1294 st_abv_min: parseFloat($("#st_abv_min").jqxNumberInput('decimal')),
1187 st_abv_max: dataRecord.st_abv_max, 1295 st_abv_max: parseFloat($("#st_abv_max").jqxNumberInput('decimal')),
1188 type: $("#type").val(), 1296 type: $("#type").val(),
1189 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')), 1297 batch_size: parseFloat($("#batch_size").jqxNumberInput('decimal')),
1190 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')), 1298 boil_time: parseFloat($("#boil_time").jqxNumberInput('decimal')),
1191 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')), 1299 efficiency: parseFloat($("#efficiency").jqxNumberInput('decimal')),
1192 est_og: parseFloat($("#est_og").jqxNumberInput('decimal')), 1300 est_og: parseFloat($("#est_og").jqxNumberInput('decimal')),

mercurial