Mercurial > lada > lada-client
comparison app/controller/grid/ProbeList.js @ 1244:d391f055022e
WIP Added Erfassungsbogen-Druck
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Tue, 08 Nov 2016 10:55:24 +0100 |
parents | 848b50a4a4eb |
children | a7dc14e3b976 |
comparison
equal
deleted
inserted
replaced
1243:03826fba90bb | 1244:d391f055022e |
---|---|
34 click: this.uploadFile | 34 click: this.uploadFile |
35 }, | 35 }, |
36 'probelistgrid toolbar button[action=export]': { | 36 'probelistgrid toolbar button[action=export]': { |
37 click: this.downloadFile | 37 click: this.downloadFile |
38 }, | 38 }, |
39 'probelistgrid toolbar button[action=print]': { | 39 'probelistgrid toolbar button[action=printSheet]': { |
40 click: this.printSelection | 40 click: { |
41 fn: this.printSelection, | |
42 mode: 'printsheet' | |
43 } | |
44 }, | |
45 'probelistgrid toolbar button[action=printExtract]': { | |
46 click: { | |
47 fn: this.printSelection, | |
48 mode: 'printextract' | |
49 } | |
41 }, | 50 }, |
42 'probelistgrid gridview': { | 51 'probelistgrid gridview': { |
43 expandbody: this.expandBody, | 52 expandbody: this.expandBody, |
44 collapsebody: this.collapseBody | 53 collapsebody: this.collapseBody |
45 } | 54 } |
150 }, | 159 }, |
151 | 160 |
152 /** | 161 /** |
153 * Send the selection to a Printservice | 162 * Send the selection to a Printservice |
154 */ | 163 */ |
155 printSelection: function(button) { | 164 printSelection: function(button, e, eOpts) { |
156 | 165 switch (eOpts.mode) { |
166 case "printextract" : | |
167 var printData = this.createExtractData(button); | |
168 this.printpdf(printData, 'lada_print', 'lada-print.pdf', button); | |
169 break; | |
170 case "printsheet" : | |
171 // The Data is loaded from the server again, so we need | |
172 // to be a little bit asynchronous here... | |
173 callback = function(response) { | |
174 var data = response.responseText; | |
175 var printData = '{"layout": "A4 portrait", "outputFormat": "pdf",' | |
176 + '"attributes": { "proben": ' + data | |
177 + '}}'; | |
178 this.printpdf(printData, 'lada_erfassungsbogen', | |
179 'lada-erfassungsbogen.pdf', button); | |
180 } | |
181 | |
182 this.createSheetData(button, callback, this); | |
183 break; | |
184 } | |
185 }, | |
186 | |
187 /** | |
188 * Toggles the buttons in the toolbar | |
189 **/ | |
190 activateButtons: function(rowModel, record) { | |
191 var grid = rowModel.view.up('grid'); | |
192 this.buttonToggle(true, grid); | |
193 }, | |
194 | |
195 /** | |
196 * Toggles the buttons in the toolbar | |
197 **/ | |
198 deactivateButtons: function(rowModel, record) { | |
199 var grid = rowModel.view.up('grid'); | |
200 // Only disable buttons when nothing is selected | |
201 if (rowModel.selected.items == 0) { | |
202 this.buttonToggle(false, grid); | |
203 } | |
204 }, | |
205 | |
206 /** | |
207 * Enables/Disables a set of buttons | |
208 **/ | |
209 buttonToggle: function(enabled, grid) { | |
210 if (!enabled) { | |
211 grid.down('button[action=export]').disable(); | |
212 grid.down('button[action=printExtract]').disable(); | |
213 grid.down('button[action=printSheet]').disable(); | |
214 } | |
215 else { | |
216 grid.down('button[action=export]').enable(); | |
217 grid.down('button[action=printExtract]').enable(); | |
218 grid.down('button[action=printSheet]').enable(); | |
219 } | |
220 }, | |
221 | |
222 reload: function(btn) { | |
223 if (btn === 'yes') { | |
224 location.reload(); | |
225 } | |
226 }, | |
227 | |
228 expandBody: function(rowNode, record, expandRow) { | |
229 // var row = Ext.get('probe-row-' + record.get('id')); | |
230 // var messungGrid = Ext.create('Lada.view.grid.Messung', { | |
231 // recordId: record.get('id'), | |
232 // bottomBar: false, | |
233 // rowLines: true | |
234 // }); | |
235 // row.swallowEvent(['click', 'mousedown', 'mouseup', 'dblclick'], true); | |
236 // messungGrid.render(row); | |
237 }, | |
238 | |
239 collapseBody: function(rowNode, record, expandRow) { | |
240 // var element = Ext.get('probe-row-' + record.get('id')).down('div'); | |
241 // element.destroy(); | |
242 }, | |
243 | |
244 /** | |
245 * Returns a Json-Object whcih contains the data which has | |
246 * to be printed. | |
247 * The parameter printFunctionCallback will be called once the ajax-request | |
248 * starting the json-export was evaluated | |
249 **/ | |
250 createSheetData: function(button, printFunctionCallback, cbscope){ | |
251 //disable Button and setLoading... | |
252 // TODO ACTIVATE! | |
253 //button.disable(); | |
254 //button.setLoading(true); | |
255 | |
256 | |
257 // get Selected Items. | |
258 var grid = button.up('grid'); | |
259 var selection = grid.getView().getSelectionModel().getSelection(); | |
260 var i18n = Lada.getApplication().bundle; | |
261 var me = this; | |
262 var ids = []; | |
263 | |
264 for (item in selection) { | |
265 ids.push(selection[item].data['id']); | |
266 } | |
267 | |
268 //basically, thats the same as the downloadFile | |
269 // code does. | |
270 var data = '{ "proben": ['+ids.toString()+'] }'; | |
271 | |
272 Ext.Ajax.request({ | |
273 url: 'lada-server/data/export/json', | |
274 jsonData: data, | |
275 binary: false, | |
276 scope: cbscope, | |
277 success: printFunctionCallback, | |
278 failure: function(response) { | |
279 console.log('failure'); | |
280 // Error handling | |
281 // TODO | |
282 console.log(response.responseText) | |
283 button.enable(); | |
284 button.setLoading(false); | |
285 // This is "copy & waste-code" from downloadFile | |
286 // FIXME | |
287 /* | |
288 SSO will send a 302 if the Client is not authenticated | |
289 unfortunately this seems to be filtered by the browser. | |
290 We assume that a 302 was send when the follwing statement | |
291 is true. | |
292 */ | |
293 if (response.status == 0 && response.responseText === "") { | |
294 Ext.MessageBox.confirm(Lada.getApplication().bundle.getMsg('err.msg.sso.expired.title'), | |
295 Lada.getApplication().bundle.getMsg('err.msg.sso.expired.body'), | |
296 this.reload); | |
297 } | |
298 // further error handling | |
299 var json = Ext.JSON.decode(response.responseText); | |
300 if (json) { | |
301 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
302 formPanel.setMessages(json.errors, json.warnings); | |
303 } | |
304 if(json.message){ | |
305 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') | |
306 +' #'+json.message, | |
307 Lada.getApplication().bundle.getMsg(json.message)); | |
308 } else { | |
309 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
310 i18n.getMsg('err.msg.print.failed')); | |
311 } | |
312 } else { | |
313 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
314 i18n.getMsg('err.msg.print.failed')); | |
315 } | |
316 | |
317 return null; | |
318 } | |
319 }); | |
320 }, | |
321 | |
322 /** | |
323 * Returns a Json-Object whcih contains the data which has | |
324 * to be printed. | |
325 **/ | |
326 createExtractData: function(button){ | |
157 //disable Button and setLoading... | 327 //disable Button and setLoading... |
158 button.disable(); | 328 button.disable(); |
159 button.setLoading(true); | 329 button.setLoading(true); |
160 | 330 |
161 var grid = button.up('grid'); | 331 var grid = button.up('grid'); |
255 'columns': columnNames, | 425 'columns': columnNames, |
256 'data': data | 426 'data': data |
257 } | 427 } |
258 } | 428 } |
259 } | 429 } |
260 | 430 return printData; |
431 }, | |
432 | |
433 /** | |
434 * this function uses an AJAX request in order to | |
435 * send the data to the endpoint of the mapfish-print | |
436 */ | |
437 printpdf: function(data, endpoint, filename, button){ | |
261 Ext.Ajax.request({ | 438 Ext.Ajax.request({ |
262 url: 'lada-printer/buildreport.pdf', | 439 url: 'lada-printer/'+endpoint+'/buildreport.pdf', |
263 //configure a proxy in apache conf! | 440 //configure a proxy in apache conf! |
264 jsonData: printData, | 441 jsonData: data, |
265 binary: true, | 442 binary: true, |
266 success: function(response) { | 443 success: function(response) { |
267 var content = response.responseBytes; | 444 var content = response.responseBytes; |
268 var filetype = response.getResponseHeader('Content-Type'); | 445 var filetype = response.getResponseHeader('Content-Type'); |
269 var blob = new Blob([content],{type: filetype}); | 446 var blob = new Blob([content],{type: filetype}); |
270 saveAs(blob, 'lada-print.pdf'); | 447 saveAs(blob, filename); |
271 button.enable(); | 448 button.enable(); |
272 button.setLoading(false); | 449 button.setLoading(false); |
273 }, | 450 }, |
274 failure: function(response) { | 451 failure: function(response) { |
452 var i18n = Lada.getApplication().bundle; | |
275 console.log('failure'); | 453 console.log('failure'); |
276 // Error handling | 454 // Error handling |
277 // TODO | 455 // TODO |
278 //console.log(response.responseText) | 456 //console.log(response.responseText) |
279 button.enable(); | 457 button.enable(); |
302 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | 480 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), |
303 i18n.getMsg('err.msg.print.noContact')); | 481 i18n.getMsg('err.msg.print.noContact')); |
304 } | 482 } |
305 } | 483 } |
306 }); | 484 }); |
307 }, | |
308 | |
309 /** | |
310 * Toggles the buttons in the toolbar | |
311 **/ | |
312 activateButtons: function(rowModel, record) { | |
313 var grid = rowModel.view.up('grid'); | |
314 this.buttonToggle(true, grid); | |
315 }, | |
316 | |
317 /** | |
318 * Toggles the buttons in the toolbar | |
319 **/ | |
320 deactivateButtons: function(rowModel, record) { | |
321 var grid = rowModel.view.up('grid'); | |
322 // Only disable buttons when nothing is selected | |
323 if (rowModel.selected.items == 0) { | |
324 this.buttonToggle(false, grid); | |
325 } | |
326 }, | |
327 | |
328 /** | |
329 * Enables/Disables a set of buttons | |
330 **/ | |
331 buttonToggle: function(enabled, grid) { | |
332 if (!enabled) { | |
333 grid.down('button[action=export]').disable(); | |
334 grid.down('button[action=print]').disable(); | |
335 } | |
336 else { | |
337 grid.down('button[action=export]').enable(); | |
338 grid.down('button[action=print]').enable(); | |
339 } | |
340 }, | |
341 | |
342 reload: function(btn) { | |
343 if (btn === 'yes') { | |
344 location.reload(); | |
345 } | |
346 }, | |
347 | |
348 expandBody: function(rowNode, record, expandRow) { | |
349 // var row = Ext.get('probe-row-' + record.get('id')); | |
350 // var messungGrid = Ext.create('Lada.view.grid.Messung', { | |
351 // recordId: record.get('id'), | |
352 // bottomBar: false, | |
353 // rowLines: true | |
354 // }); | |
355 // row.swallowEvent(['click', 'mousedown', 'mouseup', 'dblclick'], true); | |
356 // messungGrid.render(row); | |
357 }, | |
358 | |
359 collapseBody: function(rowNode, record, expandRow) { | |
360 // var element = Ext.get('probe-row-' + record.get('id')).down('div'); | |
361 // element.destroy(); | |
362 } | 485 } |
486 | |
363 }); | 487 }); |