comparison app/view/window/GenProbenFromMessprogramm.js @ 812:188a9faf96e0

Added Errorhandling for AJAX-Requests, especially Authentication Issues.
author Dustin Demuth <dustin@intevation.de>
date Wed, 27 May 2015 16:59:23 +0200
parents 3bc19188fc3a
children 097d4edc2f00
comparison
equal deleted inserted replaced
811:5cdfe0ff1df3 812:188a9faf96e0
48 'X-OPENID-PARAMS': Lada.openIDParams 48 'X-OPENID-PARAMS': Lada.openIDParams
49 }, 49 },
50 jsonData: jsondata, 50 jsonData: jsondata,
51 success: function(response) { 51 success: function(response) {
52 var json = Ext.JSON.decode(response.responseText); 52 var json = Ext.JSON.decode(response.responseText);
53 console.log(json);
54 Ext.Msg.show({ 53 Ext.Msg.show({
55 title: i18n.getMsg('success'), 54 title: i18n.getMsg('success'),
56 autoScroll: true, 55 autoScroll: true,
57 msg: me.evalResponse(json), 56 msg: me.evalResponse(json),
58 buttons: Ext.Msg.OK, 57 buttons: Ext.Msg.OK,
59 }); 58 });
60 }, 59 },
61 failure: function(response) { 60 failure: function(response) {
62 // TODO handle Errors correctly, especially AuthenticationTimeouts
63 var json = Ext.JSON.decode(response.responseText); 61 var json = Ext.JSON.decode(response.responseText);
64 if (json) { 62 if (json) {
65 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ 63 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
66 formPanel.setMessages(json.errors, json.warnings); 64 formPanel.setMessages(json.errors, json.warnings);
67 } 65 }
66 // TODO Move this handling of 699 and 698 to a more central place!
67 // TODO i18n
68 if (json.message === "699" || json.message === "698") {
69 /* This is the unauthorized message with the authentication
70 * redirect in the data */
68 71
69 if(json.message){ 72 /* We decided to handle this with a redirect to the identity
70 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') 73 * provider. In which case we have no other option then to
74 * handle it here with relaunch. */
75 Ext.MessageBox.confirm('Erneutes Login erforderlich',
76 'Der Server konnte die Anfrage nicht authentifizieren.<br/>'+
77 'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
78 'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
79 'Soll die Anwendung jetzt neu geladen werden?', this.reload);
80 }
81 else if(json.message){
82 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
71 +' #'+json.message, 83 +' #'+json.message,
72 Lada.getApplication().bundle.getMsg(json.message)); 84 Lada.getApplication().bundle.getMsg(json.message));
73 } else { 85 } else {
74 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), 86 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
75 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); 87 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
76 } 88 }
77 } else { 89 } else {
78 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), 90 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
79 Lada.getApplication().bundle.getMsg('err.msg.response.body')); 91 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
80 } 92 }
81 } 93 }
82 }); 94 });
83 } 95 }
150 * Parse ServerResponse when Proben have been generated 162 * Parse ServerResponse when Proben have been generated
151 */ 163 */
152 evalResponse: function(response) { 164 evalResponse: function(response) {
153 var i18n = Lada.getApplication().bundle; 165 var i18n = Lada.getApplication().bundle;
154 var r = ''; 166 var r = '';
155 r += response.totalCount; 167 r += response.data.length;
156 r += ' ' + i18n.getMsg('probecreated'); 168 r += ' ' + i18n.getMsg('probecreated');
157 r += '<br/>'; 169 r += '<br/>';
158 r += i18n.getMsg('probeids'); 170 r += i18n.getMsg('probeids');
159 var i; 171 var i;
160 for (i in response.data){ 172 for (i in response.data){
161 r += '<br/>'; 173 r += '<br/>';
162 r += response.data[i].probeIdAlt 174 r += response.data[i].probeIdAlt
163 } 175 }
164 return r; 176 return r;
177 },
178
179 reload: function(btn) {
180 if (btn === 'yes') {
181 location.reload();
182 }
165 } 183 }
166 }); 184 });

http://lada.wald.intevation.org