www/js/inv_water_sources.js

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

mercurial