Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 1 | window.angular && (function(angular) { |
| 2 | 'use strict'; |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 3 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 4 | angular |
| 5 | .module('app.common.directives') |
| 6 | .directive('logSearchControl', ['APIUtils', function(APIUtils) { |
| 7 | return { |
| 8 | 'restrict': 'E', |
| 9 | 'template': require('./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 | } |
| 19 | else { |
| 20 | if (search.length == 0) { |
| 21 | $scope.clearSearchItem(); |
| 22 | } |
| 23 | } |
| 24 | }; |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 25 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 26 | $scope.clear = function() { |
| 27 | $scope.customSearch = ''; |
| 28 | $scope.clearSearchItem(); |
| 29 | }; |
Iftekharul Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 30 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame^] | 31 | $scope.doSearchOnClick = function() { |
| 32 | var search = $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); |
| 33 | if (search.length >= 2) { |
| 34 | $scope.clearSearchItem(); |
| 35 | $scope.addSearchItem(search); |
| 36 | } |
| 37 | else { |
| 38 | if (search.length == 0) { |
| 39 | $scope.clearSearchItem(); |
| 40 | } |
| 41 | } |
| 42 | }; |
| 43 | }] |
| 44 | }; |
| 45 | }]); |
Iftekharul Islam | 8b4828a | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 46 | })(window.angular); |