diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2017-02-10 14:47:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-10 14:47:33 +0100 |
commit | 354bbd50a78b49d349c92b2bca584b9585369d05 (patch) | |
tree | 0d0075eb3b7ad8a904d225c723e372dc4536a22c | |
parent | b4ade766656a2032f33d56eb4a0f17bb128af722 (diff) | |
parent | 01963b4d7226c1768d3f95dc75eb01ed715706c2 (diff) | |
download | nextcloud-server-354bbd50a78b49d349c92b2bca584b9585369d05.tar.gz nextcloud-server-354bbd50a78b49d349c92b2bca584b9585369d05.zip |
Merge pull request #3371 from m3ntalsp00n/reload_countdown
showUpdate funciton allows updated messages
-rw-r--r-- | core/js/js.js | 38 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 6 |
2 files changed, 40 insertions, 4 deletions
diff --git a/core/js/js.js b/core/js/js.js index 3651635541a..5ef5c72f625 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -780,8 +780,18 @@ var OCP = {}, // sometimes "beforeunload" happens later, so need to defer the reload a bit setTimeout(function() { if (!self._userIsNavigatingAway && !self._reloadCalled) { - OC.Notification.show(t('core', 'Problem loading page, reloading in 5 seconds')); - setTimeout(OC.reload, 5000); + var timer = 0; + var seconds = 5; + var interval = setInterval( function() { + OC.Notification.showUpdate(n('core', 'Problem loading page, reloading in %n second', 'Problem loading page, reloading in %n seconds', seconds - timer)); + if (timer >= seconds) { + clearInterval(interval); + OC.reload(); + } + timer++; + }, 1000 // 1 second interval + ); + // only call reload once self._reloadCalled = true; } @@ -1174,6 +1184,30 @@ OC.Notification={ }, /** + * Updates (replaces) a sanitized notification. + * + * @param {string} text Message to display + * @return {jQuery} JQuery element for notificaiton row + */ + showUpdate: function(text) { + var $notification = $('#notification'); + // sanitise + var $html = $('<div/>').text(text).html(); + + // new notification + if (text && $notification.find('.row').length == 0) { + return this.showHtml($html); + } + + var $row = $('<div class="row"></div>').prepend($html); + + // just update html in notification + $notification.html($row); + + return $row; + }, + + /** * Shows a notification that disappears after x seconds, default is * 7 seconds * diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index d83c0cd9a38..3380b6be420 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -1000,7 +1000,7 @@ describe('Core base tests', function() { describe('global ajax errors', function() { var reloadStub, ajaxErrorStub, clock; var notificationStub; - var waitTimeMs = 6000; + var waitTimeMs = 6500; var oldCurrentUser; beforeEach(function() { @@ -1075,10 +1075,12 @@ describe('Core base tests', function() { it('displays notification', function() { var xhr = { status: 401 }; + notificationUpdateStub = sinon.stub(OC.Notification, 'showUpdate'); + $(document).trigger(new $.Event('ajaxError'), xhr); clock.tick(waitTimeMs); - expect(notificationStub.calledOnce).toEqual(true); + expect(notificationUpdateStub.notCalled).toEqual(false); }); it('shows a temporary notification if the connection is lost', function() { var xhr = { status: 0 }; |