aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/fileactions.js
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <hey@jancborchardt.net>2015-08-13 17:17:10 +0200
committerJan-Christoph Borchardt <hey@jancborchardt.net>2015-08-13 17:17:10 +0200
commit4e53b5922d9b3727502a13eb0c36844e69f498e3 (patch)
tree3e186d3743db98a0e81b3ae1993960b17a806830 /apps/files/js/fileactions.js
parentaf7ffe5492cd9d7254f16f09959c12fffbdc3d46 (diff)
parentc964eff17b1a7feeab794f6035a7beff8143ac85 (diff)
downloadnextcloud-server-4e53b5922d9b3727502a13eb0c36844e69f498e3.tar.gz
nextcloud-server-4e53b5922d9b3727502a13eb0c36844e69f498e3.zip
Merge pull request #18178 from owncloud/files-sidebar-actions
Sidebar file actions
Diffstat (limited to 'apps/files/js/fileactions.js')
-rw-r--r--apps/files/js/fileactions.js89
1 files changed, 82 insertions, 7 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 2edbed7f3c4..1d0493f2140 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -31,6 +31,10 @@
actions: {},
defaults: {},
icons: {},
+
+ /**
+ * @deprecated
+ */
currentFile: null,
/**
@@ -331,6 +335,9 @@
$trigger.addClass('open');
menu = new OCA.Files.FileActionsMenu();
+
+ context.$file.find('td.filename').append(menu.$el);
+
menu.$el.on('afterHide', function() {
context.$file.removeClass('mouseOver');
$trigger.removeClass('open');
@@ -338,7 +345,6 @@
});
context.$file.addClass('mouseOver');
- context.$file.find('td.filename').append(menu.$el);
menu.show(context);
},
@@ -401,11 +407,22 @@
// also set on global object for legacy apps
window.FileActions.currentFile = currentFile;
+ var callContext = _.extend({}, context);
+
+ if (!context.dir && context.fileList) {
+ callContext.dir = $file.attr('data-path') || context.fileList.getCurrentDirectory();
+ }
+
+ if (!context.fileInfoModel && context.fileList) {
+ callContext.fileInfoModel = context.fileList.getModelForFile(fileName);
+ if (!callContext.fileInfoModel) {
+ console.warn('No file info model found for file "' + fileName + '"');
+ }
+ }
+
actionSpec.action(
fileName,
- _.extend(context, {
- dir: $file.attr('data-path') || context.fileList.getCurrentDirectory()
- })
+ callContext
);
}
);
@@ -414,6 +431,63 @@
},
/**
+ * Trigger the given action on the given file.
+ *
+ * @param {string} actionName action name
+ * @param {OCA.Files.FileInfoModel} fileInfoModel file info model
+ * @param {OCA.Files.FileList} [fileList] file list, for compatibility with older action handlers [DEPRECATED]
+ *
+ * @return {boolean} true if the action handler was called, false otherwise
+ *
+ * @since 8.2
+ */
+ triggerAction: function(actionName, fileInfoModel, fileList) {
+ var actionFunc;
+ var actions = this.get(
+ fileInfoModel.get('mimetype'),
+ fileInfoModel.isDirectory() ? 'dir' : 'file',
+ fileInfoModel.get('permissions')
+ );
+
+ if (actionName) {
+ actionFunc = actions[actionName];
+ } else {
+ actionFunc = this.getDefault(
+ fileInfoModel.get('mimetype'),
+ fileInfoModel.isDirectory() ? 'dir' : 'file',
+ fileInfoModel.get('permissions')
+ );
+ }
+
+ if (!actionFunc) {
+ actionFunc = actions['Download'];
+ }
+
+ if (!actionFunc) {
+ return false;
+ }
+
+ var context = {
+ fileActions: this,
+ fileInfoModel: fileInfoModel,
+ dir: fileInfoModel.get('path')
+ };
+
+ var fileName = fileInfoModel.get('name');
+ this.currentFile = fileName;
+ // also set on global object for legacy apps
+ window.FileActions.currentFile = fileName;
+
+ if (fileList) {
+ // compatibility with action handlers that expect these
+ context.fileList = fileList;
+ context.$file = fileList.findFileEl(fileName);
+ }
+
+ actionFunc(fileName, context);
+ },
+
+ /**
* Display file actions for the given element
* @param parent "td" element of the file for which to display actions
* @param triggerEvent if true, triggers the fileActionsReady on the file
@@ -627,11 +701,12 @@
* Action handler function for file actions
*
* @callback OCA.Files.FileActions~actionHandler
- * @param {String} fileName name of the clicked file
+ * @param {String} fileName name of the file on which the action must be performed
* @param context context
* @param {String} context.dir directory of the file
- * @param context.$file jQuery element of the file
- * @param {OCA.Files.FileList} context.fileList the FileList instance on which the action occurred
+ * @param {OCA.Files.FileInfoModel} fileInfoModel file info model
+ * @param {Object} [context.$file] jQuery element of the file [DEPRECATED]
+ * @param {OCA.Files.FileList} [context.fileList] the FileList instance on which the action occurred [DEPRECATED]
* @param {OCA.Files.FileActions} context.fileActions the FileActions instance on which the action occurred
*/