Mon, 19 Nov 2018 20:21:56 +0100
Prepare for production brews databases
11 | 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, | |
34 | 29 | height: 175, |
11 | 30 | resizable: false, |
31 | isModal: true, | |
32 | modalOpacity: 0.4, | |
33 | okButton: $('#delOk'), | |
34 | cancelButton: $('#delCancel'), | |
35 | initContent: function () { | |
51 | 36 | $('#delOk').jqxButton({ template: "danger", width: '65px', theme: theme }); |
37 | $('#delCancel').jqxButton({ template: "success", width: '65px', theme: theme }); | |
11 | 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' }, | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
75 | { name: 'tht_date', type: 'string' } |
11 | 76 | ], |
77 | id: 'record', | |
78 | url: url, | |
79 | deleterow: function (rowid, commit) { | |
80 | // synchronize with the server - send delete command | |
81 | var data = "delete=true&" + $.param({ record: rowid }); | |
82 | $.ajax({ | |
83 | dataType: 'json', | |
84 | url: url, | |
85 | cache: false, | |
86 | data: data, | |
87 | success: function (data, status, xhr) { | |
88 | // delete command is executed. | |
89 | commit(true); | |
90 | }, | |
91 | error: function (jqXHR, textStatus, errorThrown) { | |
92 | commit(false); | |
93 | } | |
94 | }); | |
95 | }, | |
96 | addrow: function (rowid, rowdata, position, commit) { | |
97 | var data = "insert=true&" + $.param(rowdata); | |
98 | $.ajax({ | |
99 | dataType: 'json', | |
100 | url: url, | |
101 | cache: false, | |
102 | data: data, | |
103 | success: function (data, status, xhr) { | |
104 | commit(true); | |
105 | }, | |
106 | error: function(jqXHR, textStatus, errorThrown) { | |
107 | commit(false); | |
108 | } | |
109 | }); | |
110 | }, | |
111 | updaterow: function (rowid, rowdata, commit) { | |
112 | var data = "update=true&" + $.param(rowdata); | |
113 | $.ajax({ | |
114 | dataType: 'json', | |
115 | url: url, | |
116 | cache: false, | |
117 | data: data, | |
118 | success: function (data, status, xhr) { | |
119 | // update command is executed. | |
120 | commit(true); | |
121 | }, | |
122 | error: function(jqXHR, textStatus, errorThrown) { | |
123 | commit(false); | |
124 | } | |
125 | }); | |
126 | } | |
127 | }; | |
128 | var srcType = [ "Grain", "Sugar", "Extract", "Dry Extract", "Adjunct" ]; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
129 | var srcGraintype = [ "Base", "Crystal", "Special", "Roast", "Kilned", "No malt" ]; |
11 | 130 | // initialize the input fields. |
131 | $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
132 | $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 100, height: 23, dropDownHeight: 156 }); |
11 | 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 }); | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
138 | $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); |
11 | 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 }); | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
149 | $("#graintype").jqxDropDownList({ theme: theme, source: srcGraintype, width: 100, height: 23, dropDownHeight: 185 }); |
11 | 150 | |
151 | $("#inventory").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); | |
152 | $("#production_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); | |
153 | ||
154 | $("#cost").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); | |
155 | $("#tht_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); | |
156 | var dataAdapter = new $.jqx.dataAdapter(source); | |
157 | var editrow = -1; | |
158 | // initialize jqxGrid | |
159 | $("#jqxgrid").jqxGrid({ | |
160 | width: 1280, | |
161 | height: 630, | |
162 | source: dataAdapter, | |
163 | theme: theme, | |
164 | showstatusbar: true, | |
165 | localization: getLocalization(), | |
166 | renderstatusbar: function (statusbar) { | |
167 | var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); | |
34 | 168 | 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>"); |
11 | 169 | container.append(addButton); |
170 | statusbar.append(container); | |
34 | 171 | addButton.jqxButton({ theme: theme, width: 120, height: 20 }); |
11 | 172 | // add new row. |
173 | addButton.click(function (event) { | |
174 | editrow = -1; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
175 | $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
11 | 176 | $("#name").val(''); |
177 | $("#type").val('Grain'); | |
178 | $("#origin").val(''); | |
179 | $("#supplier").val(''); | |
180 | $("#notes").val(''); | |
181 | $("#coarse_fine_diff").val(''); | |
182 | $("#moisture").val(''); | |
183 | $("#diastatic_power").val(''); | |
184 | $("#protein").val(''); | |
185 | $("#max_in_batch").val(''); | |
186 | $("#recommend_mash").val(''); | |
187 | $("#ibu_gal_per_lb").val(''); | |
188 | $("#always_on_stock").val(''); | |
189 | $("#di_ph").val(''); | |
190 | $("#acid_to_ph_57").val(''); | |
191 | $("#graintype").val(''); | |
192 | $("#inventory").val(''); | |
193 | $("#cost").val(''); | |
194 | $("#production_date").val(''); | |
195 | $("#tht_date").val(''); | |
196 | $("#popupWindow").jqxWindow('open'); | |
197 | }); | |
198 | }, | |
199 | filterable: true, | |
200 | filtermode: 'excel', | |
201 | columns: [ | |
37
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
202 | { text: 'Producent', datafield: 'supplier', width: 200 }, |
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
203 | { text: 'Vergistbaar product', datafield: 'name' }, |
30
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
204 | { text: 'Soort', datafield: 'type', align: 'center', cellsalign: 'center', width: 90 }, |
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
205 | { text: 'Mout type', datafield: 'graintype', align: 'center', cellsalign: 'center', width: 90 }, |
11 | 206 | { text: 'Herkomst', datafield: 'origin', width: 150 }, |
30
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
207 | { text: 'Kleur', datafield: 'color', width: 70, align: 'right', cellsalign: 'right' }, |
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
208 | { text: 'Opbrengst', datafield: 'yield', width: 70, align: 'right', cellsalign: 'right', cellsformat: 'p1' }, |
34 | 209 | { text: 'Vooraad', datafield: 'inventory', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f3' }, |
210 | { text: 'Prijs', datafield: 'cost', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'c2' }, | |
211 | { text: 'Wijzig', datafield: 'Edit', width: 120, align: 'center', columntype: 'button', cellsrenderer: function () { | |
212 | return "Wijzig"; | |
11 | 213 | }, buttonclick: function (row) { |
214 | // open the popup window when the user clicks a button. | |
215 | editrow = row; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
216 | $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
11 | 217 | // get the clicked row's data and initialize the input fields. |
218 | var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); | |
219 | $("#name").val(dataRecord.name); | |
220 | $("#type").val(dataRecord.type); | |
221 | $("#yield").val(dataRecord.yield); | |
222 | $("#color").val(dataRecord.color); | |
223 | $("#add_after_boil").val(dataRecord.add_after_boil); | |
224 | $("#origin").val(dataRecord.origin); | |
225 | $("#supplier").val(dataRecord.supplier); | |
226 | $("#notes").val(dataRecord.notes); | |
227 | $("#coarse_fine_diff").val(dataRecord.coarse_fine_diff); | |
228 | $("#moisture").val(dataRecord.moisture); | |
229 | $("#diastatic_power").val(dataRecord.diastatic_power); | |
230 | $("#protein").val(dataRecord.protein); | |
231 | $("#max_in_batch").val(dataRecord.max_in_batch); | |
232 | $("#recommend_mash").val(dataRecord.recommend_mash); | |
233 | $("#ibu_gal_per_lb").val(dataRecord.ibu_gal_per_lb); | |
234 | $("#always_on_stock").val(dataRecord.always_on_stock); | |
235 | $("#di_ph").val(dataRecord.di_ph); | |
236 | $("#acid_to_ph_57").val(dataRecord.acid_to_ph_57); | |
237 | $("#graintype").val(dataRecord.graintype); | |
238 | $("#inventory").val(dataRecord.inventory); | |
239 | $("#cost").val(dataRecord.cost); | |
240 | $("#production_date").val(dataRecord.production_date); | |
241 | $("#tht_date").val(dataRecord.tht_date); | |
242 | // show the popup window. | |
243 | $("#popupWindow").jqxWindow('open'); | |
244 | } | |
245 | } | |
246 | ] | |
247 | }); | |
248 | // initialize the popup window and buttons. | |
249 | $("#popupWindow").jqxWindow({ | |
250 | width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 | |
251 | }); | |
252 | $("#popupWindow").on('open', function () { | |
253 | $("#name").jqxInput('selectAll'); | |
254 | }); | |
255 | $("#Delete").jqxButton({ theme: theme }); | |
256 | $("#Delete").click(function () { | |
257 | if (editrow >= 0) { | |
258 | // Open a popup to confirm this action. | |
259 | $('#eventWindow').jqxWindow('open'); | |
260 | $("#delOk").click(function () { | |
261 | var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); | |
262 | $("#jqxgrid").jqxGrid('deleterow', rowID); | |
263 | }); | |
264 | } | |
265 | $("#popupWindow").jqxWindow('hide'); | |
266 | }); | |
267 | $("#Cancel").jqxButton({ theme: theme }); | |
268 | $("#Save").jqxButton({ theme: theme }); | |
269 | // update the edited row when the user clicks the 'Save' button. | |
270 | $("#Save").click(function () { | |
271 | if (editrow >= 0) { | |
272 | var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); | |
273 | var row = { | |
274 | record: rowID, | |
275 | name: $("#name").val(), | |
276 | type: $("#type").val(), | |
277 | yield: parseFloat($("#yield").jqxNumberInput('decimal')), | |
278 | color: parseFloat($("#color").jqxNumberInput('decimal')), | |
279 | add_after_boil: $("#add_after_boil").val(), | |
280 | origin: $("#origin").val(), | |
281 | supplier: $("#supplier").val(), | |
282 | notes: $("#notes").val(), | |
283 | coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), | |
284 | moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), | |
285 | diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), | |
286 | protein: parseFloat($("#protein").jqxNumberInput('decimal')), | |
287 | max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), | |
288 | recommend_mash: $("#recommend_mash").val(), | |
289 | ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), | |
290 | always_on_stock: $("#always_on_stock").val(), | |
291 | di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), | |
292 | acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), | |
293 | graintype: $("#graintype").val(), | |
294 | inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), | |
295 | cost: parseFloat($("#cost").jqxNumberInput('decimal')), | |
296 | production_date: $("#production_date").val(), | |
297 | tht_date: $("#tht_date").val(), | |
298 | }; | |
299 | $('#jqxgrid').jqxGrid('updaterow', rowID, row); | |
300 | $("#popupWindow").jqxWindow('hide'); | |
301 | } else { | |
302 | // Insert a record | |
303 | var newrow = { | |
304 | record: -1, | |
305 | name: $("#name").val(), | |
306 | type: $("#type").val(), | |
307 | yield: parseFloat($("#yield").jqxNumberInput('decimal')), | |
308 | color: parseFloat($("#color").jqxNumberInput('decimal')), | |
309 | add_after_boil: $("#add_after_boil").val(), | |
310 | origin: $("#origin").val(), | |
311 | supplier: $("#supplier").val(), | |
312 | notes: $("#notes").val(), | |
313 | coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), | |
314 | moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), | |
315 | diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), | |
316 | protein: parseFloat($("#protein").jqxNumberInput('decimal')), | |
317 | max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), | |
318 | recommend_mash: $("#recommend_mash").val(), | |
319 | ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), | |
320 | always_on_stock: $("#always_on_stock").val(), | |
321 | di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), | |
322 | acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), | |
323 | graintype: $("#graintype").val(), | |
324 | inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), | |
325 | cost: parseFloat($("#cost").jqxNumberInput('decimal')), | |
326 | production_date: $("#production_date").val(), | |
327 | tht_date: $("#tht_date").val(), | |
328 | }; | |
329 | $('#jqxgrid').jqxGrid('addrow', null, newrow); | |
330 | $("#popupWindow").jqxWindow('hide'); | |
331 | } | |
332 | }); | |
333 | createDelElements(); | |
334 | }); | |
335 |