diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2021-05-12 10:53:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 10:53:58 +0200 |
commit | 6c741724fbdfc71762407298738c330e5ceb9b88 (patch) | |
tree | e7f0847fa0105f56fd17d7e0da1a943fa570b48e | |
parent | a2a96466fc951c6739ee965c9d93b984aea9307e (diff) | |
parent | 96515d7338006a99b853c899708d7f6667bd43fd (diff) | |
download | nextcloud-server-6c741724fbdfc71762407298738c330e5ceb9b88.tar.gz nextcloud-server-6c741724fbdfc71762407298738c330e5ceb9b88.zip |
Merge pull request #26941 from nextcloud/enh/register-multiselect-fileactions
Allow apps to register a file action for multiselect
-rw-r--r-- | apps/files/js/app.js | 3 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 33 |
2 files changed, 32 insertions, 4 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 8015f395b74..1a7049832ca 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -97,17 +97,20 @@ name: 'copyMove', displayName: t('files', 'Move or copy'), iconClass: 'icon-external', + order: 10, }, { name: 'download', displayName: t('files', 'Download'), iconClass: 'icon-download', + order: 10, }, OCA.Files.FileList.MultiSelectMenuActions.ToggleSelectionModeAction, { name: 'delete', displayName: t('files', 'Delete'), iconClass: 'icon-delete', + order: 99, }, ], sorting: { diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 11d0bc4511d..b981785db40 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -330,9 +330,7 @@ this.multiSelectMenuItems[i] = this.multiSelectMenuItems[i](this); } } - this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(this.multiSelectMenuItems); - this.fileMultiSelectMenu.render(); - this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el); + this._updateMultiSelectFileActions() } if (options.sorting) { @@ -516,7 +514,7 @@ multiSelectMenuClick: function (ev, action) { var actionFunction = _.find(this.multiSelectMenuItems, function (item) {return item.name === action;}).action; if (actionFunction) { - actionFunction(ev); + actionFunction(this.getSelectedFiles()); return; } switch (action) { @@ -1369,6 +1367,32 @@ }, /** + * Register action for multiple selected files + * + * @param {OCA.Files.FileAction} fileAction object + * The callback of FileAction will be called with an array of files that are currently selected + */ + registerMultiSelectFileAction: function(fileAction) { + if (typeof this.multiSelectMenuItems === 'undefined') { + return; + } + this.multiSelectMenuItems.push(fileAction) + this._updateMultiSelectFileActions() + }, + + _updateMultiSelectFileActions: function() { + if (typeof this.multiSelectMenuItems === 'undefined') { + return; + } + this.fileMultiSelectMenu = new OCA.Files.FileMultiSelectMenu(this.multiSelectMenuItems.sort(function(a, b) { + return a.order > b.order + })); + this.fileMultiSelectMenu.render(); + this.$el.find('.selectedActions .filesSelectMenu').remove(); + this.$el.find('.selectedActions').append(this.fileMultiSelectMenu.$el); + }, + + /** * Sets the files to be displayed in the list. * This operation will re-render the list and update the summary. * @param filesArray array of file data (map) @@ -3785,6 +3809,7 @@ return t('files', 'Select file range'); }, iconClass: 'icon-fullscreen', + order: 15, action: function() { fileList._onClickToggleSelectionMode(); }, |