www/js/inv_suppliers.js

changeset 800
3775ee26657f
parent 799
cf145b35d65f
child 801
55c2510891b8
equal deleted inserted replaced
799:cf145b35d65f 800:3775ee26657f
1 /*****************************************************************************
2 * Copyright (C) 2014-2022
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
25 function createDelElements() {
26 $('#eventWindow').jqxWindow({
27 theme: theme,
28 position: { x: 490, y: 210 },
29 width: 300,
30 height: 175,
31 resizable: false,
32 isModal: true,
33 modalOpacity: 0.4,
34 okButton: $('#delOk'),
35 cancelButton: $('#delCancel'),
36 initContent: function() {
37 $('#delOk').jqxButton({ template: 'danger', width: '65px', theme: theme });
38 $('#delCancel').jqxButton({ template: 'success', width: '65px', theme: theme });
39 $('#delCancel').focus();
40 }
41 });
42 $('#eventWindow').jqxWindow('hide');
43 }
44
45
46
47 $(document).ready(function() {
48
49 // tooltips
50 $('#name').jqxTooltip({ content: 'De naam van de leverancier.' });
51 $('#address').jqxTooltip({ content: 'Het adres en huisnummer.' });
52 $('#city').jqxTooltip({ content: 'De woonplaats of gemeente.' });
53 $('#zip').jqxTooltip({ content: 'De postcode.' });
54 $('#country').jqxTooltip({ content: 'Het land.' });
55 $('#website').jqxTooltip({ content: 'Het website adres.' });
56 $('#email').jqxTooltip({ content: 'Het email adres.' });
57 $('#phone').jqxTooltip({ content: 'Het telefoon nummer.' });
58 $('#notes').jqxTooltip({ content: 'Opmerkingen over deze leverancier.' });
59
60 var dataRecord = {},
61 url = 'includes/db_inventory_suppliers.php',
62 source = {
63 datatype: 'json',
64 cache: false,
65 datafields: [
66 { name: 'record', type: 'number' },
67 { name: 'uuid', type: 'string' },
68 { name: 'name', type: 'string' },
69 { name: 'address', type: 'string' },
70 { name: 'city', type: 'string' },
71 { name: 'zip', type: 'string' },
72 { name: 'country', type: 'string' },
73 { name: 'website', type: 'string' },
74 { name: 'email', type: 'string' },
75 { name: 'phone', type: 'string' },
76 { name: 'notes', type: 'string' }
77 ],
78 id: 'record',
79 url: url,
80 deleterow: function(rowid, commit) {
81 // synchronize with the server - send delete command
82 var data = 'delete=true&' + $.param({ record: rowid });
83 $.ajax({
84 dataType: 'json',
85 url: url,
86 cache: false,
87 data: data,
88 type: 'POST',
89 success: function(data) {
90 if (data.error) {
91 console.log('delete: ' + data.msg);
92 alert('Fout: ' + data.msg);
93 } else {
94 console.log('delete: success');
95 }
96 location.reload(true);
97 },
98 error: function(jqXHR, textStatus, errorThrown) {
99 commit(false);
100 }
101 });
102 },
103 addrow: function(rowid, rowdata, position, commit) {
104 var data = 'insert=true&' + $.param(rowdata);
105 $.ajax({
106 dataType: 'json',
107 url: url,
108 cache: false,
109 data: data,
110 type: 'POST',
111 success: function(data) {
112 if (data.error) {
113 console.log('insert: ' + data.msg);
114 alert('Fout: ' + data.msg);
115 } else {
116 console.log('insert: success');
117 }
118 location.reload(true);
119 },
120 error: function(jqXHR, textStatus, errorThrown) {
121 commit(false);
122 }
123 });
124 },
125 updaterow: function(rowid, rowdata, commit) {
126 var data = 'update=true&' + $.param(rowdata);
127 $.ajax({
128 dataType: 'json',
129 url: url,
130 cache: false,
131 data: data,
132 type: 'POST',
133 success: function(data) {
134 if (data.error) {
135 console.log('updaterow: ' + data.msg);
136 alert('Fout: ' + data.msg);
137 } else {
138 console.log('updaterow: success');
139 }
140 location.reload(true);
141 },
142 error: function(jqXHR, textStatus, errorThrown) {
143 commit(false);
144 }
145 });
146 }
147 },
148 dataAdapter = new $.jqx.dataAdapter(source),
149 editrow = -1;
150
151 // initialize the input fields.
152 $('#name').jqxInput({ theme: theme, width: 640, height: 23 });
153 $('#address').jqxInput({ theme: theme, width: 350, height: 23 });
154 $('#zip').jqxInput({ theme: theme, width: 120, height: 23 });
155 $('#city').jqxInput({ theme: theme, width: 350, height: 23 });
156 $('#country').jqxInput({ theme: theme, width: 250, height: 23 });
157 $('#website').jqxInput({ theme: theme, width: 640, height: 23 });
158 $('#email').jqxInput({ theme: theme, width: 640, height: 23 });
159 $('#phone').jqxInput({ theme: theme, width: 175, height: 23 });
160 $('#notes').jqxInput({ theme: theme, width: 800, height: 100 });
161
162 // initialize jqxGrid
163 $('#jqxgrid').jqxGrid({
164 width: 1280,
165 height: 630,
166 source: dataAdapter,
167 theme: theme,
168 showstatusbar: true,
169 renderstatusbar: function(statusbar) {
170 var rowCount = $("#jqxgrid").jqxGrid('getrows').length;
171 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Aantal items: ' + rowCount + '</div>');
172 var addButton, container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>');
173 addButton = $('<div style="float: right; margin-right: 15px;"><img style="position: relative; margin-top: 2px;" ' +
174 'src="images/add.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Nieuw</span></div>');
175 expButton = $('<div style="float: right; margin-right: 50px;"><img style="position: relative; margin-top: 2px;" ' +
176 'src="images/database.png"/><span style="margin-left: 4px; position: relative; top: -3px;">Export</span></div>');
177 container.append(addButton);
178 container.append(expButton);
179 statusbar.append(container);
180 addButton.jqxButton({ theme: theme, width: 90, height: 20 });
181 expButton.jqxButton({ theme: theme, width: 90, height: 20 });
182 // add new row.
183 addButton.click(function(event) {
184 editrow = -1;
185 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
186 $('#name').val('Nieuwe leverancier');
187 dataRecord.uuid = '';
188 $('#address').val('');
189 $('#city').val('');
190 $('#zip').val('');
191 $('#country').val('Nederland');
192 $('#website').val('');
193 $('#email').val('');
194 $('#phone').val('');
195 $('#notes').val('');
196 $('#popupWindow').jqxWindow('open');
197 });
198 expButton.click(function(event) {
199 window.open('export_suppliers.php');
200 });
201 },
202 filterable: false,
203 columns: [
204 { text: 'Leverancier naam', datafield: 'name' },
205 { text: 'Adres', datafield: 'address', width: 300 },
206 { text: 'Plaats', datafield: 'city', width: 250 },
207 { text: 'Land', datafield: 'country', width: 200 },
208 { text: 'Telefoon', datafield: 'phone', width: 175 },
209 { text: 'Wijzig', datafield: 'Edit', width: 100, align: 'center', columntype: 'button',
210 cellsrenderer: function() {
211 return 'Wijzig';
212 }, buttonclick: function(row) {
213 // open the popup window when the user clicks a button.
214 editrow = row;
215 $('#popupWindow').jqxWindow({ position: { x: 110, y: 30 } });
216 // get the clicked row's data and initialize the input fields.
217 dataRecord = $('#jqxgrid').jqxGrid('getrowdata', editrow);
218 $('#name').val(dataRecord.name);
219 $('#address').val(dataRecord.address);
220 $('#city').val(dataRecord.city);
221 $('#zip').val(dataRecord.zip);
222 $('#country').val(dataRecord.country);
223 $('#website').val(dataRecord.website);
224 $('#email').val(dataRecord.email);
225 $('#phone').val(dataRecord.phone);
226 $('#notes').val(dataRecord.notes);
227 // show the popup window.
228 $('#popupWindow').jqxWindow('open');
229 }
230 }
231 ]
232 });
233 // initialize the popup window and buttons.
234 $('#popupWindow').jqxWindow({
235 width: 1050,
236 height: 550,
237 resizable: false,
238 theme: theme,
239 isModal: true,
240 autoOpen: false,
241 cancelButton: $('#Cancel'),
242 modalOpacity: 0.40
243 });
244 $('#popupWindow').on('open', function() {
245 $('#name').jqxInput('selectAll');
246 });
247 $('#Delete').jqxButton({ template: 'danger', width: '90px', theme: theme });
248 $('#Delete').click(function() {
249 if (editrow >= 0) {
250 // Open a popup to confirm this action.
251 $('#eventWindow').jqxWindow('open');
252 $('#delOk').click(function() {
253 var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
254 $('#jqxgrid').jqxGrid('deleterow', rowID);
255 });
256 }
257 $('#popupWindow').jqxWindow('hide');
258 });
259 $('#Cancel').jqxButton({ template: 'primary', width: '90px', theme: theme });
260 $('#Save').jqxButton({ template: 'success', width: '90px', theme: theme });
261 // update the edited row when the user clicks the 'Save' button.
262 $('#Save').click(function() {
263 var row, rowID = -1;
264 if (editrow >= 0) {
265 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
266 }
267 row = {
268 record: rowID,
269 name: $('#name').val(),
270 uuid: dataRecord.uuid,
271 address: $('#address').val(),
272 city: $('#city').val(),
273 zip: $('#zip').val(),
274 country: $('#country').val(),
275 website: $('#website').val(),
276 email: $('#email').val(),
277 phone: $('#phone').val(),
278 notes: $('#notes').val()
279 };
280 if (editrow >= 0) {
281 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
282 } else {
283 $('#jqxgrid').jqxGrid('addrow', null, row);
284 }
285 $('#popupWindow').jqxWindow('hide');
286 });
287 createDelElements();
288 });
289

mercurial