www/js/inv_hops.js

changeset 488
77f1617b6994
parent 395
463d64cce768
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 / 1000)); 49 $('#totval').val(cost * (inventory / 1000));
52 } 50 }
53 51
54 var url = "includes/db_inventory_hops.php"; 52 var dataRecord = {},
53 url = 'includes/db_inventory_hops.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' },
88 url: url, 87 url: url,
89 cache: false, 88 cache: false,
90 data: data, 89 data: data,
91 type: "POST", 90 type: "POST",
92 success: function (data, status, xhr) { 91 success: function (data, status, xhr) {
93 // delete command is executed.
94 commit(true); 92 commit(true);
93 location.reload( true );
95 }, 94 },
96 error: function (jqXHR, textStatus, errorThrown) { 95 error: function (jqXHR, textStatus, errorThrown) {
97 commit(false); 96 commit(false);
98 } 97 }
99 }); 98 });
106 cache: false, 105 cache: false,
107 data: data, 106 data: data,
108 type: "POST", 107 type: "POST",
109 success: function (data, status, xhr) { 108 success: function (data, status, xhr) {
110 commit(true); 109 commit(true);
110 location.reload( true );
111 }, 111 },
112 error: function(jqXHR, textStatus, errorThrown) { 112 error: function(jqXHR, textStatus, errorThrown) {
113 commit(false); 113 commit(false);
114 } 114 }
115 }); 115 });
121 url: url, 121 url: url,
122 cache: false, 122 cache: false,
123 data: data, 123 data: data,
124 type: "POST", 124 type: "POST",
125 success: function (data, status, xhr) { 125 success: function (data, status, xhr) {
126 // update command is executed.
127 commit(true); 126 commit(true);
127 location.reload( true );
128 }, 128 },
129 error: function(jqXHR, textStatus, errorThrown) { 129 error: function(jqXHR, textStatus, errorThrown) {
130 commit(false); 130 commit(false);
131 } 131 }
132 }); 132 });
133 } 133 }
134 }; 134 },
135 dataAdapter = new $.jqx.dataAdapter(source),
136 editrow = -1;
137
135 // initialize the input fields. 138 // initialize the input fields.
136 $("#name").jqxInput({ theme: theme, width: 640, height: 23 }); 139 $("#name").jqxInput({ theme: theme, width: 640, height: 23 });
137 $("#alpha").jqxNumberInput( Perc1dec ); 140 $("#alpha").jqxNumberInput( Perc1dec );
138 $("#beta").jqxNumberInput( Perc1dec ); 141 $("#beta").jqxNumberInput( Perc1dec );
139 $("#humulene").jqxNumberInput( Perc1dec ); 142 $("#humulene").jqxNumberInput( Perc1dec );
169 $("#cost").jqxNumberInput( Spin2dec ); 172 $("#cost").jqxNumberInput( Spin2dec );
170 $("#tht_date").jqxDateTimeInput( Dateopts ); 173 $("#tht_date").jqxDateTimeInput( Dateopts );
171 $("#total_oil").jqxNumberInput( Perc1dec ); 174 $("#total_oil").jqxNumberInput( Perc1dec );
172 $("#totval").jqxNumberInput( Show2dec ); 175 $("#totval").jqxNumberInput( Show2dec );
173 176
174 var dataAdapter = new $.jqx.dataAdapter(source);
175 var editrow = -1;
176 // initialize jqxGrid 177 // initialize jqxGrid
177 $("#jqxgrid").jqxGrid({ 178 $("#jqxgrid").jqxGrid({
178 width: 1280, 179 width: 1280,
179 height: 630, 180 height: 630,
180 source: dataAdapter, 181 source: dataAdapter,
181 theme: theme, 182 theme: theme,
182 showstatusbar: true, 183 showstatusbar: true,
183 renderstatusbar: function (statusbar) { 184 renderstatusbar: function (statusbar) {
184 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); 185 var container, addButton, impButton;
185 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>"); 186 container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
186 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>"); 187 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>");
188 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>");
187 container.append(addButton); 189 container.append(addButton);
188 container.append(impButton); 190 container.append(impButton);
189 statusbar.append(container); 191 statusbar.append(container);
190 addButton.jqxButton({ theme: theme, width: 90, height: 20 }); 192 addButton.jqxButton({ theme: theme, width: 90, height: 20 });
191 impButton.jqxButton({ theme: theme, width: 90, height: 20 }); 193 impButton.jqxButton({ theme: theme, width: 90, height: 20 });
213 $("#tht_date").val(''); 215 $("#tht_date").val('');
214 $("#total_oil").val(0); 216 $("#total_oil").val(0);
215 $("#popupWindow").jqxWindow('open'); 217 $("#popupWindow").jqxWindow('open');
216 }); 218 });
217 impButton.click(function (event) { 219 impButton.click(function (event) {
218 var url="import_ingredients.php?select=hops"; 220 window.location.href = 'import_ingredients.php?select=hops';
219 window.location.href = url;
220 }); 221 });
221 }, 222 },
222 filterable: true, 223 filterable: true,
223 filtermode: 'excel', 224 filtermode: 'excel',
224 columns: [ 225 columns: [
249 amount = dataAdapter.formatNumber(value / 1000.0,"f1")+" kg"; 250 amount = dataAdapter.formatNumber(value / 1000.0,"f1")+" kg";
250 } 251 }
251 return '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>'; 252 return '<span style="margin: 4px; margin-top: 6px; float: right;">' + amount + '</span>';
252 } 253 }
253 }, 254 },
254 { text: '', datafield: 'Wijzig', columntype: 'button', width: 100, align: 'center', menu: false, cellsrenderer: function () { 255 { text: '', datafield: 'Wijzig', columntype: 'button', width: 100, align: 'center', menu: false,
255 return "Wijzig"; 256 cellsrenderer: function () {
257 return "Wijzig";
256 }, buttonclick: function (row) { 258 }, buttonclick: function (row) {
257 // open the popup window when the user clicks a button. 259 // open the popup window when the user clicks a button.
258 editrow = row; 260 editrow = row;
259 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); 261 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } });
260 // get the clicked row's data and initialize the input fields. 262 // get the clicked row's data and initialize the input fields.
346 tht_date: '', 348 tht_date: '',
347 total_oil: parseFloat($("#total_oil").jqxNumberInput('decimal')) 349 total_oil: parseFloat($("#total_oil").jqxNumberInput('decimal'))
348 }; 350 };
349 $('#jqxgrid').jqxGrid('addrow', null, row); 351 $('#jqxgrid').jqxGrid('addrow', null, row);
350 $("#popupWindow").jqxWindow('hide'); 352 $("#popupWindow").jqxWindow('hide');
351 location.reload( true ); // reload ourself.
352 }); 353 });
353 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); 354 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme });
354 // update the edited row when the user clicks the 'Save' button. 355 // update the edited row when the user clicks the 'Save' button.
355 $("#Save").click(function () { 356 $("#Save").click(function () {
356 var rowID = -1; 357 var row, rowID = -1;
357 if (editrow >= 0) { 358 if (editrow >= 0) {
358 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); 359 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
359 } 360 }
360 var row = { 361 row = {
361 record: rowID, 362 record: rowID,
362 name: $("#name").val(), 363 name: $("#name").val(),
363 alpha: parseFloat($("#alpha").jqxNumberInput('decimal')), 364 alpha: parseFloat($("#alpha").jqxNumberInput('decimal')),
364 beta: parseFloat($("#beta").jqxNumberInput('decimal')), 365 beta: parseFloat($("#beta").jqxNumberInput('decimal')),
365 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')), 366 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')),
381 }; 382 };
382 if (editrow >= 0) { 383 if (editrow >= 0) {
383 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 384 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
384 } else { 385 } else {
385 $('#jqxgrid').jqxGrid('addrow', null, row); 386 $('#jqxgrid').jqxGrid('addrow', null, row);
386 location.reload( true ); // reload ourself.
387 } 387 }
388 $("#popupWindow").jqxWindow('hide'); 388 $("#popupWindow").jqxWindow('hide');
389 }); 389 });
390 createDelElements(); 390 createDelElements();
391 }); 391 });

mercurial