diff 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
line wrap: on
line diff
--- a/app/view/window/GenProbenFromMessprogramm.js	Wed May 27 16:04:59 2015 +0200
+++ b/app/view/window/GenProbenFromMessprogramm.js	Wed May 27 16:59:23 2015 +0200
@@ -50,7 +50,6 @@
                     jsonData: jsondata,
                     success: function(response) {
                         var json = Ext.JSON.decode(response.responseText);
-                        console.log(json);
                         Ext.Msg.show({
                             title: i18n.getMsg('success'),
                             autoScroll: true,
@@ -59,23 +58,36 @@
                         });
                     },
                     failure: function(response) {
-                    // TODO handle Errors correctly, especially AuthenticationTimeouts
                         var json = Ext.JSON.decode(response.responseText);
                         if (json) {
                             if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
                                 formPanel.setMessages(json.errors, json.warnings);
                             }
+                            // TODO Move this handling of 699 and 698 to a more central place!
+                            // TODO i18n
+                            if (json.message === "699" || json.message === "698") {
+                                /* This is the unauthorized message with the authentication
+                                    * redirect in the data */
 
-                            if(json.message){
-                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
+                                /* We decided to handle this with a redirect to the identity
+                                    * provider. In which case we have no other option then to
+                                    * handle it here with relaunch. */
+                                Ext.MessageBox.confirm('Erneutes Login erforderlich',
+                                    'Der Server konnte die Anfrage nicht authentifizieren.<br/>'+
+                                    'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
+                                    'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
+                                    'Soll die Anwendung jetzt neu geladen werden?', this.reload);
+                            }
+                            else if(json.message){
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
                                     +' #'+json.message,
                                     Lada.getApplication().bundle.getMsg(json.message));
                             } else {
-                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
                                     Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
                             }
                         } else {
-                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
                                 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
                         }
                     }
@@ -152,7 +164,7 @@
     evalResponse: function(response) {
         var i18n = Lada.getApplication().bundle;
         var r = '';
-            r += response.totalCount;
+            r += response.data.length;
             r += ' ' + i18n.getMsg('probecreated');
             r += '<br/>';
             r += i18n.getMsg('probeids');
@@ -162,5 +174,11 @@
                 r += response.data[i].probeIdAlt
             }
         return r;
+    },
+
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
     }
 });

http://lada.wald.intevation.org