Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('cbuComponents').component 'cbCheckboxList',
- bindings:
- collection: '<'
- textProperty: '<'
- textPropertyComplementary: '<'
- onChange: '&'
- templateUrl: 'scripts/components/cb-checkbox-list/cb-checkbox-list.html'
- controller: ($scope, $element, $attrs) ->
- ctrl = this
- ctrl.all = false
- ###*
- * Iterate over all collection to know if we have to render "check all" as
- * checked or unchecked.
- ###
- calculateAllStatus = () ->
- active = _.filter(ctrl.collection, {active: true})
- ctrl.all = ctrl.collection.length is active.length
- ###*
- * Initializes the component and determines if we need to leave check all
- * enabled or not.
- * @param { Object } changesObj
- ###
- ctrl.$onChanges = (changesObj) ->
- if ctrl?.collection?.length > 0
- calculateAllStatus()
- ###*
- * Method fired on user clicking "check all" to enable all the items.
- ###
- ctrl.toggleAll = () ->
- ctrl.collection.forEach (item) ->
- item.active = ctrl.all
- # fires onChange method when activating all the items.
- ctrl.onChange({value: item})
- ###*
- * Method fired on user clicking each item checkbox element.
- * It checks if "check all" should be marked.
- * It also fires notification to parent controller.
- * @param {[type]} value [description]
- * @return {[type]} [description]
- ###
- ctrl.fieldChange = (value) ->
- calculateAllStatus()
- ctrl.onChange({value: value})
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement