From 8ef1542ad02d71e6475d7de91a51498262c2dfec Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 12 Jun 2014 17:29:55 +0200 Subject: [PATCH] Fix public download link when zip download is disabled When zip download is disabled, the public download action defined in public.js is overridden by the one in fileactions.js because of the JS loading order. This quick fix prevents the override to happen when a download action is already defined. There are additional changes that were required to make the download action icon work when registered from the public page. --- apps/files/js/fileactions.js | 11 ++++++++--- apps/files_sharing/js/public.js | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 9fea7f5145e..21011a811c5 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -163,13 +163,18 @@ var FileActions = { }; $(document).ready(function () { + var hasDownloadAction = false; + var downloadScope; if ($('#allowZipDownload').val() == 1) { - var downloadScope = 'all'; + downloadScope = 'all'; } else { - var downloadScope = 'file'; + downloadScope = 'file'; } - if (typeof disableDownloadActions == 'undefined' || !disableDownloadActions) { + hasDownloadAction = FileActions.actions[downloadScope] && FileActions.actions[downloadScope].Download; + + // do not override download action if it exists (might have been registered by an app already) + if ((typeof disableDownloadActions == 'undefined' || !disableDownloadActions) && !hasDownloadAction) { FileActions.register(downloadScope, 'Download', OC.PERMISSION_READ, function () { return OC.imagePath('core', 'actions/download'); }, function (filename) { diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 730649c6378..0696f8f8b5a 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -25,13 +25,17 @@ $(document).ready(function() { window.location = $(tr).find('a.name').attr('href'); } }); - FileActions.register('file', 'Download', OC.PERMISSION_READ, '', function(filename) { + FileActions.register('file', 'Download', OC.PERMISSION_READ, function() { + return OC.imagePath('core', 'actions/download'); + }, function(filename) { var tr = FileList.findFileEl(filename); if (tr.length > 0) { window.location = $(tr).find('a.name').attr('href'); } }); - FileActions.register('dir', 'Download', OC.PERMISSION_READ, '', function(filename) { + FileActions.register('dir', 'Download', OC.PERMISSION_READ, function() { + return OC.imagePath('core', 'actions/download'); + }, function(filename) { var tr = FileList.findFileEl(filename); if (tr.length > 0) { window.location = $(tr).find('a.name').attr('href')+'&download';