comparison app/controller/Proben.js @ 497:7c0653e8d9f7

Fixed some js related issues (unused vars, arrays, etc.) and code style.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 06 Nov 2014 10:38:17 +0100
parents d07e5086a64b
children 8b4ec61c5752
comparison
equal deleted inserted replaced
496:d07e5086a64b 497:7c0653e8d9f7
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz 1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH 2 * Software engineering by Intevation GmbH
3 * 3 *
4 * This file is Free Software under the GNU GPL (v>=3) 4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out 5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details. 6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */ 7 */
8 8
9 /** 9 /**
10 * Controller for Proben 10 * Controller for Proben
11 */ 11 */
19 } 19 }
20 return errors; 20 return errors;
21 } 21 }
22 22
23 function buildImportReport(filename, msg, errors, warnings) { 23 function buildImportReport(filename, msg, errors, warnings) {
24 var out = Array(); 24 var out = [];
25 // There is a entry for each imported proben in the errors dict (might be 25 // There is a entry for each imported proben in the errors dict (might be
26 // empty) 26 // empty)
27 var num_proben = (Object.keys(errors).length > 0); 27 var numProben = (Object.keys(errors).length > 0);
28 var num_errors = (numOfErrors(errors)); 28 var numErrors = (numOfErrors(errors));
29 var has_warnings = (Object.keys(warnings).length > 0); 29 var hasWarnings = (Object.keys(warnings).length > 0);
30 if (msg != 200) { 30 if (msg !== 200) {
31 out.push("Der Import der Datei " + filename + " war nicht erfolgreich. Der Importvorgang konnte aufgrund eines Fehlers im Server nicht beendet werden."); 31 out.push('Der Import der Datei ' +
32 } else { 32 filename +
33 if (num_errors == num_proben) { 33 ' war nicht erfolgreich. Der Importvorgang konnte aufgrund' +
34 out.push("Der Import der Datei " + filename + " war nicht erfolgreich."); 34 'eines Fehlers im Server nicht beendet werden.');
35 }
36 else if (num_errors == 0) {
37 out.push("Der Import der Datei " + filename + " war erfolgreich.");
38 } else {
39 out.push("Der Import der Datei " + filename + " war nicht oder nur teilweise erfolgreich.");
40 }
41 out.push(" Bei dem Import sind folgende Fehler und Warnungen aufgetreten:");
42 out.push("<br/>");
43 if (num_errors) {
44 out.push("<strong>Fehler:</strong>");
45 out.push("<br/>");
46 out.push("<ol>");
47 for (var key in errors) {
48 out.push("<li>Probe: "+key)
49 var msgs = errors[key];
50 out.push("<ol>");
51 for (var i = msgs.length - 1; i >= 0; i--){
52 out.push("<li>"+msgs[i].key+" ("+Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+"): "+msgs[i].value+"</li>")
53 };
54 out.push("</ol>");
55 out.push("</li>");
56 }
57 out.push("</ol>");
58 out.push("<br/>");
59 }
60 if (has_warnings) {
61 out.push("<strong>Warnungen:</strong>");
62 out.push("<br/>");
63 out.push("<ol>");
64 for (var key in warnings) {
65 out.push("<li>"+key)
66 var msgs = warnings[key];
67 out.push("<ol>");
68 for (var i = msgs.length - 1; i >= 0; i--){
69 out.push("<li>"+msgs[i].key+" ("+Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+"): "+msgs[i].value+"</li>")
70 };
71 out.push("</ol>");
72 out.push("</li>");
73 }
74 out.push("</ol>");
75 }
76 } 35 }
77 return out.join(""); 36 else {
37 if (numErrors === numProben) {
38 out.push('Der Import der Datei '
39 + filename + ' war nicht erfolgreich.');
40 }
41 else if (numErrors === 0) {
42 out.push('Der Import der Datei ' + filename + ' war erfolgreich.');
43 }
44 else {
45 out.push('Der Import der Datei '
46 + filename + ' war nicht oder nur teilweise erfolgreich.');
47 }
48 out.push(' Bei dem Import sind folgende Fehler und Warnungen ' +
49 'aufgetreten:');
50 out.push('<br/>');
51 var key;
52 var msgs;
53 if (numErrors) {
54 out.push('<strong>Fehler:</strong>');
55 out.push('<br/>');
56 out.push('<ol>');
57 for (key in errors) {
58 out.push('<li>Probe: ' + key);
59 msgs = errors[key];
60 out.push('<ol>');
61 for (var i = msgs.length - 1; i >= 0; i--) {
62 out.push('<li>' + msgs[i].key +
63 ' (' + Lada.getApplication().bundle.getMsg(
64 msgs[i].code.toString()) +
65 '): ' + msgs[i].value + '</li>');
66 }
67 out.push('</ol>');
68 out.push('</li>');
69 }
70 out.push('</ol>');
71 out.push('<br/>');
72 }
73 if (hasWarnings) {
74 out.push('<strong>Warnungen:</strong>');
75 out.push('<br/>');
76 out.push('<ol>');
77 for (key in warnings) {
78 out.push('<li>' + key);
79 msgs = warnings[key];
80 out.push('<ol>');
81 for (var i = msgs.length - 1; i >= 0; i--) {
82 out.push('<li>' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'</li>')
83 }
84 out.push('</ol>');
85 out.push('</li>');
86 }
87 out.push('</ol>');
88 }
89 }
90 return out.join('');
78 } 91 }
79 92
80 Ext.define('Lada.controller.Proben', { 93 Ext.define('Lada.controller.Proben', {
81 extend: 'Lada.controller.Base', 94 extend: 'Lada.controller.Base',
82 95
131 savefailure: this.editFailure 144 savefailure: this.editFailure
132 } 145 }
133 }); 146 });
134 }, 147 },
135 148
136 addItem: function(button) { 149 addItem: function() {
137 console.log('Adding new Probe'); 150 console.log('Adding new Probe');
138 var view = Ext.widget('probencreate'); 151 Ext.widget('probencreate');
139 }, 152 },
140 153
141 /** 154 /**
142 * Opens a window with a file chooser to select the file to upload 155 * Opens a window with a file chooser to select the file to upload
143 * @private 156 * @private
144 */ 157 */
145 selectUploadFile: function(button) { 158 selectUploadFile: function() {
146 console.log('Importing'); 159 console.log('Importing');
147 var view = Ext.widget('probenimport'); 160 Ext.widget('probenimport');
148 }, 161 },
149 162
150 /** Uploads the selected file the the server 163 /** Uploads the selected file the the server
151 * @private 164 * @private
152 */ 165 */
162 success: function(fp, resp) { 175 success: function(fp, resp) {
163 var errors = resp.result.data.errors; 176 var errors = resp.result.data.errors;
164 var warnings = resp.result.data.warnings; 177 var warnings = resp.result.data.warnings;
165 var filename = resp.result.data.filename; 178 var filename = resp.result.data.filename;
166 var message = resp.result.message; 179 var message = resp.result.message;
167 var dialogbody = buildImportReport(filename, message, errors, warnings) 180 var dialogbody =
168 var filename = resp.result.data.filename; 181 buildImportReport(filename, message, errors, warnings);
169 Ext.Msg.alert('Erfolg', dialogbody); 182 Ext.Msg.alert('Erfolg', dialogbody);
170 win.close(); 183 win.close();
171 }, 184 },
172 failure: function(fp, resp) { 185 failure: function(fp, resp) {
173 var errors = resp.result.data.errors; 186 var errors = resp.result.data.errors;
174 var warnings = resp.result.data.warnings; 187 var warnings = resp.result.data.warnings;
175 var filename = resp.result.data.filename; 188 var filename = resp.result.data.filename;
176 var message = resp.result.message; 189 var message = resp.result.message;
177 var dialogbody = buildImportReport(filename, message, errors, warnings) 190 var dialogbody =
191 buildImportReport(filename, message, errors, warnings);
178 Ext.Msg.alert('Fehler', dialogbody); 192 Ext.Msg.alert('Fehler', dialogbody);
179 win.close(); 193 win.close();
180 } 194 }
181 }); 195 });
182 } 196 }
246 }); 260 });
247 var view = Ext.widget('probenedit', { 261 var view = Ext.widget('probenedit', {
248 modelId: id 262 modelId: id
249 }); 263 });
250 view.show(); 264 view.show();
251 console.log("Loaded Probe with ID " + record.getId()); //outputs ID 265 console.log('Loaded Probe with ID ' + record.getId());
252 }, 266 },
253 267
254 createSuccess: function(form, record, response) { 268 createSuccess: function(form, record, response) {
255 // Close Createdialog 269 // Close Createdialog
256 var win = form.up('window'); 270 var win = form.up('window');
257 win.close(); 271 win.close();
258 var store = this.getProbenStore(); 272 var store = this.getProbenStore();
259 //Load or reload the probenstore. 273 // Load or reload the probenstore.
260 if (store.getCount() === 0) { 274 if (store.getCount() === 0) {
261 store.load({ 275 store.load({
262 scope: this, 276 scope: this,
263 callback: function(records, operation, success) { 277 callback: function() {
264 console.log('Loaded store'); 278 console.log('Loaded store');
265 // Open Editdialog 279 // Open Editdialog
266 var json = Ext.decode(response.responseText); 280 var json = Ext.decode(response.responseText);
267 if (json) { 281 if (json) {
268 var probeId = json.data.probeId; 282 var probeId = json.data.probeId;
269 var probe = store.findRecord("probeId", probeId); 283 var probe = store.findRecord('probeId', probeId);
270 this.editItem(null, probe); 284 this.editItem(null, probe);
271 } 285 }
272 } 286 }
273 }); 287 });
274 } 288 }
275 else { 289 else {
276 store.reload({ 290 store.reload({
277 scope: this, 291 scope: this,
278 callback: function(records, operation, success) { 292 callback: function() {
279 console.log('Reloaded store'); 293 console.log('Reloaded store');
280 // Open Editdialog 294 // Open Editdialog
281 var json = Ext.decode(response.responseText); 295 var json = Ext.decode(response.responseText);
282 if (json) { 296 if (json) {
283 var probeId = json.data.probeId; 297 var probeId = json.data.probeId;
284 var probe = store.findRecord("probeId", probeId); 298 var probe = store.findRecord('probeId', probeId);
285 this.editItem(null, probe); 299 this.editItem(null, probe);
286 } 300 }
287 } 301 }
288 }); 302 });
289 } 303 }
290 }, 304 },
291 305
292 editSuccess: function(form, record, response) { 306 editSuccess: function(form) {
293 // Reload store 307 // Reload store
294 var store = this.getProbenStore(); 308 var store = this.getProbenStore();
295 store.reload(); 309 store.reload();
296 var win = form.up('window'); 310 var win = form.up('window');
297 win.close(); 311 win.close();

http://lada.wald.intevation.org