-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectAllCheckBox.js
More file actions
63 lines (57 loc) · 2.08 KB
/
Copy pathselectAllCheckBox.js
File metadata and controls
63 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(function() {
var app = angular.module('UserMgr');
app.directive('selectAllCheckbox', function() {
return {
replace: true,
restrict: 'E',
scope: {
checkboxes: '=',
allselected: '=allSelected',
allclear: '=allClear'
},
template: '<input type="checkbox" ng-model="master" ng-change="masterChange()">',
controller: function($scope, $element) {
$scope.masterChange = function() {
if ($scope.master) {
angular.forEach($scope.checkboxes, function(cb, index) {
cb.isSelected = true;
});
} else {
angular.forEach($scope.checkboxes, function(cb, index) {
cb.isSelected = !$scope.preIndeterminate;
});
}
};
$scope.$watch('checkboxes', function() {
var allSet = $scope.checkboxes.length > 0,
allClear = true;
angular.forEach($scope.checkboxes, function(cb, index) {
if (cb.isSelected) {
allClear = false;
} else {
allSet = false;
}
});
if ($scope.allselected !== undefined) {
$scope.allselected = allSet;
}
if ($scope.allclear !== undefined) {
$scope.allclear = allClear;
}
$element.prop('indeterminate', false);
if (allSet) {
$scope.preIndeterminate = true;
$scope.master = true;
} else if (allClear) {
$scope.preIndeterminate = false;
$scope.master = false;
} else {
$scope.preIndeterminate = $scope.master===null ? $scope.preIndeterminate:$scope.master;
$scope.master = null;
$element.prop('indeterminate', true);
}
}, true);
}
};
});
})();