www/js/inv_miscs.js

changeset 21
acb2d8098f19
child 34
a720353fada9
equal deleted inserted replaced
20:22271f3598ac 21:acb2d8098f19
1 /*****************************************************************************
2 * Copyright (C) 2014-2018
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * BrewCloud is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with ThermFerm; see the file COPYING. If not, write to the Free
18 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 *****************************************************************************/
20
21
22 function createDelElements() {
23 $('#eventWindow').jqxWindow({
24 theme: theme,
25 position: { x: 490, y: 210 },
26 width: 300,
27 height: 145,
28 resizable: false,
29 isModal: true,
30 modalOpacity: 0.4,
31 okButton: $('#delOk'),
32 cancelButton: $('#delCancel'),
33 initContent: function () {
34 $('#delOk').jqxButton({ width: '65px', theme: theme });
35 $('#delCancel').jqxButton({ width: '65px', theme: theme });
36 $('#delCancel').focus();
37 }
38 });
39 $('#eventWindow').jqxWindow('hide');
40 }
41
42
43 $(document).ready(function () {
44 var url = "includes/db_inventory_miscs.php";
45 // prepare the data
46 var source = {
47 datatype: "json",
48 cache: false,
49 datafields: [
50 { name: 'record', type: 'number' },
51 { name: 'name', type: 'string' },
52 { name: 'type', type: 'string' },
53 { name: 'use_use', type: 'string' },
54 { name: 'time', type: 'float' },
55 { name: 'amount', type: 'float' },
56 { name: 'amount_is_weight', type: 'bool' },
57 { name: 'use_for', type: 'string' },
58 { name: 'notes', type: 'string' },
59 { name: 'always_on_stock', type: 'bool' },
60 { name: 'inventory', type: 'float' },
61 { name: 'cost', type: 'float' },
62 { name: 'production_date', type: 'string' },
63 { name: 'tht_date', type: 'string' }
64 ],
65 id: 'record',
66 url: url,
67 deleterow: function (rowid, commit) {
68 // synchronize with the server - send delete command
69 var data = "delete=true&" + $.param({ record: rowid });
70 $.ajax({
71 dataType: 'json',
72 url: url,
73 cache: false,
74 data: data,
75 success: function (data, status, xhr) {
76 // delete command is executed.
77 commit(true);
78 },
79 error: function (jqXHR, textStatus, errorThrown) {
80 commit(false);
81 }
82 });
83 },
84 addrow: function (rowid, rowdata, position, commit) {
85 var data = "insert=true&" + $.param(rowdata);
86 $.ajax({
87 dataType: 'json',
88 url: url,
89 cache: false,
90 data: data,
91 success: function (data, status, xhr) {
92 commit(true);
93 },
94 error: function(jqXHR, textStatus, errorThrown) {
95 commit(false);
96 }
97 });
98 },
99 updaterow: function (rowid, rowdata, commit) {
100 var data = "update=true&" + $.param(rowdata);
101 $.ajax({
102 dataType: 'json',
103 url: url,
104 cache: false,
105 data: data,
106 success: function (data, status, xhr) {
107 // update command is executed.
108 commit(true);
109 },
110 error: function(jqXHR, textStatus, errorThrown) {
111 commit(false);
112 }
113 });
114 }
115 };
116 var srcType = [ "Spice", "Fining", "Water Agent", "Herb", "Flavor", "Other" ];
117 var srcUse = [ "Boil", "Mash", "Primary", "Secondary", "Bottling" ];
118 // initialize the input fields.
119 $("#name").jqxInput({ theme: theme, width: 250, height: 23 });
120 $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 130, height: 23, dropDownHeight: 188 });
121 $("#use_use").jqxDropDownList({ theme: theme, source: srcUse, width: 90, height: 23, dropDownHeight: 156 });
122 $("#time").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true });
123 $("#amount_is_weight").jqxCheckBox({ theme: theme, width: 120, height: 23 });
124 $("#use_for").jqxInput({ theme: theme, width: 640, height: 48 });
125 $("#notes").jqxInput({ theme: theme, width: 640, height: 100 });
126 $("#always_on_stock").jqxCheckBox({ theme: theme, width: 120, height: 23 });
127 $("#inventory").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true });
128 $("#production_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' });
129 $("#cost").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true });
130 $("#tht_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' });
131
132 var dataAdapter = new $.jqx.dataAdapter(source);
133 var editrow = -1;
134 // initialize jqxGrid
135 $("#jqxgrid").jqxGrid({
136 width: 1280,
137 height: 630,
138 source: dataAdapter,
139 theme: theme,
140 showstatusbar: true,
141 localization: getLocalization(),
142 renderstatusbar: function (statusbar) {
143 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>");
144 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>");
145 container.append(addButton);
146 statusbar.append(container);
147 addButton.jqxButton({ width: 60, height: 20 });
148 // add new row.
149 addButton.click(function (event) {
150 editrow = -1;
151 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } });
152 $("#name").val('');
153 $("#type").val('');
154 $("#use_use").val('');
155 $("#time").val('');
156 $("#amount_is_weight").val('');
157 $("#use_for").val('');
158 $("#notes").val('');
159 $("#always_on_stock").val('');
160 $("#inventory").val('');
161 $("#cost").val('');
162 $("#production_date").val('');
163 $("#tht_date").val('');
164 $("#popupWindow").jqxWindow('open');
165 });
166 },
167 filterable: true,
168 filtermode: 'excel',
169 columns: [
170 { text: 'Ingredient naam', datafield: 'name', width: 250 },
171 { text: 'Soort', datafield: 'type', width: 90 },
172 { text: 'Gebruik', datafield: 'use_use', width: 90 },
173 { text: 'Tijd', datafield: 'time', width: 90, cellsalign: 'right', cellsformat: 'f2' },
174 { text: 'Voorraad.', datafield: 'inventory', width: 70, cellsalign: 'right' },
175 { text: 'Prijs', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' },
176 { text: 'THT datum', datafield: 'tht_date', width: 100 },
177 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () {
178 return "Edit";
179 }, buttonclick: function (row) {
180 // open the popup window when the user clicks a button.
181 editrow = row;
182 $("#popupWindow").jqxWindow({ position: { x: 230, y: 30 } });
183 // get the clicked row's data and initialize the input fields.
184 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
185 $("#name").val(dataRecord.name);
186 $("#type").val(dataRecord.type);
187 $("#use_use").val(dataRecord.use_use);
188 $("#time").val(dataRecord.time);
189 $("#amount_is_weight").val(dataRecord.amount_is_weight);
190 $("#use_for").val(dataRecord.use_for);
191 $("#notes").val(dataRecord.notes);
192 $("#always_on_stock").val(dataRecord.always_on_stock);
193 $("#inventory").val(dataRecord.inventory);
194 $("#cost").val(dataRecord.cost);
195 $("#production_date").val(dataRecord.production_date);
196 $("#tht_date").val(dataRecord.tht_date);
197 // show the popup window.
198 $("#popupWindow").jqxWindow('open');
199 }
200 }
201 ]
202 });
203 // initialize the popup window and buttons.
204 $("#popupWindow").jqxWindow({
205 width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40
206 });
207 $("#popupWindow").on('open', function () {
208 $("#name").jqxInput('selectAll');
209 });
210 $("#Delete").jqxButton({ theme: theme });
211 $("#Delete").click(function () {
212 if (editrow >= 0) {
213 // Open a popup to confirm this action.
214 $('#eventWindow').jqxWindow('open');
215 $("#delOk").click(function () {
216 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
217 $("#jqxgrid").jqxGrid('deleterow', rowID);
218 });
219 }
220 $("#popupWindow").jqxWindow('hide');
221 });
222 $("#Cancel").jqxButton({ theme: theme });
223 $("#Save").jqxButton({ theme: theme });
224 // update the edited row when the user clicks the 'Save' button.
225 $("#Save").click(function () {
226 if (editrow >= 0) {
227 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
228 var row = {
229 record: rowID,
230 name: $("#name").val(),
231 type: $("#type").val(),
232 use_use: $("#use_use").val(),
233 time: parseFloat($("#time").jqxNumberInput('decimal')),
234 amount_is_weight: $("#amount_is_weight").val(),
235 use_for: $("#use_for").val(),
236 notes: $("#notes").val(),
237 always_on_stock: $("#always_on_stock").val(),
238 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')),
239 cost: parseFloat($("#cost").jqxNumberInput('decimal')),
240 production_date: $("#production_date").val(),
241 tht_date: $("#tht_date").val()
242 };
243 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
244 $("#popupWindow").jqxWindow('hide');
245 } else {
246 // Insert a record
247 var newrow = {
248 record: -1,
249 name: $("#name").val(),
250 type: $("#type").val(),
251 use_use: $("#use_use").val(),
252 time: parseFloat($("#time").jqxNumberInput('decimal')),
253 amount_is_weight: $("#amount_is_weight").val(),
254 use_for: $("#use_for").val(),
255 notes: $("#notes").val(),
256 always_on_stock: $("#always_on_stock").val(),
257 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')),
258 cost: parseFloat($("#cost").jqxNumberInput('decimal')),
259 production_date: $("#production_date").val(),
260 tht_date: $("#tht_date").val()
261 };
262 $('#jqxgrid').jqxGrid('addrow', null, newrow);
263 $("#popupWindow").jqxWindow('hide');
264 }
265 });
266 createDelElements();
267 });
268

mercurial