aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/fileactions.js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-06-29 15:20:47 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-07-07 13:56:49 +0200
commite557fe0aabe9e1e97249aa5446eef30c804da79f (patch)
tree037e1d9ec9f10f3b901892d08f8beec2c9b6bd6b /apps/files/js/fileactions.js
parent5a528214b8c6326590c8ff6784187c4191d64f56 (diff)
downloadnextcloud-server-e557fe0aabe9e1e97249aa5446eef30c804da79f.tar.gz
nextcloud-server-e557fe0aabe9e1e97249aa5446eef30c804da79f.zip
Add proper download started feedback
* this code adds a cookie when a special get parameter is set * the content of this get parameter is used as value for the cookie * the cookie expires after 20 seconds * the JS code checks every 500 milliseconds for the cookie -> if the cookie is set the request returned and the download is started
Diffstat (limited to 'apps/files/js/fileactions.js')
-rw-r--r--apps/files/js/fileactions.js29
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index bf529aeb3e8..6678c2d5b34 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -491,14 +491,31 @@
var sourceImage = icon.attr('src');
icon.attr('src', sourceImage.replace('actions/download.svg', 'loading-small.gif'));
- // TODO proper detection of "download has started"
- setTimeout(function(){
- icon.attr('src', sourceImage);
- downloadFileaction.removeClass('disabled');
- }, 2000);
+ var randomString = Math.random().toString(36).substring(2);
+
+ var isCookieSet = function(name, value) {
+ var cookies = document.cookie.split(';');
+ for (var i=0; i < cookies.length; i++) {
+ var cookie = cookies[i].split('=');
+ if (cookie[0].trim() === name && cookie[1].trim() === value) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ var checkForDownloadCookie = function() {
+ if (!isCookieSet('ocDownloadStarted', randomString)){
+ setTimeout(checkForDownloadCookie, 500);
+ } else {
+ icon.attr('src', sourceImage);
+ downloadFileaction.removeClass('disabled');
+ }
+ };
if (url) {
- OC.redirect(url);
+ OC.redirect(url + '&downloadStartSecret=' + randomString);
+ checkForDownloadCookie();
}
}, t('files', 'Download'));
}