client/app/search/search_controller.js
changeset 47 dd750778535c
parent 8 824c87a9084c
child 55 10fd23382e76
--- a/client/app/search/search_controller.js	Tue Mar 31 12:22:00 2015 +0200
+++ b/client/app/search/search_controller.js	Tue Mar 31 12:24:05 2015 +0200
@@ -1,18 +1,44 @@
 (function(){
-  'use strict';
+	'use strict';
+
+	angular.module('ammicoSearch',['ngResource', 'ngRoute', 'ui.bootstrap'])
+	.config(function ($routeProvider) {
+		$routeProvider
+		.when('/', {
+			templateUrl: 'search/search.html',
+			controller: 'searchCtrl'
+		});
+	})
+	.controller('searchCtrl', function($scope, $location, $routeParams, searchApi, $modal){
+		$scope.q = $routeParams.q || '';
+		$scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
+		
+		$scope.toggleModal = function (index) {
 
-  angular.module('ammicoSearch',['ngResource', 'ngRoute'])
-    .config(function ($routeProvider) {
-      $routeProvider
-        .when('/', {
-          templateUrl: 'search/search.html',
-          controller: 'searchCtrl'
-        });
-    })
-    .controller('searchCtrl', function($scope, $location, $routeParams, searchApi){
-      console.log('search 6',$scope, $location, $routeParams);
-      $scope.q = $routeParams.q || '';
-      $scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp();
-    });
+			var modalInstance = $modal.open({
+				templateUrl: 'search/modal.html',
+				controller: 'ModalInstanceCtrl',
+				size: 'sm'
+			});
 
+			modalInstance.result.then(function (idBook) {
+				var newSlide = {
+					book: idBook,
+					idInventory: $scope.results.hits[index].metas_dict.inventorynumber
+				};
+				searchApi.listSlides.save(newSlide);
+			});
+		};
+	})
+	.controller('ModalInstanceCtrl', function ($scope, searchApi, $modalInstance) {
+		$scope.books = searchApi.listBooks.query({format:'json'});
+		
+		$scope.addToBook = function(idBook){
+			$modalInstance.close(idBook);
+		};
+
+		$scope.cancel = function () {
+			$modalInstance.dismiss('cancel');
+		};
+	});
 })();