diff 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
line wrap: on
line diff
--- a/app/view/window/ImportResponse.js	Mon Oct 31 10:05:10 2016 +0100
+++ b/app/view/window/ImportResponse.js	Mon Oct 31 13:54:00 2016 +0100
@@ -19,8 +19,9 @@
         var html;
         var download;
         var i18n = Lada.getApplication().bundle;
-        if (me.data && me.message) {
-            html = me.parseShortResponse(me.message, me.data);
+        var data = Ext.JSON.decode(me.data, true);
+        if (data) {
+            html = me.parseShortResponse(data);
         }
         else {
             html = 'Der Import der Datei ' + this.fileName +
@@ -49,18 +50,16 @@
             }
         }];
         this.callParent(arguments);
-        if (me.data && me.message) {
-            download = me.parseResponse(me.message, me.data);
+        if (data) {
+            download = me.parseResponse(data);
         }
     },
 
     /**
      * Parse the response and create a summary of the result
-     * @param msg
      * @param data
      */
-    parseShortResponse: function(msg, data) {
-        data = Ext.JSON.decode(data, true);
+    parseShortResponse: function(data) {
         var errors = data.data.errors;
         var warnings = data.data.warnings;
         var out = [];
@@ -81,7 +80,7 @@
         else {
             numWarnings = Object.keys(warnings).length;
         }
-        if (msg !== '200') {
+        if (!data.success) {
                 out.push('Der Import der Datei ' + this.fileName +
                     ' war nicht erfolgreich. Der Importvorgang konnte ' +
                     'aufgrund eines Fehlers im Server nicht beendet werden.');
@@ -112,11 +111,9 @@
 
     /**
      * Parse the Response
-     * @param msg the Lada-Erro-Code
      * @param data the payload of the response
      */
-    parseResponse: function(msg, data) {
-        data = Ext.JSON.decode(data, true);
+    parseResponse: function(data) {
         var errors = data.data.errors;
         var warnings = data.data.warnings;
         var out = [];
@@ -137,7 +134,7 @@
         else {
             numWarnings = Object.keys(warnings).length;
         }
-        if (msg !== '200') {
+        if (!data.success) {
                 out.push('Der Import der Datei ' + this.fileName +
                     ' war nicht erfolgreich. Der Importvorgang konnte ' +
                     'aufgrund eines Fehlers im Server nicht beendet werden.');

http://lada.wald.intevation.org