1window.angular && (function (angular) {
2    'use strict';
3
4    angular
5        .module('app.common.directives')
6        .directive('logSearchControl', ['APIUtils', function (APIUtils) {
7            return {
8                'restrict': 'E',
9                'templateUrl': 'common/directives/log-search-control.html',
10                'controller': ['$rootScope', '$scope','dataService', '$location', function($rootScope, $scope, dataService, $location){
11                    $scope.dataService = dataService;
12                    $scope.doSearchOnEnter = function (event) {
13                        var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
14                        if (event.keyCode === 13 &&
15                            search.length >= 2) {
16                            $scope.clearSearchItem();
17                            $scope.addSearchItem(search);
18                        }else{
19                            if(search.length == 0){
20                                $scope.clearSearchItem();
21                            }
22                        }
23                    };
24
25                    $scope.clear = function(){
26                        $scope.customSearch = "";
27                        $scope.clearSearchItem();
28                    }
29
30                    $scope.doSearchOnClick = function() {
31                        var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
32                        if (search.length >= 2) {
33                            $scope.clearSearchItem();
34                            $scope.addSearchItem(search);
35                        }else{
36                            if(search.length == 0){
37                                $scope.clearSearchItem();
38                            }
39                        }
40                    }
41                }]
42            };
43        }]);
44})(window.angular);
45