22
33var directiveModule = angular . module ( 'angularjs-dropdown-multiselect' , [ ] ) ;
44
5- directiveModule . run ( [ '$templateCache' , function ( $templateCache )
6- {
7- var template = '<div class="multiselect-parent btn-group dropdown-multiselect" data-ng-class="{open: open}">' ;
8- template += '<button type="button" class="btn btn-default dropdown-toggle" data-ng-click="open=!open;">{{getButtonText()}}<span class="caret"></span></button>' ;
9- template += '<ul class="dropdown-menu">' ;
10- template += '<li><a data-ng-click="selectAll()"><span class="glyphicon glyphicon-ok"></span> Check All</a>' ;
11- template += '<li><a data-ng-click="deselectAll();"><span class="glyphicon glyphicon-remove"></span> Uncheck All</a></li>' ;
12- template += '<li class="divider"></li>' ;
13- template += '<li data-ng-repeat="option in options"><a data-ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><span data-ng-class="isChecked(getPropertyForObject(option,settings.idProp))"></span>{{getPropertyForObject(option, settings.displayProp)}}</a></li>' ;
14- template += '</ul>' ;
15- template += '</div>' ;
16-
17- $templateCache . put ( 'dropdown-multiselect-template.html' , template ) ;
18- } ] ) ;
19-
20- directiveModule . directive ( 'ngDropdownMultiselect' , [ '$filter' , '$document' , function ( $filter , $document ) {
5+ directiveModule . directive ( 'ngDropdownMultiselect' , [ '$filter' , '$document' , '$compile' , function ( $filter , $document , $compile ) {
216
227 return {
238 restrict : 'AE' ,
@@ -26,8 +11,42 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', func
2611 options : '=' ,
2712 extraSettings : '='
2813 } ,
29- templateUrl : 'dropdown-multiselect-template.html' ,
30- link : function ( $scope , $element ) {
14+ template : function ( element , attrs )
15+ {
16+ var checkboxes = attrs . checkboxes ? true : false ;
17+
18+ var template = '<div class="multiselect-parent btn-group dropdown-multiselect" data-ng-class="{open: open}">' ;
19+ template += '<button type="button" class="btn btn-default dropdown-toggle" ng-click="toggleDropdown()">{{getButtonText()}}<span class="caret"></span></button>' ;
20+ template += '<ul class="dropdown-menu dropdown-menu-form">' ;
21+ template += '<li><a data-ng-click="selectAll()"><span class="glyphicon glyphicon-ok"></span> Check All</a>' ;
22+ template += '<li><a data-ng-click="deselectAll();"><span class="glyphicon glyphicon-remove"></span> Uncheck All</a></li>' ;
23+ template += '<li class="divider"></li>' ;
24+
25+ if ( checkboxes )
26+ {
27+ template += '<li data-ng-repeat="option in options"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a></li>' ;
28+ }
29+ else {
30+ template += '<li data-ng-repeat="option in options"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a></li>' ;
31+ }
32+
33+ template += '</ul>' ;
34+ template += '</div>' ;
35+
36+ element . html ( template ) ;
37+ } ,
38+ link : function ( $scope , $element , $attrs ) {
39+ $scope . toggleDropdown = function ( )
40+ {
41+ $scope . open = ! $scope . open ;
42+ } ;
43+
44+ $scope . checkboxClick = function ( $event , id )
45+ {
46+ $scope . setSelectedItem ( id ) ;
47+ $event . stopImmediatePropagation ( ) ;
48+ } ;
49+
3150 $scope . settings = {
3251 dynamicTitle : true ,
3352 defaultText : 'Select' ,
@@ -143,9 +162,10 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', func
143162
144163 $scope . isChecked = function ( id ) {
145164 if ( _ . findIndex ( $scope . selectedModel , getFindObj ( id ) ) !== - 1 ) {
146- return 'glyphicon glyphicon-ok' ;
165+ return true ;
147166 }
148- return '' ;
167+
168+ return false ;
149169 } ;
150170 }
151171 } ;
0 commit comments