Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-20 18:01:34 +0400
committerVincent Petry <pvince81@owncloud.com>2014-05-30 12:06:29 +0400
commitef59c69dc822c9ff69c564c41e0dfdce142b9cdf (patch)
treea99667ab22daba65cbbd77ac591fccac234f06eb /apps/files
parentfa32243d84e1801c379a5e8956ba2f3de236c718 (diff)
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')
-rw-r--r--apps/files/js/app.js19
-rw-r--r--apps/files/js/fileactions.js69
-rw-r--r--apps/files/js/filelist.js21
-rw-r--r--apps/files/tests/js/appSpec.js53
-rw-r--r--apps/files/tests/js/fileactionsSpec.js7
-rw-r--r--apps/files/tests/js/filelistSpec.js5
6 files changed, 132 insertions, 42 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index 6d8a9788d97..6ccf5135000 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -24,20 +24,27 @@
initialize: function() {
this.navigation = new OCA.Files.Navigation($('#app-navigation'));
- // TODO: ideally these should be in a separate class / app (the embedded "all files" app)
- this.fileActions = OCA.Files.FileActions.clone();
+ var fileActions = new OCA.Files.FileActions();
+ // default actions
+ fileActions.registerDefaultActions();
+ // legacy actions
+ fileActions.merge(window.FileActions);
+ // regular actions
+ fileActions.merge(OCA.Files.fileActions);
+
this.files = OCA.Files.Files;
+ // TODO: ideally these should be in a separate class / app (the embedded "all files" app)
this.fileList = new OCA.Files.FileList(
$('#app-content-files'), {
scrollContainer: $('#app-content'),
dragOptions: dragOptions,
- folderDropOptions: folderDropOptions
+ folderDropOptions: folderDropOptions,
+ fileActions: fileActions,
+ allowLegacyActions: true
}
);
this.files.initialize();
- this.fileActions.registerDefaultActions();
- this.fileList.setFileActions(this.fileActions);
// for backward compatibility, the global FileList will
// refer to the one of the "files" view
@@ -146,7 +153,7 @@
})();
$(document).ready(function() {
- // wait for other apps/extensions to register their event handlers
+ // wait for other apps/extensions to register their event handlers and file actions
// in the "ready" clause
_.defer(function() {
OCA.Files.App.initialize();
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);
+ };
+})();
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index e1cbfc38566..52d4c8ba3fe 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -125,7 +125,7 @@
this.$container = options.scrollContainer || $(window);
this.$table = $el.find('table:first');
this.$fileList = $el.find('#fileList');
- this.fileActions = OCA.Files.FileActions;
+ this._initFileActions(options.fileActions);
this.files = [];
this._selectedFiles = {};
this._selectionSummary = new OCA.Files.FileSummary();
@@ -168,6 +168,14 @@
this.$container.on('scroll', _.bind(this._onScroll, this));
},
+ _initFileActions: function(fileActions) {
+ this.fileActions = fileActions;
+ if (!this.fileActions) {
+ this.fileActions = new OCA.Files.FileActions();
+ this.fileActions.registerDefaultActions();
+ }
+ },
+
/**
* Event handler for when the URL changed
*/
@@ -248,6 +256,8 @@
var action = this.fileActions.getDefault(mime,type, permissions);
if (action) {
event.preventDefault();
+ // also set on global object for legacy apps
+ window.FileActions.currentFile = this.fileActions.currentFile;
action(filename, {
$file: $tr,
fileList: this,
@@ -792,15 +802,6 @@
},
/**
- * Sets the file actions handler.
- *
- * @param fileActions FileActions handler
- */
- setFileActions: function(fileActions) {
- this.fileActions = fileActions;
- },
-
- /**
* Sets the current directory name and updates the breadcrumb.
* @param targetDir directory to display
* @param changeUrl true to also update the URL, false otherwise (default)
diff --git a/apps/files/tests/js/appSpec.js b/apps/files/tests/js/appSpec.js
index 0e9abad6989..a9bbab03ecb 100644
--- a/apps/files/tests/js/appSpec.js
+++ b/apps/files/tests/js/appSpec.js
@@ -41,6 +41,10 @@ describe('OCA.Files.App tests', function() {
'</div>'
);
+ window.FileActions = new OCA.Files.FileActions();
+ OCA.Files.legacyFileActions = window.FileActions;
+ OCA.Files.fileActions = new OCA.Files.FileActions();
+
pushStateStub = sinon.stub(OC.Util.History, 'pushState');
parseUrlQueryStub = sinon.stub(OC.Util.History, 'parseUrlQuery');
parseUrlQueryStub.returns({});
@@ -51,8 +55,6 @@ describe('OCA.Files.App tests', function() {
App.navigation = null;
App.fileList = null;
App.files = null;
- App.fileActions.clear();
- App.fileActions = null;
pushStateStub.restore();
parseUrlQueryStub.restore();
@@ -64,6 +66,53 @@ describe('OCA.Files.App tests', function() {
expect(App.fileList.fileActions.actions.all).toBeDefined();
expect(App.fileList.$el.is('#app-content-files')).toEqual(true);
});
+ it('merges the legacy file actions with the default ones', function() {
+ var legacyActionStub = sinon.stub();
+ var actionStub = sinon.stub();
+ // legacy action
+ window.FileActions.register(
+ 'all',
+ 'LegacyTest',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ legacyActionStub
+ );
+ // legacy action to be overwritten
+ window.FileActions.register(
+ 'all',
+ 'OverwriteThis',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ legacyActionStub
+ );
+
+ // regular file actions
+ OCA.Files.fileActions.register(
+ 'all',
+ 'RegularTest',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub
+ );
+
+ // overwrite
+ OCA.Files.fileActions.register(
+ 'all',
+ 'OverwriteThis',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub
+ );
+
+ App.initialize();
+
+ var actions = App.fileList.fileActions.actions;
+ expect(actions.all.OverwriteThis.action).toBe(actionStub);
+ expect(actions.all.LegacyTest.action).toBe(legacyActionStub);
+ expect(actions.all.RegularTest.action).toBe(actionStub);
+ // default one still there
+ expect(actions.dir.Open.action).toBeDefined();
+ });
});
describe('URL handling', function() {
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index edd7e343884..fa634da08a2 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -21,7 +21,7 @@
describe('OCA.Files.FileActions tests', function() {
var $filesTable, fileList;
- var FileActions = OCA.Files.FileActions;
+ var FileActions;
beforeEach(function() {
// init horrible parameters
@@ -31,10 +31,11 @@ describe('OCA.Files.FileActions tests', function() {
// dummy files table
$filesTable = $body.append('<table id="filestable"></table>');
fileList = new OCA.Files.FileList($('#testArea'));
- FileActions.registerDefaultActions(fileList);
+ FileActions = new OCA.Files.FileActions();
+ FileActions.registerDefaultActions();
});
afterEach(function() {
- FileActions.clear();
+ FileActions = null;
fileList = undefined;
$('#dir, #permissions, #filestable').remove();
});
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 739ae599c65..a197fd5722c 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -21,7 +21,6 @@
describe('OCA.Files.FileList tests', function() {
var testFiles, alertStub, notificationStub, fileList;
- var FileActions = OCA.Files.FileActions;
/**
* Generate test file data
@@ -117,15 +116,11 @@ describe('OCA.Files.FileList tests', function() {
}];
fileList = new OCA.Files.FileList($('#app-content-files'));
- FileActions.clear();
- FileActions.registerDefaultActions(fileList);
- fileList.setFileActions(FileActions);
});
afterEach(function() {
testFiles = undefined;
fileList = undefined;
- FileActions.clear();
notificationStub.restore();
alertStub.restore();
});