www/js/inv_hops.js

changeset 13
b8c3ca152984
parent 12
c26af32428a4
child 18
395833e20f88
equal deleted inserted replaced
12:c26af32428a4 13:b8c3ca152984
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2014=2018 2 * Copyright (C) 2014-2018
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of BrewCloud 6 * This file is part of BrewCloud
7 * 7 *
55 { name: 'beta', type: 'float' }, 55 { name: 'beta', type: 'float' },
56 { name: 'humulene', type: 'float' }, 56 { name: 'humulene', type: 'float' },
57 { name: 'caryophyllene', type: 'float' }, 57 { name: 'caryophyllene', type: 'float' },
58 { name: 'cohumulone', type: 'float' }, 58 { name: 'cohumulone', type: 'float' },
59 { name: 'myrcene', type: 'float' }, 59 { name: 'myrcene', type: 'float' },
60 { name: 'hsi', type: 'float' },
60 { name: 'useat', type: 'string' }, 61 { name: 'useat', type: 'string' },
61 { name: 'type', type: 'string' }, 62 { name: 'type', type: 'string' },
62 { name: 'form', type: 'string' }, 63 { name: 'form', type: 'string' },
63 { name: 'notes', type: 'string' }, 64 { name: 'notes', type: 'string' },
64 { name: 'origin', type: 'string' }, 65 { name: 'origin', type: 'string' },
66 { name: 'always_on_stock', type: 'bool' }, 67 { name: 'always_on_stock', type: 'bool' },
67 { name: 'inventory', type: 'float' }, 68 { name: 'inventory', type: 'float' },
68 { name: 'cost', type: 'float' }, 69 { name: 'cost', type: 'float' },
69 { name: 'production_date', type: 'string' }, 70 { name: 'production_date', type: 'string' },
70 { name: 'tht_date', type: 'string' }, 71 { name: 'tht_date', type: 'string' },
71 { name: 'supplier_rec', type: 'float' } 72 { name: 'supplier_rec', type: 'number' },
73 { name: 'total_oil', type: 'float' }
72 ], 74 ],
73 id: 'record', 75 id: 'record',
74 url: url, 76 url: url,
75 deleterow: function (rowid, commit) { 77 deleterow: function (rowid, commit) {
76 // synchronize with the server - send delete command 78 // synchronize with the server - send delete command
119 commit(false); 121 commit(false);
120 } 122 }
121 }); 123 });
122 } 124 }
123 }; 125 };
124 var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ]; 126 // var srcUse = [ "Boil", "Dry Hop", "Mash", "First Wort", "Aroma" ]; // Only in recipes
125 var srcType = [ "Bittering", "Aroma", "Both" ]; 127 var srcType = [ "Bittering", "Aroma", "Both" ];
126 var srcForm = [ "Pellet", "Plug", "Leaf" ]; 128 var srcForm = [ "Pellet", "Plug", "Leaf" ];
127 // initialize the input fields. 129 // initialize the input fields.
128 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); 130 $("#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 }); 131 $("#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 }); 132 $("#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 }); 133 $("#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 }); 134 $("#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 }); 135 $("#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 }); 136 $("#myrcene").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
135 137 $("#hsi").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
136 $("#useat").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 130 }); 138
137 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 130 }); 139 // $("#useat").jqxDropDownList({ theme: theme, source: srcUse, width: 90, height: 23, dropDownHeight: 130 }); // Only in recipes
138 $("#form").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 130 }); 140 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 95 });
139 $("#notes").jqxInput({ theme: theme, width: 640, height: 48 }); 141 $("#form").jqxDropDownList({ theme: theme, source: srcForm, width: 90, height: 23, dropDownHeight: 95 });
142 $("#notes").jqxInput({ theme: theme, width: 640, height: 100 });
140 $("#origin").jqxInput({ theme: theme, width: 250, height: 23 }); 143 $("#origin").jqxInput({ theme: theme, width: 250, height: 23 });
141 $("#substitutes").jqxInput({ theme: theme, width: 250, height: 23 }); 144 $("#substitutes").jqxInput({ theme: theme, width: 250, height: 23 });
142 $("#always_on_stock").jqxCheckBox({ theme: theme, width: 120, height: 23 }); 145 $("#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 }); 146 $("#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' }); 147 $("#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 }); 148 $("#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' }); 149 $("#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 }); 150 // $("#supplier_rec").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); // Implement later.
151 $("#total_oil").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
148 var dataAdapter = new $.jqx.dataAdapter(source); 152 var dataAdapter = new $.jqx.dataAdapter(source);
149 var editrow = -1; 153 var editrow = -1;
150 // initialize jqxGrid 154 // initialize jqxGrid
151 $("#jqxgrid").jqxGrid({ 155 $("#jqxgrid").jqxGrid({
152 width: 1280, 156 width: 1280,
153 height: 630, 157 height: 630,
154 source: dataAdapter, 158 source: dataAdapter,
155 theme: theme, 159 theme: theme,
160 //altrows: true,
156 showstatusbar: true, 161 showstatusbar: true,
162 localization: getLocalization(),
157 renderstatusbar: function (statusbar) { 163 renderstatusbar: function (statusbar) {
158 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); 164 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>"); 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>");
160 container.append(addButton); 166 container.append(addButton);
161 statusbar.append(container); 167 statusbar.append(container);
162 addButton.jqxButton({ width: 60, height: 20 }); 168 addButton.jqxButton({ width: 60, height: 20 });
163 // add new row. 169 // add new row.
164 addButton.click(function (event) { 170 addButton.click(function (event) {
165 editrow = -1; 171 editrow = -1;
166 $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); 172 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } });
167 $("#name").val(''); 173 $("#name").val('');
168 $("#alpha").val(''); 174 $("#alpha").val('');
169 $("#beta").val(''); 175 $("#beta").val('');
170 $("#humulene").val(''); 176 $("#humulene").val('');
171 $("#caryophyllene").val(''); 177 $("#caryophyllene").val('');
172 $("#cohumulone").val(''); 178 $("#cohumulone").val('');
173 $("#myrcene").val(''); 179 $("#myrcene").val('');
180 $("#hsi").val('');
174 $("#useat").val('Boil'); 181 $("#useat").val('Boil');
175 $("#type").val('Bittering'); 182 $("#type").val('Bittering');
176 $("#form").val('Pellet'); 183 $("#form").val('Pellet');
177 $("#notes").val(''); 184 $("#notes").val('');
178 $("#origin").val(''); 185 $("#origin").val('');
181 $("#inventory").val(''); 188 $("#inventory").val('');
182 $("#cost").val(''); 189 $("#cost").val('');
183 $("#production_date").val(''); 190 $("#production_date").val('');
184 $("#tht_date").val(''); 191 $("#tht_date").val('');
185 $("#supplier_rec").val(''); 192 $("#supplier_rec").val('');
193 $("#total_oil").val('');
186 $("#popupWindow").jqxWindow('open'); 194 $("#popupWindow").jqxWindow('open');
187 }); 195 });
188 }, 196 },
189 filterable: true, 197 filterable: true,
190 filtermode: 'excel', 198 filtermode: 'excel',
191 columns: [ 199 columns: [
192 { text: 'Hop Name', datafield: 'name', width: 250 }, 200 { text: 'Hop Naam', datafield: 'name', width: 250 },
193 { text: 'Type', datafield: 'type', width: 90 }, 201 { text: 'Soort', datafield: 'type', width: 90 },
194 { text: 'Alpha', datafield: 'alpha', width: 70, cellsalign: 'right', cellsformat: 'c2' }, 202 { text: 'Vorm', datafield: 'form', width: 90 },
195 { text: 'Origin', datafield: 'origin', width: 150 }, 203 { text: 'Alpha %', datafield: 'alpha', width: 80, cellsalign: 'right', cellsformat: 'p1' },
196 { text: 'Inv.', datafield: 'inventory', width: 70, cellsalign: 'right' }, 204 { text: 'Beta %', datafield: 'beta', width: 80, cellsalign: 'right', cellsformat: 'p1' },
197 { text: 'Cost', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' }, 205 { text: 'Cohumuloon %%', datafield: 'cohumulone', width: 80, cellsalign: 'right', cellsformat: 'p1' },
206 { text: 'HSI', datafield: 'hsi', width: 60, cellsalign: 'right', cellsformat: 'f1' },
207 { text: 'Herkomst', datafield: 'origin', width: 150 },
208 { text: 'Oogst datum', datafield: 'production_date', width: 100 },
209 { text: 'Voorraad', datafield: 'inventory', width: 70, cellsalign: 'right' },
210 { text: 'Prijs /kg', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' },
198 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { 211 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () {
199 return "Edit"; 212 return "Edit";
200 }, buttonclick: function (row) { 213 }, buttonclick: function (row) {
201 // open the popup window when the user clicks a button. 214 // open the popup window when the user clicks a button.
202 editrow = row; 215 editrow = row;
203 $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); 216 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } });
204 // get the clicked row's data and initialize the input fields. 217 // get the clicked row's data and initialize the input fields.
205 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); 218 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
206 $("#name").val(dataRecord.name); 219 $("#name").val(dataRecord.name);
207 $("#alpha").val(dataRecord.alpha); 220 $("#alpha").val(dataRecord.alpha);
208 $("#beta").val(dataRecord.beta); 221 $("#beta").val(dataRecord.beta);
209 $("#humulene").val(dataRecord.humulene); 222 $("#humulene").val(dataRecord.humulene);
210 $("#caryophyllene").val(dataRecord.caryophyllene); 223 $("#caryophyllene").val(dataRecord.caryophyllene);
211 $("#cohumulone").val(dataRecord.cohumulone); 224 $("#cohumulone").val(dataRecord.cohumulone);
212 $("#myrcene").val(dataRecord.myrcene); 225 $("#myrcene").val(dataRecord.myrcene);
226 $("#hsi").val(dataRecord.hsi);
213 $("#useat").val(dataRecord.useat); 227 $("#useat").val(dataRecord.useat);
214 $("#type").val(dataRecord.type); 228 $("#type").val(dataRecord.type);
215 $("#form").val(dataRecord.form); 229 $("#form").val(dataRecord.form);
216 $("#notes").val(dataRecord.notes); 230 $("#notes").val(dataRecord.notes);
217 $("#origin").val(dataRecord.origin); 231 $("#origin").val(dataRecord.origin);
220 $("#inventory").val(dataRecord.inventory); 234 $("#inventory").val(dataRecord.inventory);
221 $("#cost").val(dataRecord.cost); 235 $("#cost").val(dataRecord.cost);
222 $("#production_date").val(dataRecord.production_date); 236 $("#production_date").val(dataRecord.production_date);
223 $("#tht_date").val(dataRecord.tht_date); 237 $("#tht_date").val(dataRecord.tht_date);
224 $("#supplier_rec").val(dataRecord.supplier_rec); 238 $("#supplier_rec").val(dataRecord.supplier_rec);
239 $("#total_oil").val(dataRecord.total_oil);
225 // show the popup window. 240 // show the popup window.
226 $("#popupWindow").jqxWindow('open'); 241 $("#popupWindow").jqxWindow('open');
227 } 242 }
228 } 243 }
229 ] 244 ]
260 beta: parseFloat($("#beta").jqxNumberInput('decimal')), 275 beta: parseFloat($("#beta").jqxNumberInput('decimal')),
261 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')), 276 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')),
262 caryophyllene: parseFloat($("#caryophyllene").jqxNumberInput('decimal')), 277 caryophyllene: parseFloat($("#caryophyllene").jqxNumberInput('decimal')),
263 cohumulone: parseFloat($("#cohumulone").jqxNumberInput('decimal')), 278 cohumulone: parseFloat($("#cohumulone").jqxNumberInput('decimal')),
264 myrcene: parseFloat($("#myrcene").jqxNumberInput('decimal')), 279 myrcene: parseFloat($("#myrcene").jqxNumberInput('decimal')),
280 hsi: parseFloat($("#hsi").jqxNumberInput('decimal')),
265 useat: $("#useat").val(), 281 useat: $("#useat").val(),
266 type: $("#type").val(), 282 type: $("#type").val(),
267 form: $("#form").val(), 283 form: $("#form").val(),
268 notes: $("#notes").val(), 284 notes: $("#notes").val(),
269 origin: $("#origin").val(), 285 origin: $("#origin").val(),
271 always_on_stock: $("#always_on_stock").val(), 287 always_on_stock: $("#always_on_stock").val(),
272 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), 288 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')),
273 cost: parseFloat($("#cost").jqxNumberInput('decimal')), 289 cost: parseFloat($("#cost").jqxNumberInput('decimal')),
274 production_date: $("#production_date").val(), 290 production_date: $("#production_date").val(),
275 tht_date: $("#tht_date").val(), 291 tht_date: $("#tht_date").val(),
276 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) 292 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')),
293 total_oil: parseFloat($("#total_oil").jqxNumberInput('decimal'))
277 }; 294 };
278 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 295 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
279 $("#popupWindow").jqxWindow('hide'); 296 $("#popupWindow").jqxWindow('hide');
280 } else { 297 } else {
281 // Insert a record 298 // Insert a record
286 beta: parseFloat($("#beta").jqxNumberInput('decimal')), 303 beta: parseFloat($("#beta").jqxNumberInput('decimal')),
287 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')), 304 humulene: parseFloat($("#humulene").jqxNumberInput('decimal')),
288 caryophyllene: parseFloat($("#caryophyllene").jqxNumberInput('decimal')), 305 caryophyllene: parseFloat($("#caryophyllene").jqxNumberInput('decimal')),
289 cohumulone: parseFloat($("#cohumulone").jqxNumberInput('decimal')), 306 cohumulone: parseFloat($("#cohumulone").jqxNumberInput('decimal')),
290 myrcene: parseFloat($("#myrcene").jqxNumberInput('decimal')), 307 myrcene: parseFloat($("#myrcene").jqxNumberInput('decimal')),
308 hsi: parseFloat($("#hsi").jqxNumberInput('decimal')),
291 useat: $("#useat").val(), 309 useat: $("#useat").val(),
292 type: $("#type").val(), 310 type: $("#type").val(),
293 form: $("#form").val(), 311 form: $("#form").val(),
294 notes: $("#notes").val(), 312 notes: $("#notes").val(),
295 origin: $("#origin").val(), 313 origin: $("#origin").val(),
297 always_on_stock: $("#always_on_stock").val(), 315 always_on_stock: $("#always_on_stock").val(),
298 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), 316 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')),
299 cost: parseFloat($("#cost").jqxNumberInput('decimal')), 317 cost: parseFloat($("#cost").jqxNumberInput('decimal')),
300 production_date: $("#production_date").val(), 318 production_date: $("#production_date").val(),
301 tht_date: $("#tht_date").val(), 319 tht_date: $("#tht_date").val(),
302 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) 320 supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')),
321 total_oil: parseFloat($("#total_oil").jqxNumberInput('decimal'))
303 }; 322 };
304 $('#jqxgrid').jqxGrid('addrow', null, newrow); 323 $('#jqxgrid').jqxGrid('addrow', null, newrow);
305 $("#popupWindow").jqxWindow('hide'); 324 $("#popupWindow").jqxWindow('hide');
306 } 325 }
307 }); 326 });

mercurial