www/js/rec_edit.js

changeset 129
7f41b61c3faf
parent 128
4d188d216c88
child 130
601920b902e5
equal deleted inserted replaced
128:4d188d216c88 129:7f41b61c3faf
51 var sugarsf = 0; // Sugars after boil 51 var sugarsf = 0; // Sugars after boil
52 var psugar = 0; // Percentage real sugars 52 var psugar = 0; // Percentage real sugars
53 var pcara = 0; // Percentage cara/crystal malts 53 var pcara = 0; // Percentage cara/crystal malts
54 54
55 console.log("record:" + my_record + " return:" + my_return + " theme:" + theme); 55 console.log("record:" + my_record + " return:" + my_return + " theme:" + theme);
56 $("#jqxLoader").jqxLoader({
57 width: 250,
58 height: 150,
59 isModal: true,
60 text: "Laden recept ...",
61 theme: theme
62 });
56 63
57 function calcFermentables() { 64 function calcFermentables() {
58 console.log("calcFermentables()"); 65 console.log("calcFermentables()");
59 sugarsf = 0; 66 sugarsf = 0;
60 sugarsm = 0; 67 sugarsm = 0;
109 calcIBUs(); 116 calcIBUs();
110 }); 117 });
111 // $('#efficiency').on('change', function (event) { calcFermentables(); }); 118 // $('#efficiency').on('change', function (event) { calcFermentables(); });
112 // $('#batch_size').on('change', function (event) { calcFermentables(); }); 119 // $('#batch_size').on('change', function (event) { calcFermentables(); });
113 // $('#boil_time').on('change', function (event) { calcFermentables(); }); 120 // $('#boil_time').on('change', function (event) { calcFermentables(); });
114 // $('#fermentableGrid').on('change', function (event) { calcFermentables(); });
115 }; 121 };
116 122
117 // Styles dropdown list 123 // Styles dropdown list
118 var stylesUrl = "includes/db_profile_styles.php"; 124 var stylesUrl = "includes/db_profile_styles.php";
119 var stylesSource = { 125 var stylesSource = {
325 }, 331 },
326 loadError: function (jqXHR, status, error) { 332 loadError: function (jqXHR, status, error) {
327 }, 333 },
328 beforeLoadComplete: function (records) { 334 beforeLoadComplete: function (records) {
329 var filteredRecords = []; 335 var filteredRecords = [];
336 $('#jqxLoader').jqxLoader('open');
330 for (var i = 0; i < records.length; i++) { 337 for (var i = 0; i < records.length; i++) {
331 if (records[i].record == my_record) { 338 if (records[i].record == my_record) {
332 filteredRecords.push(records[i]); 339 filteredRecords.push(records[i]);
333 } 340 }
334 } 341 }
482 $("#fdeleterowbutton").on('click', function () { 489 $("#fdeleterowbutton").on('click', function () {
483 var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex'); 490 var selectedrowindex = $("#fermentableGrid").jqxGrid('getselectedrowindex');
484 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; 491 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
485 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 492 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
486 var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex); 493 var id = $("#fermentableGrid").jqxGrid('getrowid', selectedrowindex);
494 var percent = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_percentage");
495 var amount = $('#fermentableGrid').jqxGrid('getcellvalue', id, "f_amount");
487 var commit = $("#fermentableGrid").jqxGrid('deleterow', id); 496 var commit = $("#fermentableGrid").jqxGrid('deleterow', id);
488 } 497 }
498 rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
499 if (rowscount > 1) {
500 if (to_100) {
501 for (var i = 0; i < rowscount; i++) {
502 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
503 if (rowdata.f_adjust_to_total_100) {
504 rowdata.f_percentage += percent;
505 rowdata.f_amount += amount;
506 }
507 }
508 } else {
509 var tw = 0;
510 for (i = 0; i < rowscount; i++) {
511 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
512 tw += rowdata.f_amount;
513 };
514 for (i = 0; i < rowscount; i++) {
515 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
516 var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
517 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
518 };
519 }
520 } else {
521 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
522 }
523 calcFermentables();
524 calcIBUs();
489 }); 525 });
490 }, 526 },
491 ready: function() { 527 ready: function() {
492 calcFermentables(); 528 calcFermentables();
493 $('#jqxTabs').jqxTabs('next'); 529 $('#jqxTabs').jqxTabs('next');
505 var srcAdded = [ "Mash", "Boil", "Fermentation", "Lagering", "Bottle" ]; 541 var srcAdded = [ "Mash", "Boil", "Fermentation", "Lagering", "Bottle" ];
506 editor.jqxDropDownList({ autoDropDownHeight: true, source: srcAdded }); 542 editor.jqxDropDownList({ autoDropDownHeight: true, source: srcAdded });
507 } 543 }
508 }, 544 },
509 { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, 545 { text: 'Opbrengst', editable: false, datafield: 'f_yield', width: 90, align: 'right', cellsalign: 'right', cellsformat: 'p1' },
510 { text: 'Gewicht Kg', datafield: 'f_amount', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'f3', 546 { text: 'Gewicht Kg', datafield: 'f_amount', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f3',
511 columntype: 'numberinput', 547 columntype: 'numberinput',
512 validation: function (cell, value) { 548 validation: function (cell, value) {
513 // Maximum weight is the batch_size, just a simple check. 549 // Maximum weight is the batch_size, just a simple check.
514 var maxmout = parseFloat($("#batch_size").jqxNumberInput('decimal')); 550 var maxmout = parseFloat($("#batch_size").jqxNumberInput('decimal'));
515 if (value < 0 || value > maxmout) { 551 if (value < 0 || value > maxmout) {
516 return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" }; 552 return { result: false, message: "Gewicht moet 0-"+maxmout+" zijn" };
517 } 553 }
518 return true; 554 return true;
519 }, 555 },
520 initeditor: function (row, cellvalue, editor) { 556 initeditor: function (row, cellvalue, editor) {
521 editor.jqxNumberInput({ inputMode: 'simple', decimalDigits: 3 }); 557 editor.jqxNumberInput({ inputMode: 'simple', min: 0, decimalDigits: 3, spinButtons: false });
558 },
559 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
560 if (to_100) {
561 return oldvalue; // When using percentages, don't allow edited results.
562 }
563 // console.log("row:"+row+" col:"+column+" type:"+columntype+" old:"+oldvalue+" new:"+newvalue);
522 } 564 }
523 }, 565 },
524 { text: 'Percentage', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1', 566 { text: 'Percentage', datafield: 'f_percentage', width: 110, align: 'right', cellsalign: 'right', cellsformat: 'p1',
525 columntype: 'numberinput', 567 columntype: 'numberinput',
526 validation: function (cell, value) { 568 validation: function (cell, value) {
532 initeditor: function (row, cellvalue, editor) { 574 initeditor: function (row, cellvalue, editor) {
533 editor.jqxNumberInput({ decimalDigits: 1, min: 0, max: 100, spinButtons: false }); 575 editor.jqxNumberInput({ decimalDigits: 1, min: 0, max: 100, spinButtons: false });
534 }, 576 },
535 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { 577 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
536 oldvalue = Math.round(oldvalue * 10) / 10.0; 578 oldvalue = Math.round(oldvalue * 10) / 10.0;
537 // console.log("row:"+row+" col:"+column+" type:"+columntype+" old:"+oldvalue+" new:"+newvalue);
538 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount; 579 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
539 if ((oldvalue != newvalue) && (rowscount > 1)) { 580 if ((oldvalue != newvalue) && (rowscount > 1)) {
540 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', row); 581 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', row);
541 if (rowdata.f_adjust_to_total_100) { 582 if (rowdata.f_adjust_to_total_100) {
542 return oldvalue; 583 return oldvalue;
559 } 600 }
560 } 601 }
561 } else { 602 } else {
562 // Adjust all the rows. 603 // Adjust all the rows.
563 var nw = tw * diff / 100; 604 var nw = tw * diff / 100;
564 // console.log("weight:"+nw);
565 for (i = 0; i < rowscount; i++) { 605 for (i = 0; i < rowscount; i++) {
566 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i); 606 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
567 if (i == row) { 607 if (i == row) {
568 rowdata.f_amount += nw; 608 rowdata.f_amount += nw;
569 } else { 609 } else {
570 rowdata.f_amount -= nw / (rowscount - 1); 610 rowdata.f_amount -= nw / (rowscount - 1);
571 rowdata.f_percentage = Math.round((rowdata.f_amount / tw) * 1000) / 10.0; 611 rowdata.f_percentage = Math.round((rowdata.f_amount / tw) * 1000) / 10.0;
572 } 612 }
573 } 613 }
574 } 614 }
575 // $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc');
576 //$('#fermentableGrid').jqxGrid('render');
577 // console.log("diff:"+diff+" len:"+rowscount+" to100:"+to_100+" tw:"+tw);
578 } 615 }
579 } 616 }
580 }, 617 },
581 { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80, 618 { text: '100%', align: 'center', datafield: 'f_adjust_to_total_100', columntype: 'checkbox', width: 80,
582 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) { 619 cellvaluechanging: function (row, column, columntype, oldvalue, newvalue) {
594 ] 631 ]
595 }); 632 });
596 $("#fermentableGrid").on('cellendedit', function (event) { 633 $("#fermentableGrid").on('cellendedit', function (event) {
597 var args = event.args; 634 var args = event.args;
598 console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value); 635 console.log("Event Type: cellendedit, Column: " + args.datafield + ", Row: " + (args.rowindex) + ", Value: " + args.value);
599 // $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc'); 636 // Make sure the grid itself is updated.
637 $("#fermentableGrid").jqxGrid('setcellvalue', args.rowindex, args.datafield, args.value);
638 if ((args.datafield == 'f_amount') && (! to_100)) {
639 // If one of the amounts is changed, recalculate the percentages.
640 console.log("adjust percentages");
641 var rowscount = $("#fermentableGrid").jqxGrid('getdatainformation').rowscount;
642 if (rowscount > 1) {
643 var tw = 0;
644 for (i = 0; i < rowscount; i++) {
645 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
646 tw += rowdata.f_amount;
647 };
648 for (i = 0; i < rowscount; i++) {
649 var rowdata = $("#fermentableGrid").jqxGrid('getrowdata', i);
650 var percentage = Math.round(rowdata.f_amount / tw * 1000) / 10.0;
651 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_percentage", percentage);
652 };
653 } else {
654 $("#fermentableGrid").jqxGrid('setcellvalue', 0, "f_percentage", 100);
655 }
656 };
657 $('#fermentableGrid').jqxGrid('sortby', 'f_amount', 'desc'); // TODO: not reliable
600 calcFermentables(); 658 calcFermentables();
659 calcIBUs(); // Depends on gravity, so recalculate.
601 }); 660 });
602 }; 661 };
603 662
604 // Inline hops editor 663 // Inline hops editor
605 var editHop = function (data) { 664 var editHop = function (data) {
1259 } 1318 }
1260 }); 1319 });
1261 }, 1320 },
1262 ready: function() { 1321 ready: function() {
1263 calcInit(); 1322 calcInit();
1323 $('#jqxLoader').jqxLoader('close');
1264 $('#jqxTabs').jqxTabs('first'); 1324 $('#jqxTabs').jqxTabs('first');
1265 }, 1325 },
1266 columns: [ 1326 columns: [
1267 { text: 'Stap naam', datafield: 'step_name' }, 1327 { text: 'Stap naam', datafield: 'step_name' },
1268 { text: 'Stap type', datafield: 'step_type', width: 110, columntype: 'dropdownlist', 1328 { text: 'Stap type', datafield: 'step_type', width: 110, columntype: 'dropdownlist',

mercurial