www/js/inv_hops.js

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

mercurial