diff app/controller/FilterResult.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 5cdfe0ff1df3
children af54733a6d48
line wrap: on
line diff
--- a/app/controller/FilterResult.js	Wed May 27 16:04:59 2015 +0200
+++ b/app/controller/FilterResult.js	Wed May 27 16:59:23 2015 +0200
@@ -136,11 +136,46 @@
                 var blob = new Blob([content],{type: 'text/plain'});
                 saveAs(blob, 'export.laf');
             },
-            failure: function() {
-                // TODO handle Errors correctly, especially AuthenticationTimeouts
-                Ext.Msg.create(i18n.getMsg('err.msg.generic.title'),
+            failure: function(response) {
+                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 */
+
+                        /* 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); //TODO Scope?
+                    }
+                    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(i18n.getMsg('err.msg.generic.title'),
+                            i18n.getMsg('err.msg.laf.filecreatefailed'));
+                    }
+                } else {
+                    Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
                     i18n.getMsg('err.msg.laf.filecreatefailed'));
+                }
             }
         });
+    },
+
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
     }
 });

http://lada.wald.intevation.org