|
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_mash_profiles.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: 'grain_temp', type: 'float' }, |
|
55 { name: 'tun_temp', type: 'float' }, |
|
56 { name: 'sparge_temp', type: 'float' }, |
|
57 { name: 'ph', type: 'float' }, |
|
58 { name: 'tun_weight', type: 'float' }, |
|
59 { name: 'tun_specific_heat', type: 'float' }, |
|
60 { name: 'notes', type: 'string' }, |
|
61 { name: 'equip_adjust', type: 'bool' }, |
|
62 { name: 'steps', type: 'string' } |
|
63 ], |
|
64 id: 'record', |
|
65 url: url, |
|
66 deleterow: function (rowid, commit) { |
|
67 // synchronize with the server - send delete command |
|
68 var data = "delete=true&" + $.param({ record: rowid }); |
|
69 $.ajax({ |
|
70 dataType: 'json', |
|
71 url: url, |
|
72 cache: false, |
|
73 data: data, |
|
74 success: function (data, status, xhr) { |
|
75 // delete command is executed. |
|
76 commit(true); |
|
77 }, |
|
78 error: function (jqXHR, textStatus, errorThrown) { |
|
79 commit(false); |
|
80 } |
|
81 }); |
|
82 }, |
|
83 addrow: function (rowid, rowdata, position, commit) { |
|
84 var data = "insert=true&" + $.param(rowdata); |
|
85 $.ajax({ |
|
86 dataType: 'json', |
|
87 url: url, |
|
88 cache: false, |
|
89 data: data, |
|
90 success: function (data, status, xhr) { |
|
91 commit(true); |
|
92 }, |
|
93 error: function(jqXHR, textStatus, errorThrown) { |
|
94 commit(false); |
|
95 } |
|
96 }); |
|
97 }, |
|
98 updaterow: function (rowid, rowdata, commit) { |
|
99 var data = "update=true&" + $.param(rowdata); |
|
100 $.ajax({ |
|
101 dataType: 'json', |
|
102 url: url, |
|
103 cache: false, |
|
104 data: data, |
|
105 success: function (data, status, xhr) { |
|
106 // update command is executed. |
|
107 commit(true); |
|
108 }, |
|
109 error: function(jqXHR, textStatus, errorThrown) { |
|
110 commit(false); |
|
111 } |
|
112 }); |
|
113 } |
|
114 }; |
|
115 // initialize the input fields. |
|
116 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
117 $("#grain_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
118 $("#tun_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
119 $("#sparge_temp").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
120 $("#ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
121 $("#tun_weight").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
122 $("#tun_specific_heat").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); |
|
123 |
|
124 $("#notes").jqxInput({ theme: theme, width: 640, height: 100 }); |
|
125 $("#equip_adjust").jqxCheckBox({ theme: theme, width: 120, height: 23 }); |
|
126 var dataAdapter = new $.jqx.dataAdapter(source); |
|
127 var editrow = -1; |
|
128 // initialize jqxGrid |
|
129 $("#jqxgrid").jqxGrid({ |
|
130 width: 1280, |
|
131 height: 630, |
|
132 source: dataAdapter, |
|
133 theme: theme, |
|
134 showstatusbar: true, |
|
135 localization: getLocalization(), |
|
136 renderstatusbar: function (statusbar) { |
|
137 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
138 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>"); |
|
139 container.append(addButton); |
|
140 statusbar.append(container); |
|
141 addButton.jqxButton({ width: 60, height: 20 }); |
|
142 // add new row. |
|
143 addButton.click(function (event) { |
|
144 editrow = -1; |
|
145 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
146 $("#name").val(''); |
|
147 $("#grain_temp").val(''); |
|
148 $("#tun_temp").val(''); |
|
149 $("#sparge_temp").val(''); |
|
150 $("#ph").val(''); |
|
151 $("#tun_weight").val(''); |
|
152 $("#tun_specific_heat").val(''); |
|
153 $("#equip_adjust").val(''); |
|
154 $("#notes").val(''); |
|
155 $("#popupWindow").jqxWindow('open'); |
|
156 }); |
|
157 }, |
|
158 filterable: true, |
|
159 filtermode: 'excel', |
|
160 columns: [ |
|
161 { text: 'Maish schema', datafield: 'name', width: 250 }, |
|
162 { text: 'Notes', datafield: 'notes', width: 450 }, |
|
163 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { |
|
164 return "Edit"; |
|
165 }, buttonclick: function (row) { |
|
166 // open the popup window when the user clicks a button. |
|
167 editrow = row; |
|
168 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } }); |
|
169 // get the clicked row's data and initialize the input fields. |
|
170 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
|
171 $("#name").val(dataRecord.name); |
|
172 $("#grain_temp").val(dataRecord.grain_temp); |
|
173 $("#tun_temp").val(dataRecord.tun_temp); |
|
174 $("#sparge_temp").val(dataRecord.sparge_temp); |
|
175 $("#ph").val(dataRecord.ph); |
|
176 $("#tun_weight").val(dataRecord.tun_weight); |
|
177 $("#tun_specific_heat").val(dataRecord.tun_specific_heat); |
|
178 $("#equip_adjust").val(dataRecord.equip_adjust); |
|
179 $("#notes").val(dataRecord.notes); |
|
180 // show the popup window. |
|
181 $("#popupWindow").jqxWindow('open'); |
|
182 } |
|
183 } |
|
184 ] |
|
185 }); |
|
186 // initialize the popup window and buttons. |
|
187 $("#popupWindow").jqxWindow({ |
|
188 width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 |
|
189 }); |
|
190 $("#popupWindow").on('open', function () { |
|
191 $("#name").jqxInput('selectAll'); |
|
192 }); |
|
193 $("#Delete").jqxButton({ theme: theme }); |
|
194 $("#Delete").click(function () { |
|
195 if (editrow >= 0) { |
|
196 // Open a popup to confirm this action. |
|
197 $('#eventWindow').jqxWindow('open'); |
|
198 $("#delOk").click(function () { |
|
199 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
200 $("#jqxgrid").jqxGrid('deleterow', rowID); |
|
201 }); |
|
202 } |
|
203 $("#popupWindow").jqxWindow('hide'); |
|
204 }); |
|
205 $("#Cancel").jqxButton({ theme: theme }); |
|
206 $("#Save").jqxButton({ theme: theme }); |
|
207 // update the edited row when the user clicks the 'Save' button. |
|
208 $("#Save").click(function () { |
|
209 if (editrow >= 0) { |
|
210 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
211 var row = { |
|
212 record: rowID, |
|
213 name: $("#name").val(), |
|
214 grain_temp: parseFloat($("#grain_temp").jqxNumberInput('decimal')), |
|
215 tun_temp: parseFloat($("#tun_temp").jqxNumberInput('decimal')), |
|
216 sparge_temp: parseFloat($("#sparge_temp").jqxNumberInput('decimal')), |
|
217 ph: parseFloat($("#ph").jqxNumberInput('decimal')), |
|
218 tun_weight: parseFloat($("#tun_weight").jqxNumberInput('decimal')), |
|
219 tun_specific_heat: parseFloat($("#tun_specific_heat").jqxNumberInput('decimal')), |
|
220 equip_adjust: $("equip_adjust").val(), |
|
221 notes: $("#notes").val() |
|
222 }; |
|
223 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
224 $("#popupWindow").jqxWindow('hide'); |
|
225 } else { |
|
226 // Insert a record |
|
227 var newrow = { |
|
228 record: -1, |
|
229 name: $("#name").val(), |
|
230 grain_temp: parseFloat($("#grain_temp").jqxNumberInput('decimal')), |
|
231 tun_temp: parseFloat($("#tun_temp").jqxNumberInput('decimal')), |
|
232 sparge_temp: parseFloat($("#sparge_temp").jqxNumberInput('decimal')), |
|
233 ph: parseFloat($("#ph").jqxNumberInput('decimal')), |
|
234 tun_weight: parseFloat($("#tun_weight").jqxNumberInput('decimal')), |
|
235 tun_specific_heat: parseFloat($("#tun_specific_heat").jqxNumberInput('decimal')), |
|
236 equip_adjust: $("equip_adjust").val(), |
|
237 notes: $("#notes").val() |
|
238 }; |
|
239 $('#jqxgrid').jqxGrid('addrow', null, newrow); |
|
240 $("#popupWindow").jqxWindow('hide'); |
|
241 } |
|
242 }); |
|
243 createDelElements(); |
|
244 }); |
|
245 |