[Pkg-owncloud-commits] [owncloud] 82/107: Bring back file delete action text to be based on context

David Prévot taffit at moszumanska.debian.org
Thu Dec 17 19:40:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 5da3d5616cdca093ccc5a191242ed3cc37ac2d39
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Fri Dec 11 15:14:30 2015 +0100

    Bring back file delete action text to be based on context
    
    For received shares, the delete action becomes "Unshare" and for
    personal mounts it becomes "Disconnect storage".
    
    This also makes it possible from now on to pass a function to a file
    action's "displayName" attribute.
---
 apps/files/js/fileactions.js               | 26 +++++++++++++++++++++++---
 apps/files/js/fileactionsmenu.js           |  8 ++++++++
 apps/files/tests/js/fileactionsmenuSpec.js | 20 ++++++++++++++++++--
 3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 079c533..9947b3e 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -619,7 +619,16 @@
 
 			this.registerAction({
 				name: 'Delete',
-				displayName: t('files', 'Delete'),
+				displayName: function(context) {
+					var mountType = context.$file.attr('data-mounttype');
+					var deleteTitle = t('files', 'Delete');
+					if (mountType === 'external-root') {
+						deleteTitle = t('files', 'Disconnect storage');
+					} else if (mountType === 'shared-root') {
+						deleteTitle = t('files', 'Unshare');
+					}
+					return deleteTitle;
+				},
 				mime: 'all',
 				order: 1000,
 				// permission is READ because we show a hint instead if there is no permission
@@ -670,8 +679,9 @@
 	 * @typedef {Object} OCA.Files.FileAction
 	 *
 	 * @property {String} name identifier of the action
-	 * @property {String} displayName display name of the action, defaults
-	 * to the name given in name property
+	 * @property {(String|OCA.Files.FileActions~displayNameFunction)} displayName
+	 * display name string for the action, or function that returns the display name.
+	 * Defaults to the name given in name property
 	 * @property {String} mime mime type
 	 * @property {int} permissions permissions
 	 * @property {(Function|String)} icon icon path to the icon or function
@@ -705,6 +715,16 @@
 	 */
 
 	/**
+	 * Display name function for actions.
+	 * The function returns the display name of the action using
+	 * the given context information..
+	 *
+	 * @callback OCA.Files.FileActions~displayNameFunction
+	 * @param {OCA.Files.FileActionContext} context action context
+	 * @return {String} display name
+	 */
+
+	/**
 	 * Action handler function for file actions
 	 *
 	 * @callback OCA.Files.FileActions~actionHandler
diff --git a/apps/files/js/fileactionsmenu.js b/apps/files/js/fileactionsmenu.js
index 67cbb48..9e51d8f 100644
--- a/apps/files/js/fileactionsmenu.js
+++ b/apps/files/js/fileactionsmenu.js
@@ -81,6 +81,7 @@
 		 * Renders the menu with the currently set items
 		 */
 		render: function() {
+			var self = this;
 			var fileActions = this._context.fileActions;
 			var actions = fileActions.getActions(
 				fileActions.getCurrentMimeType(),
@@ -100,6 +101,13 @@
 					(!defaultAction || actionSpec.name !== defaultAction.name)
 				);
 			});
+			items = _.map(items, function(item) {
+				if (_.isFunction(item.displayName)) {
+					item = _.extend({}, item);
+					item.displayName = item.displayName(self._context);
+				}
+				return item;
+			});
 			items = items.sort(function(actionA, actionB) {
 				var orderA = actionA.order || 0;
 				var orderB = actionB.order || 0;
diff --git a/apps/files/tests/js/fileactionsmenuSpec.js b/apps/files/tests/js/fileactionsmenuSpec.js
index dee5424..cb51b25 100644
--- a/apps/files/tests/js/fileactionsmenuSpec.js
+++ b/apps/files/tests/js/fileactionsmenuSpec.js
@@ -20,7 +20,7 @@
 */
 
 describe('OCA.Files.FileActionsMenu tests', function() {
-	var fileList, fileActions, menu, actionStub, $tr;
+	var fileList, fileActions, menu, actionStub, menuContext, $tr;
 
 	beforeEach(function() {
 		// init horrible parameters
@@ -80,7 +80,7 @@ describe('OCA.Files.FileActionsMenu tests', function() {
 		};
 		$tr = fileList.add(fileData);
 
-		var menuContext = {
+		menuContext = {
 			$file: $tr,
 			fileList: fileList,
 			fileActions: fileActions,
@@ -189,6 +189,22 @@ describe('OCA.Files.FileActionsMenu tests', function() {
 			var yactionIndex = menu.$el.find('a[data-action=Yaction]').closest('li').index();
 			expect(wactionIndex).toBeLessThan(yactionIndex);
 		});
+		it('calls displayName function', function() {
+			var displayNameStub = sinon.stub().returns('Test');
+
+			fileActions.registerAction({
+				name: 'Something',
+				displayName: displayNameStub,
+				mime: 'text/plain',
+				permissions: OC.PERMISSION_ALL
+			});
+
+			menu.render();
+
+			expect(displayNameStub.calledOnce).toEqual(true);
+			expect(displayNameStub.calledWith(menuContext)).toEqual(true);
+			expect(menu.$el.find('a[data-action=Something]').text()).toEqual('Test');
+		});
 	});
 
 	describe('action handler', function() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list