
# HG changeset patch
# User Martin Taal <martin.taal@openbravo.com>
# Date 1479654693 -3600
# Node ID ca4c3492070301e680b1a0d8cb9408f10d2d7963
# Parent  e6dc9d4f5d1eefb6afed38883bae4118499cc6f6
Fixes issue 34587: Ping service fail method not called in case of multiple servers
Also call success in case of multi-server ping failure, as ping failure is sometimes
expected and then updates server status

diff -r e6dc9d4f5d1e -r ca4c34920703 web/org.openbravo.mobile.core/source/data/ob-requestrouter.js
--- a/web/org.openbravo.mobile.core/source/data/ob-requestrouter.js	Tue Nov 15 15:28:04 2016 +0100
+++ b/web/org.openbravo.mobile.core/source/data/ob-requestrouter.js	Sun Nov 20 16:11:33 2016 +0100
@@ -505,13 +505,29 @@
         }
         if (!ajaxRequest.origFail) {
           ajaxRequest.origFail = ajaxRequest.fail;
-
         }
         ajaxRequest.fail = function (inSender, inResponse) {
           server.changeOnlineStatus(false, ajaxRequest.ignoreForConnectionStatus);
-          // offline is controlled by the server of the webpos
+          // ajaxRequest is in the scope of the implementation function
+          // so there is only one instance even if multiple servers are offline
+          if (ajaxRequest.done) {
+            return;
+          }
+          ajaxRequest.done = true;
+          // in case of one server then real offline 
           if (OB.RR.RequestRouter.servers.length === 1) {
             ajaxRequest.origFail(inSender, inResponse);
+            ajaxRequest.origFail = null;
+          } else if (ajaxRequest.origSuccess) {
+            // in case of multiserver then don't do real offline
+            // just call success, status of server has been set anyway
+            ajaxRequest.origSuccess(null, {
+              response: {
+                contextInfo: null,
+                result: '0',
+                status: 0
+              }
+            });
           }
         };
 
@@ -545,7 +561,7 @@
           'withCredentials': true
         };
 
-        ajaxRequest.go(ajaxRequest.data).response('success').error('fail');
+        new enyo.Ajax(ajaxRequest).go(ajaxRequest.data).response('success').error('fail');
       });
     }
   };

