From a9540fe99044fd26f5c876438ae83697dbd1fe8e Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Thu, 2 Nov 2017 12:47:57 +0100 Subject: Hide summary file actions when a selected file does not match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When several files are selected and one of them can not be deleted the "Delete" file action is not shown in the summary. This commit extends that behaviour too to the other file actions in the summary ("Move or copy" and "Download"), so now an action is shown in the summary only if it can be executed on all the currently selected files. Signed-off-by: Daniel Calviño Sánchez --- apps/files/js/filelist.js | 20 ++++++++++++++++++++ apps/files/tests/js/filelistSpec.js | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 4790afcf4d0..f7bbb329532 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2822,10 +2822,30 @@ this.$el.find('#headerName a.name>span:first').text(selection); this.$el.find('#modified a>span:first').text(''); this.$el.find('table').addClass('multiselect'); + this.$el.find('.selectedActions .copy-move').toggleClass('hidden', !this.isSelectedCopiableOrMovable()); + this.$el.find('.selectedActions .download').toggleClass('hidden', !this.isSelectedDownloadable()); this.$el.find('.delete-selected').toggleClass('hidden', !this.isSelectedDeletable()); } }, + /** + * Check whether all selected files are copiable or movable + */ + isSelectedCopiableOrMovable: function() { + return _.reduce(this.getSelectedFiles(), function(copiableOrMovable, file) { + return copiableOrMovable && (file.permissions & OC.PERMISSION_UPDATE); + }, true); + }, + + /** + * Check whether all selected files are downloadable + */ + isSelectedDownloadable: function() { + return _.reduce(this.getSelectedFiles(), function(downloadable, file) { + return downloadable && (file.permissions & OC.PERMISSION_READ); + }, true); + }, + /** * Check whether all selected files are deletable */ diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 8bb188e3602..fd011474eb1 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -94,6 +94,7 @@ describe('OCA.Files.FileList tests', function() { '' + 'Name' + '' + '' + @@ -2024,6 +2025,28 @@ describe('OCA.Files.FileList tests', function() { }); }); describe('Selection overlay', function() { + it('show doesnt show the copy/move action if one or more files are not copiable/movable', function () { + fileList.setFiles(testFiles); + $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); + $('.select-all').click(); + expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false); + testFiles[0].permissions = OC.PERMISSION_READ; + $('.select-all').click(); + fileList.setFiles(testFiles); + $('.select-all').click(); + expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(true); + }); + it('show doesnt show the download action if one or more files are not downloadable', function () { + fileList.setFiles(testFiles); + $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); + $('.select-all').click(); + expect(fileList.$el.find('.selectedActions .download').hasClass('hidden')).toEqual(false); + testFiles[0].permissions = OC.PERMISSION_UPDATE; + $('.select-all').click(); + fileList.setFiles(testFiles); + $('.select-all').click(); + expect(fileList.$el.find('.selectedActions .download').hasClass('hidden')).toEqual(true); + }); it('show doesnt show the delete action if one or more files are not deletable', function () { fileList.setFiles(testFiles); $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_DELETE); -- cgit v1.2.3