Mercurial > lada > lada-client
comparison app/view/window/ImportResponse.js @ 1236:cfc24d2ae268
Fix error handling in ImportResponse window.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 31 Oct 2016 13:54:00 +0100 |
parents | 531db469779f |
children | 1ed5ec9326e6 |
comparison
equal
deleted
inserted
replaced
1235:d1f43f1e7e84 | 1236:cfc24d2ae268 |
---|---|
17 initComponent: function() { | 17 initComponent: function() { |
18 var me = this; | 18 var me = this; |
19 var html; | 19 var html; |
20 var download; | 20 var download; |
21 var i18n = Lada.getApplication().bundle; | 21 var i18n = Lada.getApplication().bundle; |
22 if (me.data && me.message) { | 22 var data = Ext.JSON.decode(me.data, true); |
23 html = me.parseShortResponse(me.message, me.data); | 23 if (data) { |
24 html = me.parseShortResponse(data); | |
24 } | 25 } |
25 else { | 26 else { |
26 html = 'Der Import der Datei ' + this.fileName + | 27 html = 'Der Import der Datei ' + this.fileName + |
27 ' war nicht erfolgreich.'; | 28 ' war nicht erfolgreich.'; |
28 } | 29 } |
47 var blob = new Blob([download],{type: 'text/html'}); | 48 var blob = new Blob([download],{type: 'text/html'}); |
48 saveAs(blob, 'report.html'); | 49 saveAs(blob, 'report.html'); |
49 } | 50 } |
50 }]; | 51 }]; |
51 this.callParent(arguments); | 52 this.callParent(arguments); |
52 if (me.data && me.message) { | 53 if (data) { |
53 download = me.parseResponse(me.message, me.data); | 54 download = me.parseResponse(data); |
54 } | 55 } |
55 }, | 56 }, |
56 | 57 |
57 /** | 58 /** |
58 * Parse the response and create a summary of the result | 59 * Parse the response and create a summary of the result |
59 * @param msg | |
60 * @param data | 60 * @param data |
61 */ | 61 */ |
62 parseShortResponse: function(msg, data) { | 62 parseShortResponse: function(data) { |
63 data = Ext.JSON.decode(data, true); | |
64 var errors = data.data.errors; | 63 var errors = data.data.errors; |
65 var warnings = data.data.warnings; | 64 var warnings = data.data.warnings; |
66 var out = []; | 65 var out = []; |
67 // There is a entry for each imported proben in the errors dict (might be | 66 // There is a entry for each imported proben in the errors dict (might be |
68 // empty) | 67 // empty) |
79 numWarnings = 0; | 78 numWarnings = 0; |
80 } | 79 } |
81 else { | 80 else { |
82 numWarnings = Object.keys(warnings).length; | 81 numWarnings = Object.keys(warnings).length; |
83 } | 82 } |
84 if (msg !== '200') { | 83 if (!data.success) { |
85 out.push('Der Import der Datei ' + this.fileName + | 84 out.push('Der Import der Datei ' + this.fileName + |
86 ' war nicht erfolgreich. Der Importvorgang konnte ' + | 85 ' war nicht erfolgreich. Der Importvorgang konnte ' + |
87 'aufgrund eines Fehlers im Server nicht beendet werden.'); | 86 'aufgrund eines Fehlers im Server nicht beendet werden.'); |
88 } | 87 } |
89 else { | 88 else { |
110 return out.join(''); | 109 return out.join(''); |
111 }, | 110 }, |
112 | 111 |
113 /** | 112 /** |
114 * Parse the Response | 113 * Parse the Response |
115 * @param msg the Lada-Erro-Code | |
116 * @param data the payload of the response | 114 * @param data the payload of the response |
117 */ | 115 */ |
118 parseResponse: function(msg, data) { | 116 parseResponse: function(data) { |
119 data = Ext.JSON.decode(data, true); | |
120 var errors = data.data.errors; | 117 var errors = data.data.errors; |
121 var warnings = data.data.warnings; | 118 var warnings = data.data.warnings; |
122 var out = []; | 119 var out = []; |
123 // There is a entry for each imported proben in the errors dict (might be | 120 // There is a entry for each imported proben in the errors dict (might be |
124 // empty) | 121 // empty) |
135 numWarnings = 0; | 132 numWarnings = 0; |
136 } | 133 } |
137 else { | 134 else { |
138 numWarnings = Object.keys(warnings).length; | 135 numWarnings = Object.keys(warnings).length; |
139 } | 136 } |
140 if (msg !== '200') { | 137 if (!data.success) { |
141 out.push('Der Import der Datei ' + this.fileName + | 138 out.push('Der Import der Datei ' + this.fileName + |
142 ' war nicht erfolgreich. Der Importvorgang konnte ' + | 139 ' war nicht erfolgreich. Der Importvorgang konnte ' + |
143 'aufgrund eines Fehlers im Server nicht beendet werden.'); | 140 'aufgrund eines Fehlers im Server nicht beendet werden.'); |
144 } | 141 } |
145 else { | 142 else { |