comparison app/controller/grid/ProbeList.js @ 975:fb99332bb48e stammdatengrids

Severe changes concerning the Resultgrids. - Intrduced "Stammdaten" which can be selected in the Mode Field on the left side, - Added Stores and Models for the Stammdaten - Removed the FilterResultgrid and replaced it with a model which uses inheritance. Dynamic Grid Columns can now be derived from app/view/widget/DynamicGrid.js For Proben and Messprogramme this is already done. - There might be some REGRESSION concerning the buttons in the ProbeList and MessprogrammeList grid, as those are not disabled properly. This needs to be fixed in future commits.
author Dustin Demuth <dustin@intevation.de>
date Wed, 02 Dec 2015 17:39:04 +0100
parents
children 56470a075e6e
comparison
equal deleted inserted replaced
974:ea477f62a667 975:fb99332bb48e
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 },
27 'probelistgrid toolbar button[action=addProbe]': {
28 click: this.addProbeItem
29 },
30 'probelistgrid toolbar button[action=import]': {
31 click: this.uploadFile
32 },
33 'probelistgrid toolbar button[action=export]': {
34 click: this.downloadFile
35 },
36 'probelistgrid toolbar button[action=print]': {
37 click: this.printSelection
38 }
39 });
40 this.callParent(arguments);
41 },
42
43 /**
44 * This function is called after a Row in the
45 * {@link Lada.view.grid.ProbeList}
46 * was double-clicked.
47 * The function opens a {@link Lada.view.window.ProbeEdit}
48 * or a {@link Lada.view.window.Messprogramm}.
49 * To determine which window has to be opened, the function
50 * analyse the records modelname.
51 */
52 editItem: function(grid, record) {
53 var winname = 'Lada.view.window.ProbeEdit';
54
55 var win = Ext.create(winname, {
56 record: record,
57 style: 'z-index: -1;' //Fixes an Issue where windows could not be created in IE8
58 });
59
60 win.show();
61 win.initData();
62 },
63
64 /**
65 * This function opens a new window to create a Probe
66 * {@link Lada.view.window.ProbeCreate}
67 */
68 addProbeItem: function() {
69 var win = Ext.create('Lada.view.window.ProbeCreate');
70 win.show();
71 win.initData();
72 },
73
74 /**
75 * This function opens a {@link Lada.view.window.FileUpload}
76 * window to upload a LAF-File
77 */
78 uploadFile: function() {
79 var win = Ext.create('Lada.view.window.FileUpload', {
80 title: 'Datenimport',
81 modal: true
82 });
83
84 win.show();
85 },
86
87 /**
88 * This function can be used to Download the items which
89 * were selected in the {@link Lada.view.grid.ProbeList}
90 * The Download does not work with Internet Explorers older than v.10
91 */
92 downloadFile: function(button) {
93 var grid = button.up('grid');
94 var selection = grid.getView().getSelectionModel().getSelection();
95 var i18n = Lada.getApplication().bundle;
96 var proben = [];
97 for (var i = 0; i < selection.length; i++) {
98 proben.push(selection[i].get('id'));
99 }
100 var me = this;
101 Ext.Ajax.request({
102 url: 'lada-server/export/laf',
103 jsonData: {'proben': proben},
104 success: function(response) {
105 var content = response.responseText;
106 var blob = new Blob([content],{type: 'text/plain'});
107 saveAs(blob, 'export.laf');
108 },
109 failure: function(response) {
110 /*
111 SSO will send a 302 if the Client is not authenticated
112 unfortunately this seems to be filtered by the browser.
113 We assume that a 302 was send when the follwing statement
114 is true.
115 */
116 if (response.status == 0 && response.responseText === "") {
117 Ext.MessageBox.confirm('Erneutes Login erforderlich',
118 'Ihre Session ist abgelaufen.<br/>'+
119 'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
120 'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
121 'Soll die Anwendung jetzt neu geladen werden?', this.reload);
122 }
123 // further error handling
124 var json = Ext.JSON.decode(response.responseText);
125 if (json) {
126 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
127 formPanel.setMessages(json.errors, json.warnings);
128 }
129 if(json.message){
130 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
131 +' #'+json.message,
132 Lada.getApplication().bundle.getMsg(json.message));
133 } else {
134 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
135 i18n.getMsg('err.msg.laf.filecreatefailed'));
136 }
137 } else {
138 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
139 i18n.getMsg('err.msg.laf.filecreatefailed'));
140 }
141 }
142 });
143 },
144
145 /**
146 * Send the selection to a Printservice
147 */
148 printSelection: function(button) {
149
150 //disable Button and setLoading...
151 button.disable();
152 button.setLoading(true);
153
154 var grid = button.up('grid');
155 var selection = grid.getView().getSelectionModel().getSelection();
156 var i18n = Lada.getApplication().bundle;
157 var me = this;
158 var columns = [];
159 var columnNames = [];
160 var visibleColumns = [];
161 var displayName = '';
162 var data = [];
163
164 // Write the columns to an array
165 try {
166 for (key in selection[0].data) {
167 // Do not write owner or readonly or id
168 if (["owner", "readonly", "id"].indexOf(key) == -1){
169 columns.push(key);
170 }
171 }
172 }
173 catch (e) {
174 console.log(e);
175 }
176
177 //Retrieve visible columns' id's and names.
178 // and set displayName
179 try {
180 var grid = button.up('grid');
181 var cman = grid.columnManager;
182 var cols = cman.getColumns();
183
184 displayName = grid.down('tbtext').text;
185
186 for (key in cols) {
187 if (cols[key].dataIndex) {
188 visibleColumns[cols[key].dataIndex] = cols[key].text;
189 }
190 }
191 }
192 catch (e) {
193 console.log(e);
194 }
195
196
197 // Retrieve Data from selection
198 try {
199 for (item in selection) {
200 var row = selection[item].data;
201 var out = [];
202 //Lookup every column and write to data array.
203 for (key in columns){
204 var attr = columns[key];
205 //Only write data to output when the column is not hidden.
206 if (row[attr] != null &&
207 visibleColumns[attr] != null) {
208 out.push(row[attr].toString());
209 }
210 else if (visibleColumns[attr] != null) {
211 out.push('');
212 }
213 }
214 data.push(out);
215 }
216 }
217 catch (e){
218 console.log(e);
219 }
220
221 //Retrieve the names of the columns.
222 try {
223 var grid = button.up('grid');
224 var cman = grid.columnManager;
225 var cols = cman.getColumns();
226 //Iterate columns and find column names for the key...
227 // This WILL run into bad behaviour when column-keys exist twice.
228 for (key in columns){
229 for (k in cols){
230 if (cols[k].dataIndex == columns[key]){
231 columnNames.push(cols[k].text);
232 break;
233 }
234 }
235 }
236 }
237 catch (e) {
238 console.log(e);
239 }
240
241 var printData = {
242 'layout': 'A4 landscape',
243 'outputFormat': 'pdf',
244 'attributes': {
245 'title': 'Auszug aus LADA',
246 'displayName': displayName,
247 'table': {
248 'columns': columnNames,
249 'data': data
250 }
251 }
252 }
253
254 Ext.Ajax.request({
255 url: 'lada-printer/buildreport.pdf',
256 //configure a proxy in apache conf!
257 jsonData: printData,
258 binary: true,
259 success: function(response) {
260 var content = response.responseBytes;
261 var filetype = response.getResponseHeader('Content-Type');
262 var blob = new Blob([content],{type: filetype});
263 saveAs(blob, 'lada-print.pdf');
264 button.enable();
265 button.setLoading(false);
266 },
267 failure: function(response) {
268 console.log('failure');
269 // Error handling
270 // TODO
271 //console.log(response.responseText)
272 button.enable();
273 button.setLoading(false);
274 if (response.responseText) {
275 try {
276 var json = Ext.JSON.decode(response.responseText);
277 }
278 catch(e){
279 console.log(e);
280 }
281 }
282 if (json) {
283 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
284 formPanel.setMessages(json.errors, json.warnings);
285 }
286 if(json.message){
287 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
288 +' #'+json.message,
289 Lada.getApplication().bundle.getMsg(json.message));
290 } else {
291 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
292 i18n.getMsg('err.msg.print.noContact'));
293 }
294 } else {
295 Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
296 i18n.getMsg('err.msg.print.noContact'));
297 }
298 }
299 });
300 },
301
302 reload: function(btn) {
303 if (btn === 'yes') {
304 location.reload();
305 }
306 }
307 });

http://lada.wald.intevation.org