|
1 /***************************************************************************** |
|
2 * Copyright (C) 2014-2018 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BrewCloud |
|
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 function createDelElements() { |
|
25 $('#eventWindow').jqxWindow({ |
|
26 theme: theme, |
|
27 position: { x: 490, y: 210 }, |
|
28 width: 300, |
|
29 height: 145, |
|
30 resizable: false, |
|
31 isModal: true, |
|
32 modalOpacity: 0.4, |
|
33 okButton: $('#delOk'), |
|
34 cancelButton: $('#delCancel'), |
|
35 initContent: function () { |
|
36 $('#delOk').jqxButton({ width: '65px', theme: theme }); |
|
37 $('#delCancel').jqxButton({ width: '65px', theme: theme }); |
|
38 $('#delCancel').focus(); |
|
39 } |
|
40 }); |
|
41 $('#eventWindow').jqxWindow('hide'); |
|
42 } |
|
43 |
|
44 |
|
45 $(document).ready(function () { |
|
46 var url = "includes/db_inventory_fermentables.php"; |
|
47 // prepare the data |
|
48 var source = { |
|
49 datatype: "json", |
|
50 cache: false, |
|
51 datafields: [ |
|
52 { name: 'record', type: 'number' }, |
|
53 { name: 'name', type: 'string' }, |
|
54 { name: 'type', type: 'string' }, |
|
55 { name: 'yield', type: 'float' }, |
|
56 { name: 'color', type: 'float' }, |
|
57 { name: 'add_after_boil', type: 'bool' }, |
|
58 { name: 'origin', type: 'string' }, |
|
59 { name: 'supplier', type: 'string' }, |
|
60 { name: 'notes', type: 'string' }, |
|
61 { name: 'coarse_fine_diff', type: 'float' }, |
|
62 { name: 'moisture', type: 'float' }, |
|
63 { name: 'diastatic_power', type: 'float' }, |
|
64 { name: 'protein', type: 'float' }, |
|
65 { name: 'max_in_batch', type: 'float' }, |
|
66 { name: 'recommend_mash', type: 'bool' }, |
|
67 { name: 'ibu_gal_per_lb', type: 'float' }, |
|
68 { name: 'always_on_stock', type: 'bool' }, |
|
69 { name: 'di_ph', type: 'float' }, |
|
70 { name: 'acid_to_ph_57', type: 'float' }, |
|
71 { name: 'graintype', type: 'string' }, |
|
72 { name: 'inventory', type: 'float' }, |
|
73 { name: 'cost', type: 'float' }, |
|
74 { name: 'production_date', type: 'string' }, |
|
75 { name: 'tht_date', type: 'string' }, |
|
76 { name: 'supplier_rec', type: 'float' } |
|
77 ], |
|
78 id: 'record', |
|
79 url: url, |
|
80 deleterow: function (rowid, commit) { |
|
81 // synchronize with the server - send delete command |
|
82 var data = "delete=true&" + $.param({ record: rowid }); |
|
83 $.ajax({ |
|
84 dataType: 'json', |
|
85 url: url, |
|
86 cache: false, |
|
87 data: data, |
|
88 success: function (data, status, xhr) { |
|
89 // delete command is executed. |
|
90 commit(true); |
|
91 }, |
|
92 error: function (jqXHR, textStatus, errorThrown) { |
|
93 commit(false); |
|
94 } |
|
95 }); |
|
96 }, |
|
97 addrow: function (rowid, rowdata, position, commit) { |
|
98 var data = "insert=true&" + $.param(rowdata); |
|
99 $.ajax({ |
|
100 dataType: 'json', |
|
101 url: url, |
|
102 cache: false, |
|
103 data: data, |
|
104 success: function (data, status, xhr) { |
|
105 commit(true); |
|
106 }, |
|
107 error: function(jqXHR, textStatus, errorThrown) { |
|
108 commit(false); |
|
109 } |
|
110 }); |
|
111 }, |
|
112 updaterow: function (rowid, rowdata, commit) { |
|
113 var data = "update=true&" + $.param(rowdata); |
|
114 $.ajax({ |
|
115 dataType: 'json', |
|
116 url: url, |
|
117 cache: false, |
|
118 data: data, |
|
119 success: function (data, status, xhr) { |
|
120 // update command is executed. |
|
121 commit(true); |
|
122 }, |
|
123 error: function(jqXHR, textStatus, errorThrown) { |
|
124 commit(false); |
|
125 } |
|
126 }); |
|
127 } |
|
128 }; |
|
129 var srcType = [ "Grain", "Sugar", "Extract", "Dry Extract", "Adjunct" ]; |
|
130 // initialize the input fields. |
|
131 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
132 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 130 }); |
|
133 $("#yield").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
134 $("#color").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
135 $("#add_after_boil").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
136 $("#origin").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
137 $("#supplier").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
138 $("#notes").jqxInput({ theme: theme, width: 640, height: 48 }); |
|
139 $("#coarse_fine_diff").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
140 $("#moisture").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
141 $("#diastatic_power").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
142 $("#protein").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
143 $("#max_in_batch").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
144 $("#recommend_mash").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
145 $("#ibu_gal_per_lb").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
146 $("#always_on_stock").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
147 $("#di_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
148 $("#acid_to_ph_57").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
149 |
|
150 $("#graintype").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
151 |
|
152 $("#inventory").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
153 $("#production_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); |
|
154 |
|
155 $("#cost").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); |
|
156 $("#tht_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); |
|
157 $("#supplier_rec").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
158 // supplier_rec |
|
159 var dataAdapter = new $.jqx.dataAdapter(source); |
|
160 var editrow = -1; |
|
161 // initialize jqxGrid |
|
162 $("#jqxgrid").jqxGrid({ |
|
163 width: 1280, |
|
164 height: 630, |
|
165 source: dataAdapter, |
|
166 theme: theme, |
|
167 showstatusbar: true, |
|
168 localization: getLocalization(), |
|
169 renderstatusbar: function (statusbar) { |
|
170 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
171 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;'>Add</span></div>"); |
|
172 container.append(addButton); |
|
173 statusbar.append(container); |
|
174 addButton.jqxButton({ width: 60, height: 20 }); |
|
175 // add new row. |
|
176 addButton.click(function (event) { |
|
177 editrow = -1; |
|
178 $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); |
|
179 $("#name").val(''); |
|
180 $("#type").val('Grain'); |
|
181 $("#origin").val(''); |
|
182 $("#supplier").val(''); |
|
183 $("#notes").val(''); |
|
184 $("#coarse_fine_diff").val(''); |
|
185 $("#moisture").val(''); |
|
186 $("#diastatic_power").val(''); |
|
187 $("#protein").val(''); |
|
188 $("#max_in_batch").val(''); |
|
189 $("#recommend_mash").val(''); |
|
190 $("#ibu_gal_per_lb").val(''); |
|
191 $("#always_on_stock").val(''); |
|
192 $("#di_ph").val(''); |
|
193 $("#acid_to_ph_57").val(''); |
|
194 $("#graintype").val(''); |
|
195 $("#inventory").val(''); |
|
196 $("#cost").val(''); |
|
197 $("#production_date").val(''); |
|
198 $("#tht_date").val(''); |
|
199 $("#supplier_rec").val(''); |
|
200 $("#popupWindow").jqxWindow('open'); |
|
201 }); |
|
202 }, |
|
203 filterable: true, |
|
204 filtermode: 'excel', |
|
205 columns: [ |
|
206 { text: 'Vergistbaar product', datafield: 'name', width: 250 }, |
|
207 { text: 'Soort', datafield: 'type', width: 90 }, |
|
208 { text: 'Herkomst', datafield: 'origin', width: 150 }, |
|
209 { text: 'Producent', datafield: 'supplier', width: 150 }, |
|
210 { text: 'Kleur', datafield: 'color', width: 70, cellsalign: 'right' }, |
|
211 { text: 'Opbrengst', datafield: 'yield', width: 70, cellsalign: 'right' }, |
|
212 { text: 'Inv.', datafield: 'inventory', width: 70, cellsalign: 'right' }, |
|
213 { text: 'Prijs', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' }, |
|
214 { text: 'Edit', datafield: 'Edit', width: 120, columntype: 'button', cellsrenderer: function () { |
|
215 return "Edit"; |
|
216 }, buttonclick: function (row) { |
|
217 // open the popup window when the user clicks a button. |
|
218 editrow = row; |
|
219 $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); |
|
220 // get the clicked row's data and initialize the input fields. |
|
221 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
|
222 $("#name").val(dataRecord.name); |
|
223 $("#type").val(dataRecord.type); |
|
224 $("#yield").val(dataRecord.yield); |
|
225 $("#color").val(dataRecord.color); |
|
226 $("#add_after_boil").val(dataRecord.add_after_boil); |
|
227 $("#origin").val(dataRecord.origin); |
|
228 $("#supplier").val(dataRecord.supplier); |
|
229 $("#notes").val(dataRecord.notes); |
|
230 $("#coarse_fine_diff").val(dataRecord.coarse_fine_diff); |
|
231 $("#moisture").val(dataRecord.moisture); |
|
232 $("#diastatic_power").val(dataRecord.diastatic_power); |
|
233 $("#protein").val(dataRecord.protein); |
|
234 $("#max_in_batch").val(dataRecord.max_in_batch); |
|
235 $("#recommend_mash").val(dataRecord.recommend_mash); |
|
236 $("#ibu_gal_per_lb").val(dataRecord.ibu_gal_per_lb); |
|
237 $("#always_on_stock").val(dataRecord.always_on_stock); |
|
238 $("#di_ph").val(dataRecord.di_ph); |
|
239 $("#acid_to_ph_57").val(dataRecord.acid_to_ph_57); |
|
240 $("#graintype").val(dataRecord.graintype); |
|
241 $("#inventory").val(dataRecord.inventory); |
|
242 $("#cost").val(dataRecord.cost); |
|
243 $("#production_date").val(dataRecord.production_date); |
|
244 $("#tht_date").val(dataRecord.tht_date); |
|
245 $("#supplier_rec").val(dataRecord.supplier_rec); |
|
246 // show the popup window. |
|
247 $("#popupWindow").jqxWindow('open'); |
|
248 } |
|
249 } |
|
250 ] |
|
251 }); |
|
252 // initialize the popup window and buttons. |
|
253 $("#popupWindow").jqxWindow({ |
|
254 width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 |
|
255 }); |
|
256 $("#popupWindow").on('open', function () { |
|
257 $("#name").jqxInput('selectAll'); |
|
258 }); |
|
259 $("#Delete").jqxButton({ theme: theme }); |
|
260 $("#Delete").click(function () { |
|
261 if (editrow >= 0) { |
|
262 // Open a popup to confirm this action. |
|
263 $('#eventWindow').jqxWindow('open'); |
|
264 $("#delOk").click(function () { |
|
265 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
266 $("#jqxgrid").jqxGrid('deleterow', rowID); |
|
267 }); |
|
268 } |
|
269 $("#popupWindow").jqxWindow('hide'); |
|
270 }); |
|
271 $("#Cancel").jqxButton({ theme: theme }); |
|
272 $("#Save").jqxButton({ theme: theme }); |
|
273 // update the edited row when the user clicks the 'Save' button. |
|
274 $("#Save").click(function () { |
|
275 if (editrow >= 0) { |
|
276 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
277 var row = { |
|
278 record: rowID, |
|
279 name: $("#name").val(), |
|
280 type: $("#type").val(), |
|
281 yield: parseFloat($("#yield").jqxNumberInput('decimal')), |
|
282 color: parseFloat($("#color").jqxNumberInput('decimal')), |
|
283 add_after_boil: $("#add_after_boil").val(), |
|
284 origin: $("#origin").val(), |
|
285 supplier: $("#supplier").val(), |
|
286 notes: $("#notes").val(), |
|
287 coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), |
|
288 moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), |
|
289 diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), |
|
290 protein: parseFloat($("#protein").jqxNumberInput('decimal')), |
|
291 max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), |
|
292 recommend_mash: $("#recommend_mash").val(), |
|
293 ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), |
|
294 always_on_stock: $("#always_on_stock").val(), |
|
295 di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), |
|
296 acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), |
|
297 graintype: $("#graintype").val(), |
|
298 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), |
|
299 cost: parseFloat($("#cost").jqxNumberInput('decimal')), |
|
300 production_date: $("#production_date").val(), |
|
301 tht_date: $("#tht_date").val(), |
|
302 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) |
|
303 }; |
|
304 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
305 $("#popupWindow").jqxWindow('hide'); |
|
306 } else { |
|
307 // Insert a record |
|
308 var newrow = { |
|
309 record: -1, |
|
310 name: $("#name").val(), |
|
311 type: $("#type").val(), |
|
312 yield: parseFloat($("#yield").jqxNumberInput('decimal')), |
|
313 color: parseFloat($("#color").jqxNumberInput('decimal')), |
|
314 add_after_boil: $("#add_after_boil").val(), |
|
315 origin: $("#origin").val(), |
|
316 supplier: $("#supplier").val(), |
|
317 notes: $("#notes").val(), |
|
318 coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), |
|
319 moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), |
|
320 diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), |
|
321 protein: parseFloat($("#protein").jqxNumberInput('decimal')), |
|
322 max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), |
|
323 recommend_mash: $("#recommend_mash").val(), |
|
324 ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), |
|
325 always_on_stock: $("#always_on_stock").val(), |
|
326 di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), |
|
327 acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), |
|
328 graintype: $("#graintype").val(), |
|
329 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), |
|
330 cost: parseFloat($("#cost").jqxNumberInput('decimal')), |
|
331 production_date: $("#production_date").val(), |
|
332 tht_date: $("#tht_date").val(), |
|
333 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) |
|
334 }; |
|
335 $('#jqxgrid').jqxGrid('addrow', null, newrow); |
|
336 $("#popupWindow").jqxWindow('hide'); |
|
337 } |
|
338 }); |
|
339 createDelElements(); |
|
340 }); |
|
341 |