1
- function SearchController ( $scope , slimClient ) {
1
+ function SearchController ( $scope , $location , slimClient ) {
2
2
3
3
$scope . client = slimClient ;
4
4
$scope . searchText = "" ;
@@ -8,22 +8,36 @@ function SearchController($scope, slimClient) {
8
8
9
9
$scope . submitSearch = function ( ) {
10
10
if ( $scope . searchText != "" ) {
11
- slimClient . search ( $scope . searchText ) .
11
+ slimClient . tracks ( "search:" + $scope . searchText ) .
12
12
success ( function ( result ) {
13
-
14
- res = result [ 'result' ] ;
15
-
16
- $scope . albums = res [ 'albums_loop' ] ;
17
- $scope . tracks = res [ 'tracks_loop '] ;
18
- $scope . artists = res [ 'contributors_loop' ] ;
19
- } ) .
20
- error ( function ( result ) {
21
- alert ( "Failed: " + result ) ;
13
+ $scope . tracks = result [ 'titles_loop' ] ;
14
+ } ) ;
15
+ slimClient . albums ( "search:" + $scope . searchText ) .
16
+ success ( function ( result ) {
17
+ $scope . albums = result [ 'albums_loop '] ;
18
+ } ) ;
19
+ slimClient . artists ( "search:" + $scope . searchText ) .
20
+ success ( function ( result ) {
21
+ $scope . artists = result [ 'artists_loop' ] ;
22
22
} ) ;
23
23
}
24
24
} ;
25
25
26
+ $scope . $watch ( "searchText" , function ( val ) {
27
+ if ( ! val || val . length == 0 ) {
28
+ $location . search ( 'search' , null ) ;
29
+ } else {
30
+ $location . search ( 'search' , val ) ;
31
+ }
32
+ } ) ;
33
+
26
34
$scope . init = function ( ) {
35
+ if ( $location . search ( ) . search ) {
36
+ $scope . searchText = $location . search ( ) . search ;
37
+ $scope . submitSearch ( ) ;
38
+ } else {
39
+ $scope . searchText = "" ;
40
+ }
27
41
} ;
28
42
29
43
}
0 commit comments