This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/multiselect-dropdown.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* An element which displays a dropdown for selecting multiple elements.
*/
angular.module('quay').directive('multiselectDropdown', function ($compile) {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/multiselect-dropdown.html',
transclude: true,
replace: false,
restrict: 'C',
scope: {
'items': '=items',
'selectedItems': '=selectedItems',
'itemName': '@itemName',
'itemChecked': '&itemChecked'
},
controller: function($scope, $element) {
$scope.isChecked = function(checked, item) {
return checked.indexOf(item) >= 0;
};
$scope.toggleItem = function(item) {
var isChecked = $scope.isChecked($scope.selectedItems, item);
if (!isChecked) {
$scope.selectedItems.push(item);
} else {
var index = $scope.selectedItems.indexOf(item);
$scope.selectedItems.splice(index, 1);
}
$scope.itemChecked({'item': item, 'checked': !isChecked});
};
}
};
return directiveDefinitionObject;
});