www/js/inv_fermentables.js

changeset 488
77f1617b6994
parent 477
7952f9331fd1
child 514
3c680d1dea35
equal deleted inserted replaced
487:06df1320327c 488:77f1617b6994
42 } 42 }
43 43
44 44
45 $(document).ready(function () { 45 $(document).ready(function () {
46 46
47 var dataRecord = {};
48
49 function calcTotal(cost, inventory) { 47 function calcTotal(cost, inventory) {
50 48
51 $('#totval').val(cost * inventory); 49 $('#totval').val(cost * inventory);
52 } 50 }
53 51
54 var url = "includes/db_inventory_fermentables.php"; 52 var dataRecord = {},
53 url = 'includes/db_inventory_fermentables.php',
55 // prepare the data 54 // prepare the data
56 var source = { 55 source = {
57 datatype: "json", 56 datatype: "json",
58 cache: false, 57 cache: false,
59 datafields: [ 58 datafields: [
60 { name: 'record', type: 'number' }, 59 { name: 'record', type: 'number' },
61 { name: 'name', type: 'string' }, 60 { name: 'name', type: 'string' },
93 url: url, 92 url: url,
94 cache: false, 93 cache: false,
95 data: data, 94 data: data,
96 type: "POST", 95 type: "POST",
97 success: function (data, status, xhr) { 96 success: function (data, status, xhr) {
98 // delete command is executed.
99 commit(true); 97 commit(true);
98 location.reload( true );
100 }, 99 },
101 error: function (jqXHR, textStatus, errorThrown) { 100 error: function (jqXHR, textStatus, errorThrown) {
102 commit(false); 101 commit(false);
103 } 102 }
104 }); 103 });
111 cache: false, 110 cache: false,
112 data: data, 111 data: data,
113 type: "POST", 112 type: "POST",
114 success: function (data, status, xhr) { 113 success: function (data, status, xhr) {
115 commit(true); 114 commit(true);
115 location.reload( true );
116 }, 116 },
117 error: function(jqXHR, textStatus, errorThrown) { 117 error: function(jqXHR, textStatus, errorThrown) {
118 commit(false); 118 commit(false);
119 } 119 }
120 }); 120 });
126 url: url, 126 url: url,
127 cache: false, 127 cache: false,
128 data: data, 128 data: data,
129 type: "POST", 129 type: "POST",
130 success: function (data, status, xhr) { 130 success: function (data, status, xhr) {
131 // update command is executed.
132 commit(true); 131 commit(true);
132 location.reload( true );
133 }, 133 },
134 error: function(jqXHR, textStatus, errorThrown) { 134 error: function(jqXHR, textStatus, errorThrown) {
135 commit(false); 135 commit(false);
136 } 136 }
137 }); 137 });
138 } 138 }
139 }; 139 },
140 dataAdapter = new $.jqx.dataAdapter(source),
141 editrow = -1;
142
140 // initialize the input fields. 143 // initialize the input fields.
141 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); 144 $("#name").jqxInput({ theme: theme, width: 640, height: 23 });
142 $("#type").jqxDropDownList({ 145 $("#type").jqxDropDownList({
143 theme: theme, 146 theme: theme,
144 source: FermentableTypeAdapter, 147 source: FermentableTypeAdapter,
186 $("#production_date").jqxDateTimeInput( Dateopts ); 189 $("#production_date").jqxDateTimeInput( Dateopts );
187 $("#cost").jqxNumberInput( Spin2dec ); 190 $("#cost").jqxNumberInput( Spin2dec );
188 $("#tht_date").jqxDateTimeInput( Dateopts ); 191 $("#tht_date").jqxDateTimeInput( Dateopts );
189 $("#totval").jqxNumberInput( Show2dec ); 192 $("#totval").jqxNumberInput( Show2dec );
190 193
191 var dataAdapter = new $.jqx.dataAdapter(source);
192 var editrow = -1;
193 // initialize jqxGrid 194 // initialize jqxGrid
194 $("#jqxgrid").jqxGrid({ 195 $("#jqxgrid").jqxGrid({
195 width: 1280, 196 width: 1280,
196 height: 630, 197 height: 630,
197 source: dataAdapter, 198 source: dataAdapter,
198 theme: theme, 199 theme: theme,
199 showstatusbar: true, 200 showstatusbar: true,
200 renderstatusbar: function (statusbar) { 201 renderstatusbar: function (statusbar) {
201 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); 202 var container, addButton, impButton;
202 var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>"); 203 container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
203 var impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>"); 204 addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Nieuw</span></div>");
205 impButton = $("<div style='float: right; margin-right: 50px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Import</span></div>");
204 container.append(addButton); 206 container.append(addButton);
205 container.append(impButton); 207 container.append(impButton);
206 statusbar.append(container); 208 statusbar.append(container);
207 addButton.jqxButton({ theme: theme, width: 90, height: 20 }); 209 addButton.jqxButton({ theme: theme, width: 90, height: 20 });
208 impButton.jqxButton({ theme: theme, width: 90, height: 20 }); 210 impButton.jqxButton({ theme: theme, width: 90, height: 20 });
235 $("#production_date").val(''); 237 $("#production_date").val('');
236 $("#tht_date").val(''); 238 $("#tht_date").val('');
237 $("#popupWindow").jqxWindow('open'); 239 $("#popupWindow").jqxWindow('open');
238 }); 240 });
239 impButton.click(function (event) { 241 impButton.click(function (event) {
240 var url="import_ingredients.php?select=fermentables"; 242 window.location.href = 'import_ingredients.php?select=fermentables';
241 window.location.href = url;
242 }); 243 });
243 }, 244 },
244 filterable: true, 245 filterable: true,
245 filtermode: 'excel', 246 filtermode: 'excel',
246 columns: [ 247 columns: [
269 amount = dataAdapter.formatNumber(value,"f1")+" kg"; 270 amount = dataAdapter.formatNumber(value,"f1")+" kg";
270 } 271 }
271 return "<span style='margin: 3px; margin-top: 6px; float: right;'>" + amount + "</span>"; 272 return "<span style='margin: 3px; margin-top: 6px; float: right;'>" + amount + "</span>";
272 } 273 }
273 }, 274 },
274 { text: '', datafield: 'Edit', width: 100, align: 'center', menu: false, columntype: 'button', cellsrenderer: function () { 275 { text: '', datafield: 'Edit', width: 100, align: 'center', menu: false, columntype: 'button',
275 return "Wijzig"; 276 cellsrenderer: function () {
277 return "Wijzig";
276 }, buttonclick: function (row) { 278 }, buttonclick: function (row) {
277 // open the popup window when the user clicks a button. 279 // open the popup window when the user clicks a button.
278 editrow = row; 280 editrow = row;
279 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); 281 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } });
280 // get the clicked row's data and initialize the input fields. 282 // get the clicked row's data and initialize the input fields.
373 graintype: $('#graintype').val(), 375 graintype: $('#graintype').val(),
374 inventory: 0, 376 inventory: 0,
375 cost: parseFloat($('#cost').jqxNumberInput('decimal')), 377 cost: parseFloat($('#cost').jqxNumberInput('decimal')),
376 production_date: '', 378 production_date: '',
377 tht_date: '' 379 tht_date: ''
378
379 }; 380 };
380 $('#jqxgrid').jqxGrid('addrow', null, row); 381 $('#jqxgrid').jqxGrid('addrow', null, row);
381 $('#popupWindow').jqxWindow('hide'); 382 $('#popupWindow').jqxWindow('hide');
382 location.reload( true ); // reload ourself.
383 }); 383 });
384 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); 384 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
385 // update the edited row when the user clicks the 'Save' button. 385 // update the edited row when the user clicks the 'Save' button.
386 $("#Save").click(function() { 386 $("#Save").click(function() {
387 var rowID = -1; 387 var row, rowID = -1;
388 if (editrow >= 0) { 388 if (editrow >= 0) {
389 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); 389 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
390 } 390 }
391 var row = { 391 row = {
392 record: rowID, 392 record: rowID,
393 name: $("#name").val(), 393 name: $("#name").val(),
394 type: $("#type").val(), 394 type: $("#type").val(),
395 yield: parseFloat($("#yield").jqxNumberInput('decimal')), 395 yield: parseFloat($("#yield").jqxNumberInput('decimal')),
396 color: parseFloat($("#color").jqxNumberInput('decimal')), 396 color: parseFloat($("#color").jqxNumberInput('decimal')),
417 }; 417 };
418 if (editrow >= 0) { 418 if (editrow >= 0) {
419 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 419 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
420 } else { 420 } else {
421 $('#jqxgrid').jqxGrid('addrow', null, row); 421 $('#jqxgrid').jqxGrid('addrow', null, row);
422 location.reload( true ); // reload ourself.
423 } 422 }
424 $("#popupWindow").jqxWindow('hide'); 423 $("#popupWindow").jqxWindow('hide');
425 }); 424 });
426 createDelElements(); 425 createDelElements();
427 }); 426 });

mercurial