Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. angular.module('cbuComponents').component 'cbCheckboxList',
  2. bindings:
  3. collection: '<'
  4. textProperty: '<'
  5. textPropertyComplementary: '<'
  6. onChange: '&'
  7. templateUrl: 'scripts/components/cb-checkbox-list/cb-checkbox-list.html'
  8. controller: ($scope, $element, $attrs) ->
  9. ctrl = this
  10. ctrl.all = false
  11.  
  12. ###*
  13. * Iterate over all collection to know if we have to render "check all" as
  14. * checked or unchecked.
  15. ###
  16. calculateAllStatus = () ->
  17. active = _.filter(ctrl.collection, {active: true})
  18. ctrl.all = ctrl.collection.length is active.length
  19.  
  20. ###*
  21. * Initializes the component and determines if we need to leave check all
  22. * enabled or not.
  23. * @param { Object } changesObj
  24. ###
  25. ctrl.$onChanges = (changesObj) ->
  26. if ctrl?.collection?.length > 0
  27. calculateAllStatus()
  28.  
  29. ###*
  30. * Method fired on user clicking "check all" to enable all the items.
  31. ###
  32. ctrl.toggleAll = () ->
  33. ctrl.collection.forEach (item) ->
  34. item.active = ctrl.all
  35. # fires onChange method when activating all the items.
  36. ctrl.onChange({value: item})
  37.  
  38. ###*
  39. * Method fired on user clicking each item checkbox element.
  40. * It checks if "check all" should be marked.
  41. * It also fires notification to parent controller.
  42. * @param {[type]} value [description]
  43. * @return {[type]} [description]
  44. ###
  45. ctrl.fieldChange = (value) ->
  46. calculateAllStatus()
  47. ctrl.onChange({value: value})
  48.  
  49. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement