@@ -48,7 +48,7 @@ angular.module( 'patternfly.utils', [] );
48
48
* Views module for patternfly.
49
49
*
50
50
*/
51
- angular . module ( 'patternfly.views' , [ ] ) ;
51
+ angular . module ( 'patternfly.views' , [ 'patternfly.utils' ] ) ;
52
52
; /**
53
53
* @ngdoc directive
54
54
* @name patternfly.autofocus:pfFocused
@@ -1991,6 +1991,130 @@ angular.module('patternfly.select', []).directive('pfSelect', function ($timeout
1991
1991
} ;
1992
1992
} ) ;
1993
1993
;
1994
+ /**
1995
+ * @ngdoc directive
1996
+ * @name patternfly.utils.directive:pfTransclude
1997
+ * @restrict A
1998
+ * @element ANY
1999
+ * @param {string } pfTransclude specifies the type of transclusion to use.<br/>
2000
+ * <strong>Values:</strong>
2001
+ * <ul style='list-style-type: none'>
2002
+ * <li> 'sibling' - The transcluded contents scope is a sibling one to the element where transclusion happens (default)
2003
+ * <li> 'parent' - The transcluded contents scope is that of the element where transclusion happens.
2004
+ * <li> 'child' - The transcluded contents scope is child scope to the scope of the element where transclusion happens.
2005
+ * </ul>
2006
+ *
2007
+ * @description
2008
+ * Directive for transcluding in directives and setting up scope of children of parent directives. This is a workaround
2009
+ * for https://github.com/angular/angular.js/issues/5489
2010
+ *
2011
+ * @example
2012
+ <example module="patternfly.utils">
2013
+ <file name="index.html">
2014
+ <style>
2015
+
2016
+ .pf-transclude-example div {
2017
+ border: 1px solid #337ab7;
2018
+ margin-bottom: 20px;
2019
+ margin-left: 20px;
2020
+ }
2021
+
2022
+ .pf-transclude-example p {
2023
+ background-color: #337ab7;
2024
+ margin: 0;
2025
+ padding: 5px 10px;
2026
+ }
2027
+
2028
+ .pf-transclude-example id {
2029
+ display: inline-block;
2030
+ background-color: #def3ff;
2031
+ color: #000000;
2032
+ border-radius: 10px;
2033
+ width: 20px;
2034
+ height: 20px;
2035
+ text-align: center;
2036
+ line-height: 20px;
2037
+ margin-left: 5px;
2038
+ }
2039
+
2040
+ .pf-transclude-example pre {
2041
+ padding: 5px;
2042
+ border-width: 0px;
2043
+ }
2044
+ </style>
2045
+ <div ng-controller="UtilCtrl" class="row pf-transclude-example" style="display:inline-block; width: 100%;">
2046
+ <span>Here the scope id is: <id>{{$id}}</id></span>
2047
+
2048
+ <transclude-sibling class="pf-transclude-example">
2049
+ <pre>This content was transcluded using <b>pf-transclude</b> or <b>pf-transclude="sibling"</b>.</pre><pre>Its scope is: <id>{{$id}}</id> the parent of which is <id>{{$parent.$id}}</id></pre>
2050
+ </transclude-sibling>
2051
+
2052
+ <transclude-parent>
2053
+ <pre>This content was transcluded using <b>pf-transclude="parent"</b>.</pre><pre>Its scope is: <id>{{$id}}</id> the parent of which is <id>{{$parent.$id}}</id></pre>
2054
+ </transclude-parent>
2055
+
2056
+ <transclude-child>
2057
+ <pre>This content was transcluded using <b>pf-transclude="child"</b>.</pre><pre>Its scope is: <id>{{$id}}</id> the parent of which is <id>{{$parent.$id}}</id></pre>
2058
+ </transclude-child>
2059
+ </div>
2060
+ </file>
2061
+
2062
+ <file name="script.js">
2063
+ angular.module('patternfly.utils')
2064
+ .controller( 'UtilCtrl', function($scope) {
2065
+
2066
+ })
2067
+
2068
+ .config(function($provide){
2069
+ $provide.decorator('ngTranscludeDirective', ['$delegate', function($delegate) {
2070
+ // Remove the original directive
2071
+ $delegate.shift();
2072
+ return $delegate;
2073
+ }]);
2074
+ })
2075
+
2076
+ .directive( 'transcludeSibling', function() {
2077
+ return {
2078
+ restrict: 'E',
2079
+ transclude: true,
2080
+ scope: {},
2081
+ template:
2082
+ '<div>' +
2083
+ '<p>I am a directive with scope <id>{{$id}}</id></p>' +
2084
+ '<span pf-transclude></span>' +
2085
+ '</div>'
2086
+ }
2087
+ })
2088
+
2089
+ .directive( 'transcludeParent', function() {
2090
+ return {
2091
+ restrict: 'E',
2092
+ transclude: true,
2093
+ scope: {},
2094
+ template:
2095
+ '<div>' +
2096
+ '<p>I am a directive with scope <id>{{$id}}</id></p>' +
2097
+ '<span pf-transclude="parent"></span>' +
2098
+ '</div>'
2099
+ }
2100
+ })
2101
+
2102
+ .directive( 'transcludeChild', function() {
2103
+ return {
2104
+ restrict: 'E',
2105
+ transclude: true,
2106
+ scope: {},
2107
+ template:
2108
+ '<div>' +
2109
+ '<p>I am a directive with scope <id>{{$id}}</id></p>' +
2110
+ '<span pf-transclude="child"></span>' +
2111
+ '</div>'
2112
+ }
2113
+ })
2114
+ ;
2115
+ </file>
2116
+ </example>
2117
+ */
1994
2118
angular
1995
2119
. module ( 'patternfly.utils' ) . directive ( 'pfTransclude' , function ( ) {
1996
2120
'use strict' ;
@@ -2212,7 +2336,7 @@ angular.module('patternfly.validation', []).directive('pfValidation', function (
2212
2336
* Directive for rendering a data list.
2213
2337
* <br><br>
2214
2338
*
2215
- * @param {object } config configuration settings for the sparkline chart :<br/>
2339
+ * @param {object } config configuration settings for the data list :<br/>
2216
2340
* <ul style='list-style-type: none'>
2217
2341
* <li>.showSelectBox - (boolean) Show item selection boxes for each item, default is true
2218
2342
* <li>.selectItems - (boolean) Allow row selection, default is false
@@ -2311,7 +2435,7 @@ angular.module('patternfly.validation', []).directive('pfValidation', function (
2311
2435
</file>
2312
2436
2313
2437
<file name="script.js">
2314
- angular.module('patternfly.views').controller('ViewCtrl', ['$scope',
2438
+ angular.module('patternfly.views').controller('ViewCtrl', ['$scope',
2315
2439
function ($scope) {
2316
2440
$scope.eventText = '';
2317
2441
var handleSelect = function (item, e) {
@@ -2383,8 +2507,8 @@ angular.module('patternfly.validation', []).directive('pfValidation', function (
2383
2507
city: "New York",
2384
2508
state: "New York"
2385
2509
},
2386
- ];
2387
- };
2510
+ ]
2511
+ }
2388
2512
]);
2389
2513
</file>
2390
2514
</example>
@@ -2395,11 +2519,10 @@ angular.module('patternfly.views').directive('pfDataList', [
2395
2519
return {
2396
2520
restrict : 'A' ,
2397
2521
scope : {
2398
- config : '=' ,
2522
+ config : '=? ' ,
2399
2523
items : '=' ,
2400
2524
eventId : '@id'
2401
2525
} ,
2402
- replace : true ,
2403
2526
transclude : true ,
2404
2527
templateUrl : 'views/datalist/data-list.html' ,
2405
2528
controller : [ '$scope' ,
@@ -2454,7 +2577,7 @@ angular.module('patternfly.views').directive('pfDataList', [
2454
2577
2455
2578
if ( alreadySelected ) {
2456
2579
// already selected so deselect
2457
- scope . config . selectedItems = _ . without ( scope . config . selectedItems , selectMatch ) ;
2580
+ scope . config . selectedItems = _ . without ( scope . config . selectedItems , item ) ;
2458
2581
} else {
2459
2582
// add the item to the selected items
2460
2583
scope . config . selectedItems . push ( item ) ;
@@ -2577,7 +2700,7 @@ angular.module('patternfly.views').directive('pfDataList', [
2577
2700
'use strict' ;
2578
2701
2579
2702
$templateCache . put ( 'views/datalist/data-list.html' ,
2580
- "<div class=data-list-pf><div class=list-group-item ng-repeat=\"item in items track by $index\" ng-class=\"{'pf-selectable': selectItems, 'active': isSelected(item), 'disabled': checkDisabled(item)}\"><div class=\"row list-row\"><div pf-transclude=parent class=list-content ng-class=\"{'with-check-box': config.showSelectBox, 'with-menu':config.showActionMenus}\" ng-click=\"itemClick($event, item)\" ng-dblclick=\"dblClick($event, item)\" ng-transclude=\"\" ></div><div class=list-check-box ng-if=config.showSelectBox style=\"padding-top: {{(config.rowHeight - 32) / 2}}px\"><input type=checkbox value=item.selected ng-model=item.selected ng-disabled=checkDisabled(item) ng-change=\"checkBoxChange(item)\"></div></div></div></div>"
2703
+ "<div class=data-list-pf><div class=list-group-item ng-repeat=\"item in items track by $index\" ng-class=\"{'pf-selectable': selectItems, 'active': isSelected(item), 'disabled': checkDisabled(item)}\"><div class=\"row list-row\"><div pf-transclude=parent class=list-content ng-class=\"{'with-check-box': config.showSelectBox, 'with-menu':config.showActionMenus}\" ng-click=\"itemClick($event, item)\" ng-dblclick=\"dblClick($event, item)\"></div><div class=list-check-box ng-if=config.showSelectBox style=\"padding-top: {{(config.rowHeight - 32) / 2}}px\"><input type=checkbox value=item.selected ng-model=item.selected ng-disabled=checkDisabled(item) ng-change=\"checkBoxChange(item)\"></div></div></div></div>"
2581
2704
) ;
2582
2705
2583
2706
} ] ) ;
0 commit comments