<commit_before>'use strict';

var directiveModule = angular.module('angularjs-dropdown-multiselect', []);

directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$compile', function ($filter, $document, $compile) {

	return {
		restrict: 'AE',
		scope:{
			selectedModel: '=',
			options: '=',
			extraSettings: '='
		},
		template: function(element, attrs)
		{
			var checkboxes = attrs.checkboxes ? true : false;

			var template = '<div class="multiselect-parent btn-group dropdown-multiselect" data-ng-class="{open: open}">';
			template +='<button type="button" class="btn btn-default dropdown-toggle" ng-click="toggleDropdown()">{{getButtonText()}}<span class="caret"></span></button>';
			template += '<ul class="dropdown-menu dropdown-menu-form">';
			template += '<li><a data-ng-click="selectAll()"><span class="glyphicon glyphicon-ok"></span>  Check All</a>';
			template += '<li><a data-ng-click="deselectAll();"><span class="glyphicon glyphicon-remove"></span>  Uncheck All</a></li>';
			template += '<li class="divider"></li>';

			if(checkboxes)
			{
				template += '<li data-ng-repeat="option in watchedOptions"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a></li>';
			}
			else {
				template += '<li data-ng-repeat="option in watchedOptions"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a></li>';
			}

			template += '</ul>';
			template += '</div>';

			element.html(template);
		},
		link: function($scope, $element, $attrs){
			$scope.toggleDropdown = function()
			{
				$scope.open = !$scope.open;
			};

			$scope.checkboxClick = function($event, id)
			{
				$scope.setSelectedItem(id);
				$event.stopImmediatePropagation();
			};

			$scope.$watch('options', function(newValue)
			{
				$scope.watchedOptions = angular.copy($scope.options);
			}, true);

			$scope.settings = {
				dynamicTitle: true,
				defaultText: 'Select',
				closeOnBlur: true,
				displayProp: 'label',
				idProp: 'id',
				externalIdProp: 'id'};

			angular.extend($scope.settings, $scope.extraSettings || []);

			function getFindObj(id)
			{<commit_msg>Added search to the directive, added example for search<commit_after>'use strict';

var directiveModule = angular.module('angularjs-dropdown-multiselect', []);

directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$compile', function ($filter, $document, $compile) {

	return {
		restrict: 'AE',
		scope:{
			selectedModel: '=',
			options: '=',
			extraSettings: '='
		},
		template: function(element, attrs)
		{
			var checkboxes = attrs.checkboxes ? true : false;

			var template = '<div class="multiselect-parent btn-group dropdown-multiselect" data-ng-class="{open: open}">';
			template +='<button type="button" class="btn btn-default dropdown-toggle" ng-click="toggleDropdown()">{{getButtonText()}}<span class="caret"></span></button>';
			template += '<ul class="dropdown-menu dropdown-menu-form">';
			template += '<li><a data-ng-click="selectAll()"><span class="glyphicon glyphicon-ok"></span>  Check All</a>';
			template += '<li><a data-ng-click="deselectAll();"><span class="glyphicon glyphicon-remove"></span>  Uncheck All</a></li>';
			template += '<li class="divider"></li>';
			template += '<li ng-show="settings.enableSearch"><input type="text" class="form-control" ng-model="searchFilter" /></li>';
			template += '<li ng-show="settings.enableSearch" class="divider"></li>';
			template += '<li data-ng-repeat="option in watchedOptions | filter: searchFilter"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))">';

			if(checkboxes)
			{
				template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a>';
			}
			else {
				template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a>';
			}

			template += '</li>';

			template += '</ul>';
			template += '</div>';

			element.html(template);
		},
		link: function($scope, $element, $attrs){
			$scope.toggleDropdown = function()
			{
				$scope.open = !$scope.open;
			};

			$scope.checkboxClick = function($event, id)
			{
				$scope.setSelectedItem(id);
				$event.stopImmediatePropagation();
			};

			$scope.$watch('options', function(newValue)
			{
				$scope.watchedOptions = angular.copy($scope.options);
			}, true);

			$scope.searchFilter = '';

			$scope.settings = {
				dynamicTitle: true,
				defaultText: 'Select',
				closeOnBlur: true,
				displayProp: 'label',
				idProp: 'id',
				externalIdProp: 'id',
				enableSearch: false};

			angular.extend($scope.settings, $scope.extraSettings || []);

			function getFindObj(id)
			{
{'fraction_non_alphanumeric': 0.1920117259069256, 'fraction_numerical': 0.0, 'mean_word_length': 5.1062639821029085, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5265291', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1664, 'n_words': 288}