summaryrefslogtreecommitdiffstats
path: root/app/common/directives/log-search-control.js
blob: abdc9ffd5335e8fe12c7a7b4b292c0c383cd209d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives').directive('logSearchControl', [
    'APIUtils',
    function(APIUtils) {
      return {
        'restrict': 'E',
        'template': require('./log-search-control.html'),
        'controller': [
          '$rootScope', '$scope', 'dataService', '$location',
          function($rootScope, $scope, dataService, $location) {
            $scope.dataService = dataService;
            $scope.doSearchOnEnter = function(event) {
              var search =
                  $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
              if (event.keyCode === 13 && search.length >= 2) {
                $scope.clearSearchItem();
                $scope.addSearchItem(search);
              } else {
                if (search.length == 0) {
                  $scope.clearSearchItem();
                }
              }
            };

            $scope.clear = function() {
              $scope.customSearch = '';
              $scope.clearSearchItem();
            };

            $scope.doSearchOnClick = function() {
              var search =
                  $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
              if (search.length >= 2) {
                $scope.clearSearchItem();
                $scope.addSearchItem(search);
              } else {
                if (search.length == 0) {
                  $scope.clearSearchItem();
                }
              }
            };
          }
        ]
      };
    }
  ]);
})(window.angular);
OpenPOWER on IntegriCloud