diff --git a/public/src/js/controllers/search.js b/public/src/js/controllers/search.js index c41bbb88..deab77a4 100644 --- a/public/src/js/controllers/search.js +++ b/public/src/js/controllers/search.js @@ -13,6 +13,11 @@ angular.module('insight.search').controller('SearchController', }, 2000); }; + var _resetSearch = function() { + $scope.q = ''; + $scope.loading = false; + }; + $scope.search = function() { var q = $scope.q; $scope.badQuery = false; @@ -21,30 +26,26 @@ angular.module('insight.search').controller('SearchController', Block.get({ blockHash: q }, function() { - $scope.q = ''; - $scope.loading = false; + _resetSearch(); $location.path('block/' + q); - }, function () { //block not found, search on TX + }, function() { //block not found, search on TX Transaction.get({ txId: q }, function() { - $scope.q = ''; - $scope.loading = false; + _resetSearch(); $location.path('tx/' + q); - }, function () { //tx not found, search on Address + }, function() { //tx not found, search on Address Address.get({ addrStr: q }, function() { - $scope.q = ''; - $scope.loading = false; + _resetSearch(); $location.path('address/' + q); - }, function () { // block by height not found + }, function() { // block by height not found if (isFinite(q)) { // ensure that q is a finite number. A logical height value. BlockByHeight.get({ blockHeight: q }, function(hash) { - $scope.q = ''; - $scope.loading = false; + _resetSearch(); $location.path('/block/' + hash.blockHash); }, function() { //not found, fail :( _badQuery();