Skip to content

Commit 37022d3

Browse files
authored
Merge pull request #323 from jeff-phillips-18/list-view
Add ability to customize ListView action buttons
2 parents 6f8f2cc + b9bf075 commit 37022d3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/views/listview/list-view-directive.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
* <ul style='list-style-type: none'>
2929
* <li>.name - (String) The name of the action, displayed on the button
3030
* <li>.title - (String) Optional title, used for the tooltip
31+
* <li>.class - (String) Optional class to add to the action button
32+
* <li>.include - (String) Optional include src for the button. Used for custom button layouts (icons, dropdowns, etc)
33+
* <li>.includeClass - (String) Optional class to set on the include src div (only relevant when include is set).
3134
* <li>.actionFn - (function(action)) Function to invoke when the action selected
3235
* </ul>
3336
* @param {function (action, item))} enableButtonForItemFn function(action, item) Used to enabled/disable an action button based on the current item
@@ -120,8 +123,8 @@
120123
</file>
121124
122125
<file name="script.js">
123-
angular.module('patternfly.views').controller('ViewCtrl', ['$scope',
124-
function ($scope) {
126+
angular.module('patternfly.views').controller('ViewCtrl', ['$scope', '$templateCache',
127+
function ($scope, $templateCache) {
125128
$scope.eventText = '';
126129
var handleSelect = function (item, e) {
127130
$scope.eventText = item.name + ' selected\r\n' + $scope.eventText;
@@ -239,6 +242,9 @@
239242
$scope.eventText = item.name + " : " + action.name + "\r\n" + $scope.eventText;
240243
};
241244
245+
var buttonInclude = '<span class="fa fa-plus"></span>{{actionButton.name}}';
246+
247+
$templateCache.put('my-button-template', buttonInclude);
242248
$scope.actionButtons = [
243249
{
244250
name: 'Action 1',
@@ -247,8 +253,15 @@
247253
},
248254
{
249255
name: 'Action 2',
256+
class: 'btn-primary',
250257
title: 'Do something else',
251258
actionFn: performAction
259+
},
260+
{
261+
name: 'Action 3',
262+
include: 'my-button-template',
263+
title: 'Do something special',
264+
actionFn: performAction
252265
}
253266
];
254267
$scope.menuActions = [

src/views/listview/list-view.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
<div class="list-view-pf-actions"
1010
ng-if="(actionButtons && actionButtons.length > 0) || (menuActions && menuActions.length > 0)">
11-
<button class="btn btn-default" ng-repeat="actionButton in actionButtons"
11+
<button class="btn btn-default {{actionButton.class}}" ng-repeat="actionButton in actionButtons"
1212
title="actionButton.title"
1313
ng-class="{'disabled' : checkDisabled(item) || !enableButtonForItem(actionButton, item)}"
1414
ng-click="handleButtonAction(actionButton, item)">
15-
{{actionButton.name}}
15+
<div ng-if="actionButton.include" class="actionButton.includeClass" ng-include src="actionButton.include"></div>
16+
<span ng-if="!actionButton.include">{{actionButton.name}}</span>
1617
</button>
1718
<div class="{{dropdownClass}} pull-right dropdown-kebab-pf"
1819
id="kebab_{{$index}}"

0 commit comments

Comments
 (0)