|
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_yeasts.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: 'form', type: 'string' }, |
|
56 { name: 'amount', type: 'float' }, |
|
57 { name: 'amount_is_weight', type: 'bool' }, |
|
58 { name: 'laboratory', type: 'string' }, |
|
59 { name: 'product_id', type: 'string' }, |
|
60 { name: 'min_temperature', type: 'number' }, |
|
61 { name: 'max_temperature', type: 'number' }, |
|
62 { name: 'flocculation', type: 'string' }, |
|
63 { name: 'attenuation', type: 'float' }, |
|
64 { name: 'notes', type: 'string' }, |
|
65 { name: 'best_for', type: 'string' }, |
|
66 { name: 'times_cultured', type: 'number' }, |
|
67 { name: 'max_reuse', type: 'number' }, |
|
68 { name: 'add_to_secondary', type: 'bool' }, |
|
69 { name: 'inventory', type: 'float' }, |
|
70 { name: 'cost', type: 'float' }, |
|
71 { name: 'production_date', type: 'string' }, |
|
72 { name: 'tht_date', type: 'string' } |
|
73 ], |
|
74 id: 'record', |
|
75 url: url, |
|
76 deleterow: function (rowid, commit) { |
|
77 // synchronize with the server - send delete command |
|
78 var data = "delete=true&" + $.param({ record: rowid }); |
|
79 $.ajax({ |
|
80 dataType: 'json', |
|
81 url: url, |
|
82 cache: false, |
|
83 data: data, |
|
84 success: function (data, status, xhr) { |
|
85 // delete command is executed. |
|
86 commit(true); |
|
87 }, |
|
88 error: function (jqXHR, textStatus, errorThrown) { |
|
89 commit(false); |
|
90 } |
|
91 }); |
|
92 }, |
|
93 addrow: function (rowid, rowdata, position, commit) { |
|
94 var data = "insert=true&" + $.param(rowdata); |
|
95 $.ajax({ |
|
96 dataType: 'json', |
|
97 url: url, |
|
98 cache: false, |
|
99 data: data, |
|
100 success: function (data, status, xhr) { |
|
101 commit(true); |
|
102 }, |
|
103 error: function(jqXHR, textStatus, errorThrown) { |
|
104 commit(false); |
|
105 } |
|
106 }); |
|
107 }, |
|
108 updaterow: function (rowid, rowdata, commit) { |
|
109 var data = "update=true&" + $.param(rowdata); |
|
110 $.ajax({ |
|
111 dataType: 'json', |
|
112 url: url, |
|
113 cache: false, |
|
114 data: data, |
|
115 success: function (data, status, xhr) { |
|
116 // update command is executed. |
|
117 commit(true); |
|
118 }, |
|
119 error: function(jqXHR, textStatus, errorThrown) { |
|
120 commit(false); |
|
121 } |
|
122 }); |
|
123 } |
|
124 }; |
|
125 var srcType = [ "Ale", "Lager", "Wheat", "Wine", "Champagne" ]; |
|
126 var srcForm = [ "Liquid", "Dry", "Slant", "Culture", "Bottle", "Frozen" ]; |
|
127 var srcFlocculation = [ "Low", "Medium", "High", "Very High" ]; |
|
128 // initialize the input fields. |
|
129 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
130 $("#laboratory").jqxInput({ theme: theme, width: 150, height: 23 }); |
|
131 $("#product_id").jqxInput({ theme: theme, width: 120, height: 23 }); |
|
132 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 170 }); |
|
133 $("#form").jqxDropDownList({ theme: theme, source: srcForm, selectedIndex: 0, width: 90, height: 23, dropDownHeight: 195 }); |
|
134 //$("#amount").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
135 //$("#amount_is_weight").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
136 |
|
137 $("#notes").jqxInput({ theme: theme, width: 640, height: 120 }); |
|
138 $("#best_for").jqxInput({ theme: theme, width: 640, height: 23 }); |
|
139 $("#inventory").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
140 $("#production_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); |
|
141 |
|
142 $("#min_temperature").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, max: 35, decimalDigits: 0, spinButtons: true }); |
|
143 $("#max_temperature").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, max: 35, decimalDigits: 0, spinButtons: true }); |
|
144 $("#flocculation").jqxDropDownList({ theme: theme, source: srcFlocculation, width: 90, height: 23, dropDownHeight: 130 }); |
|
145 $("#attenuation").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 50, max: 100, decimalDigits: 1, spinButtons: true }); |
|
146 |
|
147 //$("#times_cultured").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, max: 10, decimalDigits: 0, spinButtons: true }); |
|
148 $("#max_reuse").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, max: 10, decimalDigits: 0, spinButtons: true }); |
|
149 //$("#add_to_secondary").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
150 $("#cost").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); |
|
151 $("#tht_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); |
|
152 |
|
153 var dataAdapter = new $.jqx.dataAdapter(source); |
|
154 var editrow = -1; |
|
155 // initialize jqxGrid |
|
156 $("#jqxgrid").jqxGrid({ |
|
157 width: 1280, |
|
158 height: 630, |
|
159 source: dataAdapter, |
|
160 theme: theme, |
|
161 showstatusbar: true, |
|
162 localization: getLocalization(), |
|
163 renderstatusbar: function (statusbar) { |
|
164 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
165 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>"); |
|
166 container.append(addButton); |
|
167 statusbar.append(container); |
|
168 addButton.jqxButton({ width: 60, height: 20 }); |
|
169 // add new row. |
|
170 addButton.click(function (event) { |
|
171 editrow = -1; |
|
172 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
173 $("#name").val(''); |
|
174 $("#laboratory").val(''); |
|
175 $("#product_id").val(''); |
|
176 $("#type").val('Ale'); |
|
177 $("#form").val('Liquid'); |
|
178 $("#amount").val('0.0'); |
|
179 $("#amount_is_weight").val('false'); |
|
180 $("#min_temperature").val(''); |
|
181 $("#max_temperature").val(''); |
|
182 $("#flocculation").val('Low'); |
|
183 $("#attenuation").val('75.0'); |
|
184 $("#notes").val(''); |
|
185 $("#best_for").val(''); |
|
186 $("#times_cultured").val(''); |
|
187 $("#max_reuse").val(''); |
|
188 $("#add_to_secondary").val('false'); |
|
189 $("#inventory").val(''); |
|
190 $("#cost").val(''); |
|
191 $("#production_date").val(''); |
|
192 $("#tht_date").val(''); |
|
193 $("#popupWindow").jqxWindow('open'); |
|
194 }); |
|
195 }, |
|
196 filterable: true, |
|
197 filtermode: 'excel', |
|
198 columns: [ |
|
199 { text: 'Gist naam', datafield: 'name', width: 250 }, |
|
200 { text: 'Laboratorium', datafield: 'laboratory', width: 150 }, |
|
201 { text: 'Product ID', datafield: 'product_id', width: 120 }, |
|
202 { text: 'Type', datafield: 'type', width: 90 }, |
|
203 { text: 'Vorm', datafield: 'form', width: 90 }, |
|
204 { text: 'Voorraad', datafield: 'inventory', width: 70, cellsalign: 'right' }, |
|
205 { text: 'Prijs', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' }, |
|
206 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { |
|
207 return "Edit"; |
|
208 }, buttonclick: function (row) { |
|
209 // open the popup window when the user clicks a button. |
|
210 editrow = row; |
|
211 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
212 // get the clicked row's data and initialize the input fields. |
|
213 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
|
214 $("#name").val(dataRecord.name); |
|
215 $("#laboratory").val(dataRecord.laboratory); |
|
216 $("#product_id").val(dataRecord.product_id); |
|
217 $("#type").val(dataRecord.type); |
|
218 $("#form").val(dataRecord.form); |
|
219 $("#amount").val(dataRecord.amount); |
|
220 $("#amount_is_weight").val(dataRecord.amount_is_weight); |
|
221 $("#min_temperature").val(dataRecord.min_temperature); |
|
222 $("#max_temperature").val(dataRecord.max_temperature); |
|
223 $("#flocculation").val(dataRecord.flocculation); |
|
224 $("#attenuation").val(dataRecord.attenuation); |
|
225 $("#notes").val(dataRecord.notes); |
|
226 $("#best_for").val(dataRecord.best_for); |
|
227 $("#times_cultured").val(dataRecord.times_cultured); |
|
228 $("#max_reuse").val(dataRecord.max_reuse); |
|
229 $("#add_to_secondary").val(dataRecord.add_to_secondary); |
|
230 $("#inventory").val(dataRecord.inventory); |
|
231 $("#cost").val(dataRecord.cost); |
|
232 $("#production_date").val(dataRecord.production_date); |
|
233 $("#tht_date").val(dataRecord.tht_date); |
|
234 // show the popup window. |
|
235 $("#popupWindow").jqxWindow('open'); |
|
236 } |
|
237 } |
|
238 ] |
|
239 }); |
|
240 // initialize the popup window and buttons. |
|
241 $("#popupWindow").jqxWindow({ |
|
242 width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 |
|
243 }); |
|
244 $("#popupWindow").on('open', function () { |
|
245 $("#name").jqxInput('selectAll'); |
|
246 }); |
|
247 $("#Delete").jqxButton({ theme: theme }); |
|
248 $("#Delete").click(function () { |
|
249 if (editrow >= 0) { |
|
250 // Open a popup to confirm this action. |
|
251 $('#eventWindow').jqxWindow('open'); |
|
252 $("#delOk").click(function () { |
|
253 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
254 $("#jqxgrid").jqxGrid('deleterow', rowID); |
|
255 }); |
|
256 } |
|
257 $("#popupWindow").jqxWindow('hide'); |
|
258 }); |
|
259 $("#Cancel").jqxButton({ theme: theme }); |
|
260 $("#Save").jqxButton({ theme: theme }); |
|
261 // update the edited row when the user clicks the 'Save' button. |
|
262 $("#Save").click(function () { |
|
263 if (editrow >= 0) { |
|
264 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
265 var row = { |
|
266 record: rowID, |
|
267 name: $("#name").val(), |
|
268 type: $("#type").val(), |
|
269 form: $("#form").val(), |
|
270 amount: parseFloat($("#amount").jqxNumberInput('decimal')), |
|
271 amount_is_weight: $("#amount_is_weight").val(), |
|
272 laboratory: $("#laboratory").val(), |
|
273 product_id: $("#product_id").val(), |
|
274 min_temperature: parseInt($("#min_temperature").jqxNumberInput('decimal')), |
|
275 max_temperature: parseInt($("#max_temperature").jqxNumberInput('decimal')), |
|
276 flocculation: $("#flocculation").val(), |
|
277 attenuation: parseFloat($("#attenuation").jqxNumberInput('decimal')), |
|
278 notes: $("#notes").val(), |
|
279 best_for: $("#best_for").val(), |
|
280 times_recultured: parseInt($("#times_cultured").jqxNumberInput('decimal')), |
|
281 max_reuse: parseInt($("#max_reuse").jqxNumberInput('decimal')), |
|
282 add_to_secondary: $("#add_to_secondary").val(), |
|
283 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), |
|
284 cost: parseFloat($("#cost").jqxNumberInput('decimal')), |
|
285 production_date: $("#production_date").val(), |
|
286 tht_date: $("#tht_date").val() |
|
287 }; |
|
288 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
289 $("#popupWindow").jqxWindow('hide'); |
|
290 } else { |
|
291 // Insert a record |
|
292 var newrow = { |
|
293 record: -1, |
|
294 name: $("#name").val(), |
|
295 type: $("#type").val(), |
|
296 form: $("#form").val(), |
|
297 amount: parseFloat($("#amount").jqxNumberInput('decimal')), |
|
298 amount_is_weight: $("#amount_is_weight").val(), |
|
299 laboratory: $("#laboratory").val(), |
|
300 product_id: $("#product_id").val(), |
|
301 min_temperature: parseInt($("#min_temperature").jqxNumberInput('decimal')), |
|
302 max_temperature: parseInt($("#max_temperature").jqxNumberInput('decimal')), |
|
303 flocculation: $("#flocculation").val(), |
|
304 attenuation: parseFloat($("#attenuation").jqxNumberInput('decimal')), |
|
305 notes: $("#notes").val(), |
|
306 best_for: $("#best_for").val(), |
|
307 times_recultured: parseInt($("#times_cultured").jqxNumberInput('decimal')), |
|
308 max_reuse: parseInt($("#max_reuse").jqxNumberInput('decimal')), |
|
309 add_to_secondary: $("#add_to_secondary").val(), |
|
310 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), |
|
311 cost: parseFloat($("#cost").jqxNumberInput('decimal')), |
|
312 production_date: $("#production_date").val(), |
|
313 tht_date: $("#tht_date").val() |
|
314 }; |
|
315 $('#jqxgrid').jqxGrid('addrow', null, newrow); |
|
316 $("#popupWindow").jqxWindow('hide'); |
|
317 } |
|
318 }); |
|
319 createDelElements(); |
|
320 }); |
|
321 |