diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-06 14:58:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 14:58:02 +0200 |
commit | 6d688e89c1457a682fcc07e595e96014ada36add (patch) | |
tree | 78aa4666975adaf49064fffe58f991484a623310 /core/js/js.js | |
parent | ead4cb92b6e59455a3d5a344ba5b0cb367d2a7ae (diff) | |
parent | 5ae6d6281132c11b73448db064e9f4ce4582659c (diff) | |
download | nextcloud-server-6d688e89c1457a682fcc07e595e96014ada36add.tar.gz nextcloud-server-6d688e89c1457a682fcc07e595e96014ada36add.zip |
Merge pull request #1453 from nextcloud/do-not-reload-if-connection-lost
do not reload the page if the server is (temporarily) unreachable
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/core/js/js.js b/core/js/js.js index 67487ec979c..4b09cc49038 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -730,6 +730,17 @@ var OC={ }, /** + * Warn users that the connection to the server was lost temporarily + * + * This function is throttled to prevent stacked notfications. + * After 7sec the first notification is gone, then we can show another one + * if necessary. + */ + _ajaxConnectionLostHandler: _.throttle(function() { + OC.Notification.showTemporary(t('core', 'Connection to server lost')); + }, 7 * 1000, {trailing: false}), + + /** * Process ajax error, redirects to main page * if an error/auth error status was returned. */ @@ -742,7 +753,7 @@ var OC={ return; } - if (_.contains([0, 302, 303, 307, 401], xhr.status)) { + if (_.contains([302, 303, 307, 401], xhr.status)) { // sometimes "beforeunload" happens later, so need to defer the reload a bit setTimeout(function() { if (!self._userIsNavigatingAway && !self._reloadCalled) { @@ -752,6 +763,13 @@ var OC={ self._reloadCalled = true; } }, 100); + } else if(xhr.status === 0) { + // Connection lost (e.g. WiFi disconnected or server is down) + setTimeout(function() { + if (!self._userIsNavigatingAway && !self._reloadCalled) { + self._ajaxConnectionLostHandler(); + } + }, 100); } }, |