comparison app/view/window/ImportResponse.js @ 729:7eb8ef8e68ca

Added window to display importer messages.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 17 Apr 2015 13:15:40 +0200
parents
children def27cdd0dfa
comparison
equal deleted inserted replaced
728:aadb6e1f0a70 729:7eb8ef8e68ca
1 /**
2 *
3 */
4 Ext.define('Lada.view.window.ImportResponse', {
5 extend: 'Ext.window.Window',
6 alias: 'widget.importresponse',
7
8 data: null,
9 message: null,
10 fileName: '',
11
12 layout: 'fit',
13 /**
14 * @private
15 * Initialize the view.
16 */
17 initComponent: function() {
18 var me = this;
19 var html;
20 if (me.data && me.message) {
21 html = me.parseResponse(me.message, me.data);
22 }
23 this.bodyStyle = {background: '#fff'};
24 me.items = [{
25 xtype: 'panel',
26 html: html,
27 margin: 10,
28 border: false
29 }];
30
31 this.callParent(arguments);
32 },
33
34 parseResponse: function(msg, data) {
35 console.log(Ext.JSON.decode(data));
36 data = Ext.JSON.decode(data);
37 var errors = data.data.errors;
38 var warnings = data.data.warnings;
39 var out = [];
40 // There is a entry for each imported proben in the errors dict (might be
41 // empty)
42
43 var numErrors;
44 var numWarnings;
45 if (Ext.isEmpty(Object.keys(errors))) {
46 numErrors = 0;
47 }
48 else {
49 numErrors = Object.keys(errors).length;
50 }
51 if (Ext.isEmpty(Object.keys(warnings))) {
52 numWarnings = 0;
53 }
54 else {
55 numWarnings = Object.keys(warnings).length;
56 }
57 if (msg !== '200') {
58 out.push('Der Import der Datei ' + this.fileName +
59 ' war nicht erfolgreich. Der Importvorgang konnte ' +
60 'aufgrund eines Fehlers im Server nicht beendet werden.');
61 }
62 else {
63 if (numErrors > 0) {
64 out.push('Folgende Proben konnten nicht erfolgreich ' +
65 'importiert werden:');
66 out.push('<br/>');
67 out.push('<ol>');
68 var msgs;
69 for (var key in errors) {
70 out.push('<li>Probe: ' + key);
71 msgs = errors[key];
72 out.push('<ol>');
73 for (var i = msgs.length - 1; i >= 0; i--) {
74 if (msgs[i].key === 'validation') {
75 out.push('Validierungsfehler: ');
76 out.push('<ol>');
77 for (var vKey in msgs[i].value) {
78 out.push(Lada.getApplication().bundle.getMsg(vKey) + ': ');
79 for (var j = 0; j < msgs[i].value[vKey].length; j++) {
80 console.log(msgs[i].value[vKey][j]);
81 out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString()));
82 }
83 }
84 out.push('</ol>');
85 }
86 else {
87 out.push(msgs[i].key +
88 ' (' + Lada.getApplication().bundle.getMsg(
89 msgs[i].code.toString()) +
90 '): ' + msgs[i].value);
91 }
92 }
93 out.push('</ol>');
94 out.push('</li>');
95 }
96 out.push('</ol>');
97 out.push('<br/>');
98 }
99 if (numWarnings > 0) {
100 out.push('<br/>');
101 out.push('Bei folgenden Proben traten Warnungen auf:');
102 out.push('<br/>');
103 out.push('<ol>');
104 for (key in warnings) {
105 out.push('<li>' + key);
106 msgs = warnings[key];
107 out.push('<ol>');
108 for (var i = msgs.length - 1; i >= 0; i--) {
109 if (msgs[i].key === 'validation') {
110 out.push('Validierungswarnungen: ');
111 out.push('<ol>');
112 for (var vKey in msgs[i].value) {
113 out.push(Lada.getApplication().bundle.getMsg(vKey) + ': ');
114 for (var j = 0; j < msgs[i].value[vKey].length; j++) {
115 console.log(msgs[i].value[vKey][j]);
116 out.push(Lada.getApplication().bundle.getMsg(msgs[i].value[vKey][j].toString()));
117 }
118 }
119 out.push('</ol>');
120 }
121 else {
122 out.push('<li>' + msgs[i].key + ' (' + Lada.getApplication().bundle.getMsg(msgs[i].code.toString())+'): '+msgs[i].value+'</li>')
123 }
124 }
125 out.push('</ol>');
126 out.push('</li>');
127 }
128 out.push('</ol>');
129 }
130 out.push('<br/>');
131 }
132 console.log(out.join(''));
133 return out.join('');
134 }
135 });

http://lada.wald.intevation.org