added helper to reset serch

This commit is contained in:
Mario Colque 2014-02-12 13:04:26 -03:00
parent 42968ba12e
commit d96f60f18b
1 changed files with 12 additions and 11 deletions

View File

@ -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();