Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. angular.module('ssq.shared').directive('checkboxPicklist', function() {
  2. return {
  3. restrict: 'E',
  4. templateUrl: '/SSQV4/SSQV5/Scripts/app/Shared/directives/checkboxPicklist.html',
  5. replace: true,
  6. scope: {
  7. itemId: '=',
  8. list: '=',
  9. nameProp: '=',
  10. title: '@',
  11. searchPlaceholder: '@',
  12. callbackFn: '&'
  13. },
  14. link: function (scope, element, attrs) {
  15. scope.query = '';
  16.  
  17. var child = element.find('.dropdown-menu');
  18. child.on({
  19. 'click': function(e) {
  20. e.stopPropagation();
  21. }
  22. });
  23.  
  24. var selectedItemFn = function (item) {
  25. return item.selected;
  26. };
  27.  
  28. scope.getSelectedCount = function() {
  29. return _.filter(scope.list, selectedItemFn).length;
  30. };
  31.  
  32. scope.allSelected = function(list) {
  33. var newValue = !scope.allNeedsMet(list);
  34. _.each(list, function(item) {
  35. item.selected = newValue;
  36. scope.callbackFn({ object: item });
  37. });
  38. };
  39.  
  40. scope.allNeedsMet = function(list) {
  41.  
  42. var needsMet = _.reduce(list, function(memo, item) {
  43. return memo + (item.selected ? 1 : 0);
  44. }, 0);
  45. if (!list) {
  46. return (needsMet === 0);
  47. }
  48. return (needsMet === list.length);
  49. };
  50. }
  51. };
  52. });
  53.  
  54. app.directive('lazyLoad', function () {
  55. return {
  56. restrict: 'A',
  57. scope: { 'loadMore': '&' },
  58. link: function (scope, elem) {
  59. var scroller = elem[0]
  60. $(scroller).bind('scroll', function () {
  61. if (scroller.scrollTop + scroller.offsetHeight >= scroller.scrollHeight) {
  62. scope.$apply('loadMore()')
  63. }
  64. })
  65. }
  66. }
  67.  
  68. $scope.loadMore = function () {
  69. indServices = indServices + 10
  70. var r = 10
  71. if (ind + 10 >= $scope.buffer.Services.length) {
  72. r = $scope.buffer.Services.length - ind
  73. }
  74.  
  75. }
  76.  
  77. <div class="pec-checkbox-picklist btn-group btn-group-picklist">
  78. <button id="{{itemId}}" class="form-control dropdown-toggle" data-toggle="dropdown">
  79. <span class="cbpl-btn-text">{{ getSelectedCount() }} {{ title }}</span><span class="caret"></span>
  80.  
  81. </button>
  82. <ul class="dropdown-menu dropdown-menu-complex" data-complex-menu style="overflow-y: scroll" lazy-load>
  83.  
  84. <li class="list-group-item search-item">
  85. <input class="form-control" type="text" placeholder="{{ searchPlaceholder }}" ng-model="query" />
  86. <button type="button" class="btn btn-small" ng-show="query" ng-click="query = undefined">clear</button>
  87. </li>
  88. <li class="divider" ng-hide="query"></li>
  89. <li class="list-group-item" ng-hide="query">
  90. <label class="checkbox">
  91. <input type="checkbox" ng-click="allSelected(list)" ng-checked="allNeedsMet(list)">
  92. Select All
  93. </label>
  94. </li>
  95. <li class="divider"></li>
  96. <li class="list-group-item" ng-repeat="item in list | searchFilter:nameProp:query">
  97. <label class="checkbox" title="{{ item[nameProp] }}">
  98. <input type="checkbox" ng-model="item.selected" ng-change="callbackFn({object: item})">
  99. {{ item[nameProp] }}
  100. </label>
  101. </li>
  102.  
  103. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement