aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js/fileactions.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-20 16:01:34 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-30 10:06:29 +0200
commitef59c69dc822c9ff69c564c41e0dfdce142b9cdf (patch)
treea99667ab22daba65cbbd77ac591fccac234f06eb /apps/files/js/fileactions.js
parentfa32243d84e1801c379a5e8956ba2f3de236c718 (diff)
downloadnextcloud-server-ef59c69dc822c9ff69c564c41e0dfdce142b9cdf.tar.gz
nextcloud-server-ef59c69dc822c9ff69c564c41e0dfdce142b9cdf.zip
Distinguish legacy file actions from regular file actions
Legacy file actions are registered by legacy apps through window.FileActions.register(). These actions can only be used by the main file list ("all files") because legacy apps can only deal with a single list / container. New file actions of compatible apps must be registered through OCA.Files.fileActions. These will be used for other lists like the sharing overview. Fixed versions and sharing actions to use OCA.Files.fileActions, which makes them available in the sharing overview list.
Diffstat (limited to 'apps/files/js/fileactions.js')
-rw-r--r--apps/files/js/fileactions.js69
1 files changed, 53 insertions, 16 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index a12b1f03423..8cee037e294 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -11,11 +11,40 @@
/* global trashBinApp */
(function() {
- var FileActions = {
+ /**
+ * Construct a new FileActions instance
+ */
+ var FileActions = function() {
+ this.initialize();
+ }
+ FileActions.prototype = {
actions: {},
defaults: {},
icons: {},
currentFile: null,
+ initialize: function() {
+ this.clear();
+ },
+ /**
+ * Merges the actions from the given fileActions into
+ * this instance.
+ *
+ * @param fileActions instance of OCA.Files.FileActions
+ */
+ merge: function(fileActions) {
+ var self = this;
+ // merge first level to avoid unintended overwriting
+ _.each(fileActions.actions, function(sourceMimeData, mime) {
+ var targetMimeData = self.actions[mime];
+ if (!targetMimeData) {
+ targetMimeData = {};
+ }
+ self.actions[mime] = _.extend(targetMimeData, sourceMimeData);
+ });
+
+ this.defaults = _.extend(this.defaults, fileActions.defaults);
+ this.icons = _.extend(this.icons, fileActions.icons);
+ },
register: function (mime, name, permissions, icon, action, displayName) {
if (!this.actions[mime]) {
this.actions[mime] = {};
@@ -31,18 +60,6 @@
this.actions[mime][name]['displayName'] = displayName;
this.icons[name] = icon;
},
- /**
- * Clones the current file actions handler including the already
- * registered actions.
- */
- clone: function() {
- var fileActions = _.extend({}, this);
- // need to deep copy the actions as well
- fileActions.actions = _.extend({}, this.actions);
- fileActions.defaults = _.extend({}, this.defaults);
- //fileActions.icons = _.extend({}, this.icons);
- return fileActions;
- },
clear: function() {
this.actions = {};
this.defaults = {};
@@ -137,6 +154,9 @@
event.preventDefault();
self.currentFile = event.data.elem;
+ // also set on global object for legacy apps
+ window.FileActions.currentFile = self.currentFile;
+
var file = self.getCurrentFile();
var $tr = $(this).closest('tr');
@@ -276,8 +296,25 @@
};
OCA.Files.FileActions = FileActions;
-})();
-// for backward compatibility
-window.FileActions = OCA.Files.FileActions;
+ // global file actions to be used by all lists
+ OCA.Files.fileActions = new OCA.Files.FileActions();
+ OCA.Files.legacyFileActions = new OCA.Files.FileActions();
+
+ // for backward compatibility
+ //
+ // legacy apps are expecting a stateful global FileActions object to register
+ // their actions on. Since legacy apps are very likely to break with other
+ // FileList views than the main one ("All files"), actions registered
+ // through window.FileActions will be limited to the main file list.
+ window.FileActions = OCA.Files.legacyFileActions;
+ window.FileActions.register = function (mime, name, permissions, icon, action, displayName) {
+ console.warn('FileActions.register() is deprecated, please use OCA.Files.fileActions.register() instead');
+ OCA.Files.FileActions.prototype.register.call(window.FileActions, mime, name, permissions, icon, action, displayName);
+ };
+ window.FileActions.setDefault = function (mime, name) {
+ console.warn('FileActions.setDefault() is deprecated, please use OCA.Files.fileActions.setDefault() instead');
+ OCA.Files.FileActions.prototype.setDefault.call(window.FileActions, mime, name);
+ };
+})();