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>
This commit is contained in:
parent
cb2b38516f
commit
d2728cbdc1
|
@ -256,6 +256,19 @@
|
|||
return undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -263,7 +276,7 @@
|
|||
* @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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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', '#');
|
||||
|
|
Loading…
Reference in New Issue