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