diff options
author | Azul <azul@riseup.net> | 2020-04-06 09:41:36 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-04-08 18:19:58 +0200 |
commit | d2728cbdc13e89f11dc2b8c48b6148d6e89d0c83 (patch) | |
tree | 38decca5dc041c9f31d2233f4b6d13cd87549d9c | |
parent | cb2b38516f2a5e98400e5ed2cbcd17ceeb269b9b (diff) | |
download | nextcloud-server-d2728cbdc13e89f11dc2b8c48b6148d6e89d0c83.tar.gz nextcloud-server-d2728cbdc13e89f11dc2b8c48b6148d6e89d0c83.zip |
refactor: fileActions.getCurrentDefaultFileAction()
fileActions.getCurrentDefaultFileAction() returns the default file action
for the currently selected file.
There were a number of places querying for the mime, type and permissions
of that file first to then query for the default action.
Signed-off-by: Azul <azul@riseup.net>
-rw-r--r-- | apps/files/js/fileactions.js | 15 | ||||
-rw-r--r-- | apps/files/js/fileactionsmenu.js | 6 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 9 | ||||
-rw-r--r-- | apps/files_sharing/js/public.js | 8 |
4 files changed, 20 insertions, 18 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 24f8279116d..404b6f1877e 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -257,13 +257,26 @@ }, /** + * Returns the default file action handler for the current file + * + * @return {OCA.Files.FileActions~actionSpec} action spec + * @since 8.2 + */ + getCurrentDefaultFileAction: function() { + var mime = this.getCurrentMimeType(); + var type = this.getCurrentType(); + var permissions = this.getCurrentPermissions(); + return this.getDefaultFileAction(mime,type, permissions); + }, + + /** * Returns the default file action handler for the given conditions * * @param {string} mime mime type * @param {string} type "dir" or "file" * @param {int} permissions permissions * - * @return {OCA.Files.FileActions~actionHandler} action handler + * @return {OCA.Files.FileActions~actionSpec} action spec * @since 8.2 */ getDefaultFileAction: function(mime, type, permissions) { diff --git a/apps/files/js/fileactionsmenu.js b/apps/files/js/fileactionsmenu.js index 16c4cc0d784..53dec693c1c 100644 --- a/apps/files/js/fileactionsmenu.js +++ b/apps/files/js/fileactionsmenu.js @@ -77,11 +77,7 @@ fileActions.getCurrentPermissions() ); - var defaultAction = fileActions.getDefaultFileAction( - fileActions.getCurrentMimeType(), - fileActions.getCurrentType(), - fileActions.getCurrentPermissions() - ); + var defaultAction = fileActions.getCurrentDefaultFileAction(); var items = _.filter(actions, function(actionSpec) { return !defaultAction || actionSpec.name !== defaultAction.name; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 9973c92c8ec..ce428064337 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -892,13 +892,10 @@ event.preventDefault(); } else if (!renaming) { this.fileActions.currentFile = $tr.find('td'); - var mime = this.fileActions.getCurrentMimeType(); - var type = this.fileActions.getCurrentType(); - var permissions = this.fileActions.getCurrentPermissions(); - var action = this.fileActions.getDefault(mime,type, permissions); - if (action) { + var spec = this.fileActions.getCurrentDefaultFileAction(); + if (spec && spec.action) { event.preventDefault(); - action(filename, { + spec.action(filename, { $file: $tr, fileList: this, fileActions: this.fileActions, diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 042cc6c056e..aba7bbc029e 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -113,8 +113,8 @@ OCA.Sharing.PublicApp = { // Show file preview if previewer is available, images are already handled by the template if (mimetype.substr(0, mimetype.indexOf('/')) !== 'image' && $('.publicpreview').length === 0) { // Trigger default action if not download TODO - var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); - if (typeof action !== 'undefined') { + var action = FileActions.getDefaultFileAction(mimetype, 'file', OC.PERMISSION_READ); + if (action && action.action) { action($('#filename').val()); } } @@ -204,10 +204,6 @@ OCA.Sharing.PublicApp = { var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments); if (hideDownload === 'true') { this.fileActions.currentFile = $tr.find('td'); - var mime = this.fileActions.getCurrentMimeType(); - var type = this.fileActions.getCurrentType(); - var permissions = this.fileActions.getCurrentPermissions(); - var action = this.fileActions.getDefault(mime, type, permissions); // Remove the link. This means that files without a default action fail hard $tr.find('a.name').attr('href', '#'); |