client/app/search/search_controller.js
changeset 2 36ccc573af9a
parent 1 74bbdd739878
child 6 4be9f21f2df1
--- a/client/app/search/search_controller.js	Thu Oct 02 13:24:57 2014 +0200
+++ b/client/app/search/search_controller.js	Fri Oct 03 10:38:50 2014 +0200
@@ -9,50 +9,26 @@
           controller: 'searchCtrl'
         });
     })
-    .service('searchApi', function($resource, context) {
-        console.log('search 4',$resource, context);
-        this.searchResource = function(params){
-            return $resource(context.urls.searchUrl,  
-                {
-                    callback: 'JSON_CALLBACK'
-                },
-                {
-                    getJsonp: {
-                        method: 'JSONP',
-                        params: params,
-                        isArray: false
-                    }
-                });
-        };
-        
-    })
-    .service('searchModel', function(searchApi) {
-        console.log('search 5');
-        this.searchResults = function(params){
-            return searchApi.searchResource(params).getJsonp();
-        };
-    })
-    .controller('searchCtrl', function($scope, $location, $routeParams, searchModel){
+    .controller('searchCtrl', function($scope, $location, $routeParams, searchApi){
       console.log('search 6',$scope, $location, $routeParams);
       $scope.q = $routeParams.q || '';
-      searchModel.searchResults({q:$scope.q, of: 'json', synthesis: 'false', callback: 'JSON_CALLBACK'}).$promise.then(
+      searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).$promise.then(
           //success
           function( data ){
-              console.log('SUCCESS !', data);
               $scope.results = data;
           },
           //error
           function( error ){
-              console.log('ERROR !', error);
+              alert('Erreur avec la requĂȘte', error);
           }
       );
-      //window.myres = res;
-      //$scope.results = res;
-      //console.log('search 6-blabla', res);
-      console.log('search 7', $scope.q);
       
-      //$scope.search = searchModel.search;
-      // query = ?q=violon&of=json&synthesis=false
+      $scope.addItem = function(i){
+          console.log('addItem',i);
+          if($scope.results.hits.length>0 && 0<=i && i<$scope.results.hits.length){
+              
+          }
+      };
     })
     .filter('meta', function() {
         return function(input, metaName) {
@@ -64,6 +40,7 @@
                 }
                 i++;
             }
+            return '';
         };
     });