client/app/search/search_controller.js
author rougeronj
Fri, 22 May 2015 12:37:37 +0200
changeset 90 faf2cdb47813
parent 82 6a5e84bf859c
child 97 0afdaa004ee1
permissions -rw-r--r--
remove "comment" from the model. Copy the 'comment' field of Jamespot in the 'description' field of the model instead

(function(){
	'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, ammicoApi, $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) {

			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
				};
				ammicoApi.listSlides.save(newSlide);
			});
		};
	})
	.controller('ModalInstanceCtrl', function ($scope, ammicoApi, $modalInstance) {
		$scope.books = ammicoApi.listBooks.query({format:'json'});
		
		$scope.addToBook = function(idBook){
			$modalInstance.close(idBook);
		};

		$scope.cancel = function () {
			$modalInstance.dismiss('cancel');
		};
	});
})();