From 8db1f0e927a2f906cf3b278dee6a978642844ebe Mon Sep 17 00:00:00 2001 From: Rajat Vig Date: Mon, 7 Dec 2015 09:06:07 -0800 Subject: [PATCH] Allow specifying item to use for actions in the actions directive Currently, the item passed to the 'allowed-actions' is aware of what the HTML referred to. This patch allows for passing in the item to use in the actions directive. This removes the need to pass in the item key as part of the allowed actions list thus removing the implicit binding of the controller/service/html. This also changes the list type attribute for the directive from the action-list-type to type for readability. Co-Authored-By: Kyle Olivo Partially-Implements: blueprint angularize-images-table Change-Id: Idc344153aa7582c485a5d9c6b3cccbf8ff788d7c --- .../action-list/actions.batch.mock.html | 2 +- .../widgets/action-list/actions.directive.js | 158 ++++++++++++------ .../action-list/actions.directive.spec.js | 126 +++++++------- .../widgets/action-list/actions.row.mock.html | 2 +- .../widgets/action-list/actions.service.js | 10 +- 5 files changed, 177 insertions(+), 121 deletions(-) diff --git a/horizon/static/framework/widgets/action-list/actions.batch.mock.html b/horizon/static/framework/widgets/action-list/actions.batch.mock.html index b2e7295cd8..b42918b3b3 100644 --- a/horizon/static/framework/widgets/action-list/actions.batch.mock.html +++ b/horizon/static/framework/widgets/action-list/actions.batch.mock.html @@ -1,2 +1,2 @@ - + diff --git a/horizon/static/framework/widgets/action-list/actions.directive.js b/horizon/static/framework/widgets/action-list/actions.directive.js index 566d5cc51e..326576100c 100644 --- a/horizon/static/framework/widgets/action-list/actions.directive.js +++ b/horizon/static/framework/widgets/action-list/actions.directive.js @@ -35,71 +35,111 @@ * * Attributes: * - * allowedActions: actions allowed that can be displayed - * actionListType: allow the buttons to be shown as a list or doropdown + * @param {string} type + * Type can be only be 'row' or 'batch'. + * 'batch' actions are rendered as a button group, 'row' is rendered as a button dropdown menu. + * 'batch' actions are typically used for actions across multiple items while + * 'row' actions are used per item. * - * `allowedActions` is a list of allowed actions on the service. - * It's an array of objects of the form: - * { template: {}, permissions: , callback: 'callback'} + * @param {string=} item + * The item to pass to the callback when using 'row' type. + * The variable is evaluated and passed as an argument when evaluating 'allowed'. + * 'item' is not used when row type is 'batch'. * - * `template` is an object that can be + * @param {function} allowed + * Returns an array of actions that can be performed on the item(s). + * When using 'row' type, the current 'item' will be passed to the function. + * When using 'batch' type, no arguments are provided. * - * {url: 'template.html'} the location of the template for the action button. - * Use this for complete extensibility and control over what is rendered. - * The template will be responsible for binding the callback and styling. + * This is an array that should contain objects with the following properties: + * { + * template: