summaryrefslogtreecommitdiffstats
path: root/apps/files/js/files.js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-07-30 16:34:35 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-07-30 16:34:35 +0200
commit5699fff8893d38a3524013266a0b7e94be79bb31 (patch)
treeae72aa93fb2c37506cd3ee4216752b8f3b7a58ef /apps/files/js/files.js
parent22fd04eb4117e80341becce13190d5a8fcea98ca (diff)
parent009d1f3214f76cf1ae2318504449110104e159fb (diff)
downloadnextcloud-server-5699fff8893d38a3524013266a0b7e94be79bb31.tar.gz
nextcloud-server-5699fff8893d38a3524013266a0b7e94be79bb31.zip
Merge pull request #17175 from owncloud/add-download-feedback
Add loading spinner to download icon
Diffstat (limited to 'apps/files/js/files.js')
-rw-r--r--apps/files/js/files.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 034045ee40b..19cc3b26e44 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -271,8 +271,33 @@
FileList.scrollTo(getURLParameter('scrollto'));
}
*/
+ },
+
+ /**
+ * Handles the download and calls the callback function once the download has started
+ * - 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 call the callback
+ *
+ * @param {string} url download URL
+ * @param {function} callback function to call once the download has started
+ */
+ handleDownload: function(url, callback) {
+ var randomToken = Math.random().toString(36).substring(2),
+ checkForDownloadCookie = function() {
+ if (!OC.Util.isCookieSetToValue('ocDownloadStarted', randomToken)){
+ return false;
+ } else {
+ callback();
+ return true;
+ }
+ };
+
+ OC.redirect(url + '&downloadStartSecret=' + randomToken);
+ OC.Util.waitFor(checkForDownloadCookie, 500);
}
- }
+ };
Files._updateStorageStatisticsDebounced = _.debounce(Files._updateStorageStatistics, 250);
OCA.Files.Files = Files;