client/app/search/search_controller.js
changeset 97 0afdaa004ee1
parent 82 6a5e84bf859c
child 146 c6fa8ee3f562
equal deleted inserted replaced
96:3542155549e4 97:0afdaa004ee1
     1 (function(){
     1 (function(){
     2 	'use strict';
     2     'use strict';
     3 
     3 
     4 	angular.module('ammicoSearch',['ngResource', 'ngRoute', 'ui.bootstrap'])
     4     angular.module('ammicoSearch',['ngResource', 'ngRoute', 'ui.bootstrap'])
     5 	.config(function ($routeProvider) {
     5     .config(function ($routeProvider) {
     6 		$routeProvider
     6         $routeProvider
     7 		.when('/', {
     7         .when('/', {
     8 			templateUrl: 'search/search.html',
     8             templateUrl: 'search/search.html',
     9 			controller: 'searchCtrl'
     9             controller: 'searchCtrl'
    10 		});
    10         });
    11 	})
    11     })
    12 	.controller('searchCtrl', function($scope, $location, $routeParams, searchApi, ammicoApi, $modal){
    12     .controller('searchCtrl', function($scope, $location, $routeParams, searchApi, $modal, Slide){
    13 		$scope.q = $routeParams.q || '';
    13         $scope.q = $routeParams.q || '';
    14 		$scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
    14         $scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
    15 		
    15         
    16 		$scope.toggleModal = function (index) {
    16         $scope.toggleModal = function (index) {
    17 
    17 
    18 			var modalInstance = $modal.open({
    18             var modalInstance = $modal.open({
    19 				templateUrl: 'search/modal.html',
    19                 templateUrl: 'search/modal.html',
    20 				controller: 'ModalInstanceCtrl',
    20                 controller: 'ModalInstanceCtrl',
    21 				size: 'sm'
    21                 size: 'sm'
    22 			});
    22             });
    23 
    23 
    24 			modalInstance.result.then(function (idBook) {
    24             modalInstance.result.then(function (idBook) {
    25 				var newSlide = {
    25                 var newSlide = {
    26 					book: idBook,
    26                     book: idBook,
    27 					idInventory: $scope.results.hits[index].metas_dict.inventorynumber
    27                     idInventory: $scope.results.hits[index].metas_dict.inventorynumber
    28 				};
    28                 };
    29 				ammicoApi.listSlides.save(newSlide);
    29                 Slide.save(newSlide);
    30 			});
    30             });
    31 		};
    31         };
    32 	})
    32     })
    33 	.controller('ModalInstanceCtrl', function ($scope, ammicoApi, $modalInstance) {
    33     .controller('ModalInstanceCtrl', function ($scope, $modalInstance, Book) {
    34 		$scope.books = ammicoApi.listBooks.query({format:'json'});
    34         $scope.books = Book.query({format:'json'});
    35 		
    35         
    36 		$scope.addToBook = function(idBook){
    36         $scope.addToBook = function(idBook){
    37 			$modalInstance.close(idBook);
    37             $modalInstance.close(idBook);
    38 		};
    38         };
    39 
    39 
    40 		$scope.cancel = function () {
    40         $scope.cancel = function () {
    41 			$modalInstance.dismiss('cancel');
    41             $modalInstance.dismiss('cancel');
    42 		};
    42         };
    43 	});
    43     });
    44 })();
    44 })();