|
1 /***************************************************************************** |
|
2 * Copyright (C) 2014-2018 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of Brewery Management System |
|
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: 355, y: 210 }, |
|
28 width: 270, |
|
29 resizable: false, |
|
30 isModal: true, |
|
31 modalOpacity: 0.4, |
|
32 okButton: $('#delOk'), |
|
33 cancelButton: $('#delCancel'), |
|
34 initContent: function () { |
|
35 $('#delOk').jqxButton({ width: '65px', theme: theme }); |
|
36 $('#delCancel').jqxButton({ width: '65px', theme: theme }); |
|
37 $('#delCancel').focus(); |
|
38 } |
|
39 }); |
|
40 $('#eventWindow').jqxWindow('hide'); |
|
41 } |
|
42 |
|
43 |
|
44 $(document).ready(function () { |
|
45 var url = "includes/db_inventory_suppliers.php"; |
|
46 // prepare the data |
|
47 var source = { |
|
48 datatype: "json", |
|
49 cache: false, |
|
50 datafields: [ |
|
51 { name: 'record', type: 'number' }, |
|
52 { name: 'name', type: 'string' }, |
|
53 { name: 'address', type: 'string' }, |
|
54 { name: 'city', type: 'string' }, |
|
55 { name: 'zip', type: 'string' }, |
|
56 { name: 'country', type: 'string' }, |
|
57 { name: 'website', type: 'string' }, |
|
58 { name: 'email', type: 'string' }, |
|
59 { name: 'phone', type: 'string' }, |
|
60 { name: 'notes', type: 'string' } |
|
61 ], |
|
62 id: 'record', |
|
63 url: url, |
|
64 deleterow: function (rowid, commit) { |
|
65 // synchronize with the server - send delete command |
|
66 var data = "delete=true&" + $.param({ record: rowid }); |
|
67 $.ajax({ |
|
68 dataType: 'json', |
|
69 url: url, |
|
70 cache: false, |
|
71 data: data, |
|
72 success: function (data, status, xhr) { |
|
73 // delete command is executed. |
|
74 commit(true); |
|
75 }, |
|
76 error: function (jqXHR, textStatus, errorThrown) { |
|
77 commit(false); |
|
78 } |
|
79 }); |
|
80 }, |
|
81 addrow: function (rowid, rowdata, position, commit) { |
|
82 var data = "insert=true&" + $.param(rowdata); |
|
83 $.ajax({ |
|
84 dataType: 'json', |
|
85 url: url, |
|
86 cache: false, |
|
87 data: data, |
|
88 success: function (data, status, xhr) { |
|
89 commit(true); |
|
90 }, |
|
91 error: function(jqXHR, textStatus, errorThrown) { |
|
92 commit(false); |
|
93 } |
|
94 }); |
|
95 }, |
|
96 updaterow: function (rowid, rowdata, commit) { |
|
97 var data = "update=true&" + $.param(rowdata); |
|
98 $.ajax({ |
|
99 dataType: 'json', |
|
100 url: url, |
|
101 cache: false, |
|
102 data: data, |
|
103 success: function (data, status, xhr) { |
|
104 // update command is executed. |
|
105 commit(true); |
|
106 }, |
|
107 error: function(jqXHR, textStatus, errorThrown) { |
|
108 commit(false); |
|
109 } |
|
110 }); |
|
111 } |
|
112 }; |
|
113 // initialize the input fields. |
|
114 $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
115 $("#address").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
116 $("#zip").jqxInput({ theme: theme, width: 120, height: 23 }); |
|
117 $("#city").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
118 $("#country").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
119 $("#website").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
120 $("#email").jqxInput({ theme: theme, width: 250, height: 23 }); |
|
121 $("#phone").jqxInput({ theme: theme, width: 120, height: 23 }); |
|
122 $("#notes").jqxInput({ theme: theme, width: 640, height: 48 }); |
|
123 |
|
124 var dataAdapter = new $.jqx.dataAdapter(source); |
|
125 var editrow = -1; |
|
126 // initialize jqxGrid |
|
127 $("#jqxgrid").jqxGrid({ |
|
128 width: 980, |
|
129 source: dataAdapter, |
|
130 theme: theme, |
|
131 showstatusbar: true, |
|
132 renderstatusbar: function (statusbar) { |
|
133 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
134 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>"); |
|
135 container.append(addButton); |
|
136 statusbar.append(container); |
|
137 addButton.jqxButton({ width: 60, height: 20 }); |
|
138 // add new row. |
|
139 addButton.click(function (event) { |
|
140 editrow = -1; |
|
141 $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); |
|
142 $("#name").val(''); |
|
143 $("#address").val(''); |
|
144 $("#city").val(''); |
|
145 $("#zip").val(''); |
|
146 $("#country").val(''); |
|
147 $("#website").val(''); |
|
148 $("#email").val(''); |
|
149 $("#phone").val(''); |
|
150 $("#notes").val(''); |
|
151 $("#popupWindow").jqxWindow('open'); |
|
152 }); |
|
153 }, |
|
154 filterable: true, |
|
155 filtermode: 'excel', |
|
156 columns: [ |
|
157 { text: 'Supplier Name', datafield: 'name', width: 250 }, |
|
158 { text: 'City', datafield: 'city', width: 250 }, |
|
159 { text: 'Country', datafield: 'country', width: 250 }, |
|
160 { text: 'Phone', datafield: 'phone', width: 100 }, |
|
161 { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { |
|
162 return "Edit"; |
|
163 }, buttonclick: function (row) { |
|
164 // open the popup window when the user clicks a button. |
|
165 editrow = row; |
|
166 $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); |
|
167 // get the clicked row's data and initialize the input fields. |
|
168 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
|
169 $("#name").val(dataRecord.name); |
|
170 $("#address").val(dataRecord.address); |
|
171 $("#city").val(dataRecord.city); |
|
172 $("#zip").val(dataRecord.zip); |
|
173 $("#country").val(dataRecord.country); |
|
174 $("#website").val(dataRecord.website); |
|
175 $("#email").val(dataRecord.email); |
|
176 $("#phone").val(dataRecord.phone); |
|
177 $("#notes").val(dataRecord.notes); |
|
178 // show the popup window. |
|
179 $("#popupWindow").jqxWindow('open'); |
|
180 } |
|
181 } |
|
182 ] |
|
183 }); |
|
184 // initialize the popup window and buttons. |
|
185 $("#popupWindow").jqxWindow({ |
|
186 width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 |
|
187 }); |
|
188 $("#popupWindow").on('open', function () { |
|
189 $("#name").jqxInput('selectAll'); |
|
190 }); |
|
191 $("#Delete").jqxButton({ theme: theme }); |
|
192 $("#Delete").click(function () { |
|
193 if (editrow >= 0) { |
|
194 // Open a popup to confirm this action. |
|
195 $('#eventWindow').jqxWindow('open'); |
|
196 $("#delOk").click(function () { |
|
197 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
198 $("#jqxgrid").jqxGrid('deleterow', rowID); |
|
199 }); |
|
200 } |
|
201 $("#popupWindow").jqxWindow('hide'); |
|
202 }); |
|
203 $("#Cancel").jqxButton({ theme: theme }); |
|
204 $("#Save").jqxButton({ theme: theme }); |
|
205 // update the edited row when the user clicks the 'Save' button. |
|
206 $("#Save").click(function () { |
|
207 if (editrow >= 0) { |
|
208 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
|
209 var row = { |
|
210 record: rowID, |
|
211 name: $("#name").val(), |
|
212 address: $("#address").val(), |
|
213 city: $("#city").val(), |
|
214 zip: $("#zip").val(), |
|
215 country: $("#country").val(), |
|
216 website: $("#website").val(), |
|
217 email: $("#email").val(), |
|
218 phone: $("#phone").val(), |
|
219 notes: $("#notes").val() |
|
220 }; |
|
221 $('#jqxgrid').jqxGrid('updaterow', rowID, row); |
|
222 $("#popupWindow").jqxWindow('hide'); |
|
223 } else { |
|
224 // Insert a record |
|
225 var newrow = { |
|
226 record: -1, |
|
227 name: $("#name").val(), |
|
228 address: $("#address").val(), |
|
229 city: $("#city").val(), |
|
230 zip: $("#zip").val(), |
|
231 country: $("#country").val(), |
|
232 website: $("#website").val(), |
|
233 email: $("#email").val(), |
|
234 phone: $("#phone").val(), |
|
235 notes: $("#notes").val() |
|
236 }; |
|
237 $('#jqxgrid').jqxGrid('addrow', null, newrow); |
|
238 $("#popupWindow").jqxWindow('hide'); |
|
239 } |
|
240 }); |
|
241 createDelElements(); |
|
242 }); |
|
243 |