2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "selectAllList", () ->
|
|
|
|
return {
|
|
|
|
controller: ["$scope", ($scope) ->
|
|
|
|
# Selecting or deselecting all should apply to all projects
|
2015-06-29 08:43:34 -04:00
|
|
|
@selectAll = () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.$broadcast "select-all:select"
|
|
|
|
|
2015-06-29 08:43:34 -04:00
|
|
|
@deselectAll = () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.$broadcast "select-all:deselect"
|
|
|
|
|
2015-06-29 08:43:34 -04:00
|
|
|
@clearSelectAllState = () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.$broadcast "select-all:clear"
|
2017-06-21 11:00:56 -04:00
|
|
|
return
|
2014-07-08 07:02:26 -04:00
|
|
|
]
|
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
App.directive "selectAll", () ->
|
|
|
|
return {
|
|
|
|
require: "^selectAllList"
|
|
|
|
link: (scope, element, attrs, selectAllListController) ->
|
|
|
|
scope.$on "select-all:clear", () ->
|
|
|
|
element.prop("checked", false)
|
|
|
|
|
|
|
|
element.change () ->
|
|
|
|
if element.is(":checked")
|
|
|
|
selectAllListController.selectAll()
|
|
|
|
else
|
|
|
|
selectAllListController.deselectAll()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
App.directive "selectIndividual", () ->
|
|
|
|
return {
|
|
|
|
require: "^selectAllList"
|
|
|
|
scope: {
|
|
|
|
ngModel: "="
|
|
|
|
}
|
|
|
|
link: (scope, element, attrs, selectAllListController) ->
|
|
|
|
ignoreChanges = false
|
|
|
|
|
|
|
|
scope.$watch "ngModel", (value) ->
|
|
|
|
if value? and !ignoreChanges
|
|
|
|
selectAllListController.clearSelectAllState()
|
|
|
|
|
|
|
|
scope.$on "select-all:select", () ->
|
2017-12-14 11:18:01 -05:00
|
|
|
return if element.prop('disabled')
|
2014-07-08 07:02:26 -04:00
|
|
|
ignoreChanges = true
|
|
|
|
scope.$apply () ->
|
|
|
|
scope.ngModel = true
|
|
|
|
ignoreChanges = false
|
|
|
|
|
|
|
|
scope.$on "select-all:deselect", () ->
|
2017-12-14 11:18:01 -05:00
|
|
|
return if element.prop('disabled')
|
2014-07-08 07:02:26 -04:00
|
|
|
ignoreChanges = true
|
|
|
|
scope.$apply () ->
|
|
|
|
scope.ngModel = false
|
|
|
|
ignoreChanges = false
|
2017-05-01 12:11:03 -04:00
|
|
|
|
|
|
|
scope.$on "select-all:row-clicked", () ->
|
2017-12-14 11:18:01 -05:00
|
|
|
return if element.prop('disabled')
|
2017-05-01 12:11:03 -04:00
|
|
|
ignoreChanges = true
|
|
|
|
scope.$apply () ->
|
|
|
|
scope.ngModel = !scope.ngModel
|
2017-06-21 11:00:56 -04:00
|
|
|
if !scope.ngModel
|
|
|
|
selectAllListController.clearSelectAllState()
|
2017-05-01 12:11:03 -04:00
|
|
|
ignoreChanges = false
|
|
|
|
}
|
|
|
|
|
|
|
|
App.directive "selectRow", () ->
|
|
|
|
return {
|
|
|
|
scope: true
|
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
element.on "click", (e) ->
|
|
|
|
scope.$broadcast "select-all:row-clicked"
|
2017-12-14 11:18:01 -05:00
|
|
|
}
|