Mercurial > lada > lada-client
comparison app/controller/grid/ProbeList.js @ 1007:23bfcbdb4527
merged.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 20 Jan 2016 17:33:33 +0100 |
parents | f73ca04d73a7 |
children | dbd435256f77 |
comparison
equal
deleted
inserted
replaced
1002:54179b6043b6 | 1007:23bfcbdb4527 |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 | |
9 /** | |
10 * Controller for the ProbeList result grid. | |
11 */ | |
12 Ext.define('Lada.controller.grid.ProbeList', { | |
13 extend: 'Ext.app.Controller', | |
14 requires: [ | |
15 'Lada.view.window.ProbeEdit', | |
16 'Lada.view.window.GenProbenFromMessprogramm' | |
17 ], | |
18 | |
19 /** | |
20 * Initialize the Controller with listeners | |
21 */ | |
22 init: function() { | |
23 this.control({ | |
24 'probelistgrid': { | |
25 itemdblclick: this.editItem, | |
26 select: this.activateButtons, | |
27 deselect: this.deactivateButtons | |
28 }, | |
29 'probelistgrid toolbar button[action=addProbe]': { | |
30 click: this.addProbeItem | |
31 }, | |
32 'probelistgrid toolbar button[action=import]': { | |
33 click: this.uploadFile | |
34 }, | |
35 'probelistgrid toolbar button[action=export]': { | |
36 click: this.downloadFile | |
37 }, | |
38 'probelistgrid toolbar button[action=print]': { | |
39 click: this.printSelection | |
40 } | |
41 }); | |
42 this.callParent(arguments); | |
43 }, | |
44 | |
45 /** | |
46 * This function is called after a Row in the | |
47 * {@link Lada.view.grid.ProbeList} | |
48 * was double-clicked. | |
49 * The function opens a {@link Lada.view.window.ProbeEdit} | |
50 * or a {@link Lada.view.window.Messprogramm}. | |
51 * To determine which window has to be opened, the function | |
52 * analyse the records modelname. | |
53 */ | |
54 editItem: function(grid, record) { | |
55 var winname = 'Lada.view.window.ProbeEdit'; | |
56 | |
57 var win = Ext.create(winname, { | |
58 record: record, | |
59 style: 'z-index: -1;' //Fixes an Issue where windows could not be created in IE8 | |
60 }); | |
61 | |
62 win.show(); | |
63 win.initData(); | |
64 }, | |
65 | |
66 /** | |
67 * This function opens a new window to create a Probe | |
68 * {@link Lada.view.window.ProbeCreate} | |
69 */ | |
70 addProbeItem: function() { | |
71 var win = Ext.create('Lada.view.window.ProbeCreate'); | |
72 win.show(); | |
73 win.initData(); | |
74 }, | |
75 | |
76 /** | |
77 * This function opens a {@link Lada.view.window.FileUpload} | |
78 * window to upload a LAF-File | |
79 */ | |
80 uploadFile: function() { | |
81 var win = Ext.create('Lada.view.window.FileUpload', { | |
82 title: 'Datenimport', | |
83 modal: true | |
84 }); | |
85 | |
86 win.show(); | |
87 }, | |
88 | |
89 /** | |
90 * This function can be used to Download the items which | |
91 * were selected in the {@link Lada.view.grid.ProbeList} | |
92 * The Download does not work with Internet Explorers older than v.10 | |
93 */ | |
94 downloadFile: function(button) { | |
95 var grid = button.up('grid'); | |
96 var selection = grid.getView().getSelectionModel().getSelection(); | |
97 var i18n = Lada.getApplication().bundle; | |
98 var proben = []; | |
99 for (var i = 0; i < selection.length; i++) { | |
100 proben.push(selection[i].get('id')); | |
101 } | |
102 var me = this; | |
103 Ext.Ajax.request({ | |
104 url: 'lada-server/data/export/laf', | |
105 jsonData: {'proben': proben}, | |
106 success: function(response) { | |
107 var content = response.responseText; | |
108 var blob = new Blob([content],{type: 'text/plain'}); | |
109 saveAs(blob, 'export.laf'); | |
110 }, | |
111 failure: function(response) { | |
112 /* | |
113 SSO will send a 302 if the Client is not authenticated | |
114 unfortunately this seems to be filtered by the browser. | |
115 We assume that a 302 was send when the follwing statement | |
116 is true. | |
117 */ | |
118 if (response.status == 0 && response.responseText === "") { | |
119 Ext.MessageBox.confirm('Erneutes Login erforderlich', | |
120 'Ihre Session ist abgelaufen.<br/>'+ | |
121 'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' + | |
122 'Alle ungesicherten Daten gehen dabei verloren.<br/>' + | |
123 'Soll die Anwendung jetzt neu geladen werden?', this.reload); | |
124 } | |
125 // further error handling | |
126 var json = Ext.JSON.decode(response.responseText); | |
127 if (json) { | |
128 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
129 formPanel.setMessages(json.errors, json.warnings); | |
130 } | |
131 if(json.message){ | |
132 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') | |
133 +' #'+json.message, | |
134 Lada.getApplication().bundle.getMsg(json.message)); | |
135 } else { | |
136 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
137 i18n.getMsg('err.msg.laf.filecreatefailed')); | |
138 } | |
139 } else { | |
140 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
141 i18n.getMsg('err.msg.laf.filecreatefailed')); | |
142 } | |
143 } | |
144 }); | |
145 }, | |
146 | |
147 /** | |
148 * Send the selection to a Printservice | |
149 */ | |
150 printSelection: function(button) { | |
151 | |
152 //disable Button and setLoading... | |
153 button.disable(); | |
154 button.setLoading(true); | |
155 | |
156 var grid = button.up('grid'); | |
157 var selection = grid.getView().getSelectionModel().getSelection(); | |
158 var i18n = Lada.getApplication().bundle; | |
159 var me = this; | |
160 var columns = []; | |
161 var columnNames = []; | |
162 var visibleColumns = []; | |
163 var displayName = ''; | |
164 var data = []; | |
165 | |
166 // Write the columns to an array | |
167 try { | |
168 for (key in selection[0].data) { | |
169 // Do not write owner or readonly or id | |
170 if (["owner", "readonly", "id"].indexOf(key) == -1){ | |
171 columns.push(key); | |
172 } | |
173 } | |
174 } | |
175 catch (e) { | |
176 console.log(e); | |
177 } | |
178 | |
179 //Retrieve visible columns' id's and names. | |
180 // and set displayName | |
181 try { | |
182 var grid = button.up('grid'); | |
183 var cman = grid.columnManager; | |
184 var cols = cman.getColumns(); | |
185 | |
186 displayName = grid.down('tbtext').text; | |
187 | |
188 for (key in cols) { | |
189 if (cols[key].dataIndex) { | |
190 visibleColumns[cols[key].dataIndex] = cols[key].text; | |
191 } | |
192 } | |
193 } | |
194 catch (e) { | |
195 console.log(e); | |
196 } | |
197 | |
198 | |
199 // Retrieve Data from selection | |
200 try { | |
201 for (item in selection) { | |
202 var row = selection[item].data; | |
203 var out = []; | |
204 //Lookup every column and write to data array. | |
205 for (key in columns){ | |
206 var attr = columns[key]; | |
207 //Only write data to output when the column is not hidden. | |
208 if (row[attr] != null && | |
209 visibleColumns[attr] != null) { | |
210 out.push(row[attr].toString()); | |
211 } | |
212 else if (visibleColumns[attr] != null) { | |
213 out.push(''); | |
214 } | |
215 } | |
216 data.push(out); | |
217 } | |
218 } | |
219 catch (e){ | |
220 console.log(e); | |
221 } | |
222 | |
223 //Retrieve the names of the columns. | |
224 try { | |
225 var grid = button.up('grid'); | |
226 var cman = grid.columnManager; | |
227 var cols = cman.getColumns(); | |
228 //Iterate columns and find column names for the key... | |
229 // This WILL run into bad behaviour when column-keys exist twice. | |
230 for (key in columns){ | |
231 for (k in cols){ | |
232 if (cols[k].dataIndex == columns[key]){ | |
233 columnNames.push(cols[k].text); | |
234 break; | |
235 } | |
236 } | |
237 } | |
238 } | |
239 catch (e) { | |
240 console.log(e); | |
241 } | |
242 | |
243 var printData = { | |
244 'layout': 'A4 landscape', | |
245 'outputFormat': 'pdf', | |
246 'attributes': { | |
247 'title': 'Auszug aus LADA', | |
248 'displayName': displayName, | |
249 'table': { | |
250 'columns': columnNames, | |
251 'data': data | |
252 } | |
253 } | |
254 } | |
255 | |
256 Ext.Ajax.request({ | |
257 url: 'lada-printer/buildreport.pdf', | |
258 //configure a proxy in apache conf! | |
259 jsonData: printData, | |
260 binary: true, | |
261 success: function(response) { | |
262 var content = response.responseBytes; | |
263 var filetype = response.getResponseHeader('Content-Type'); | |
264 var blob = new Blob([content],{type: filetype}); | |
265 saveAs(blob, 'lada-print.pdf'); | |
266 button.enable(); | |
267 button.setLoading(false); | |
268 }, | |
269 failure: function(response) { | |
270 console.log('failure'); | |
271 // Error handling | |
272 // TODO | |
273 //console.log(response.responseText) | |
274 button.enable(); | |
275 button.setLoading(false); | |
276 if (response.responseText) { | |
277 try { | |
278 var json = Ext.JSON.decode(response.responseText); | |
279 } | |
280 catch(e){ | |
281 console.log(e); | |
282 } | |
283 } | |
284 if (json) { | |
285 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
286 formPanel.setMessages(json.errors, json.warnings); | |
287 } | |
288 if(json.message){ | |
289 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title') | |
290 +' #'+json.message, | |
291 Lada.getApplication().bundle.getMsg(json.message)); | |
292 } else { | |
293 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
294 i18n.getMsg('err.msg.print.noContact')); | |
295 } | |
296 } else { | |
297 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'), | |
298 i18n.getMsg('err.msg.print.noContact')); | |
299 } | |
300 } | |
301 }); | |
302 }, | |
303 | |
304 /** | |
305 * Toggles the buttons in the toolbar | |
306 **/ | |
307 activateButtons: function(rowModel, record) { | |
308 var grid = rowModel.view.up('grid'); | |
309 this.buttonToggle(true, grid); | |
310 }, | |
311 | |
312 /** | |
313 * Toggles the buttons in the toolbar | |
314 **/ | |
315 deactivateButtons: function(rowModel, record) { | |
316 var grid = rowModel.view.up('grid'); | |
317 // Only disable buttons when nothing is selected | |
318 if (rowModel.selected.items == 0) { | |
319 this.buttonToggle(false, grid); | |
320 } | |
321 }, | |
322 | |
323 /** | |
324 * Enables/Disables a set of buttons | |
325 **/ | |
326 buttonToggle: function(enabled, grid) { | |
327 if (!enabled) { | |
328 grid.down('button[action=export]').disable(); | |
329 grid.down('button[action=print]').disable(); | |
330 } | |
331 else { | |
332 grid.down('button[action=export]').enable(); | |
333 grid.down('button[action=print]').enable(); | |
334 } | |
335 }, | |
336 | |
337 reload: function(btn) { | |
338 if (btn === 'yes') { | |
339 location.reload(); | |
340 } | |
341 } | |
342 }); |