'use strict'; angular.module('quantum').directive('dropdownMultiselect', ['$document', function($document){ return { restrict: 'E', scope:{ model: '=ngModel', options: '=' }, template: "
"+ "Multi-Select"+ ""+ "" + "
" , link: function($scope,element,attr){ $scope.$watch("options",function(newValue,oldValue) { $scope.model = []; }); $scope.selectAll = function () { $scope.model = _.pluck($scope.options, 'value'); }; $scope.deselectAll = function() { $scope.model=[]; }; $scope.setSelectedItem = function(){ var value = this.option.value; if (_.contains($scope.model, value)) { $scope.model = _.without($scope.model, value); } else { $scope.model.push(value); } return false; }; $scope.isChecked = function (value) { if (_.contains($scope.model, value)) { return 'icon-included-checkmark pull-right'; } return false; }; $document.bind('click', function(event){ var isClickedElementChildOfPopup = element .find(event.target) .length > 0; if (isClickedElementChildOfPopup) return; $scope.open = false; $scope.$apply(); }); } }; }]);