resolve license issue for st-select and add some comments.
diff --git a/src/app/st-select.directive.js b/src/app/st-select.directive.js
index 3954afe..a030f9b 100644
--- a/src/app/st-select.directive.js
+++ b/src/app/st-select.directive.js
@@ -1,62 +1,66 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+/*
+ Copyright 2013 Daniel Unfried
+ Modifications 2015 Apache ODE team
- /* https://github.com/wldaunfr/ng-selectall/blob/develop/src/selectall.directive.js */
-
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
'use strict';
+/* See https://github.com/wldaunfr/ng-selectall/blob/develop/src/selectall.directive.js */
angular.module('odeConsole')
.directive('selectAllCheckbox', ['$filter', function($filter) {
return {
restrict: 'E',
template: '<input type="checkbox">',
replace: true,
- link: function(scope, element, iAttrs) {
+ link: function(scope, element, attrs) {
+ // set checked and indeterminate state
function changeState(checked, indet) {
element.prop('checked', checked).prop('indeterminate', indet);
}
+ // update item checkboxes
function updateItems() {
- angular.forEach(scope.$eval(iAttrs.items), function(el) {
- el[iAttrs.prop] = element.prop('checked');
+ angular.forEach(scope.$eval(attrs.items), function(el) {
+ el[attrs.prop] = element.prop('checked');
});
}
element.bind('change', function() {
+ // update items on change
scope.$apply(function() { updateItems(); });
});
- scope.$watch(iAttrs.items, function(newValue) {
+ scope.$watch(attrs.items, function(newValue) {
var checkedItems = $filter('filter')(newValue, function(el) {
- return el[iAttrs.prop];
+ return el[attrs.prop];
});
switch(checkedItems ? checkedItems.length : 0) {
- case 0: // none selected
+ case 0:
+ // none selected (not checked, not indeterminate)
changeState(false, false);
break;
- case newValue.length: // all selected
+ case newValue.length:
+ // all selected (checked, not indeterminate)
changeState(true, false);
break;
- default: // some selected
+ default:
+ // some selected (not checked, indeterminate)
changeState(false, true);
}
}, true);
scope.$on('$destroy', function() {
element.off('change');
});
+ // initially update items
updateItems();
}
};