diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-07-07 15:16:37 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-07-07 15:16:37 +0200 |
commit | 3f5aa27d494d56217980195534ee999b5e473ca5 (patch) | |
tree | 619a559284179afbb680a6f08d8a6b3bf8855c94 /apps/files/js/files.js | |
parent | 3d8297c25473c5496fa7e27f600f1e23053df2fc (diff) | |
download | nextcloud-server-3f5aa27d494d56217980195534ee999b5e473ca5.tar.gz nextcloud-server-3f5aa27d494d56217980195534ee999b5e473ca5.zip |
refactoring into proper methods
Diffstat (limited to 'apps/files/js/files.js')
-rw-r--r-- | apps/files/js/files.js | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 44868e78bd0..de372a71f74 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -276,8 +276,39 @@ FileList.scrollTo(getURLParameter('scrollto')); } */ + }, + + /** + * Replaces the download icon with a loading spinner and returns token for the download check: + * - browser sends download request and adds parameter with a token + * - server notices this token and adds a set cookie to the download response + * - browser now adds this cookie for the domain + * - JS periodically checks for this cookie and then knows when the download has started to remove all the user feedback + * + * @param downloadButtonElement download fileaction + * @returns {string} random token that needs to be set as cookie + */ + handleDownloadSpinner: function(downloadButtonElement) { + var randomString = Math.random().toString(36).substring(2), + icon = downloadButtonElement.find('img'), + sourceImage = icon.attr('src'), + checkForDownloadCookie = function() { + if (!OC.Util.isCookieSetToValue('ocDownloadStarted', randomString)){ + return false; + } else { + icon.attr('src', sourceImage); + downloadButtonElement.removeClass('disabled'); + return true; + } + }; + + downloadButtonElement.addClass('disabled'); + icon.attr('src', sourceImage.replace('actions/download.svg', 'loading-small.gif')); + OC.Util.waitFor(checkForDownloadCookie, 500); + + return randomString; } - } + }; Files._updateStorageStatisticsDebounced = _.debounce(Files._updateStorageStatistics, 250); OCA.Files.Files = Files; |