client/app/search/search_controller.js
author rougeronj
Tue, 31 Mar 2015 12:24:05 +0200
changeset 47 dd750778535c
parent 8 824c87a9084c
child 55 10fd23382e76
permissions -rw-r--r--
udate add fonction from a research and add a modal to select the book we want to add the slide
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
     1
(function(){
47
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     2
	'use strict';
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     3
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     4
	angular.module('ammicoSearch',['ngResource', 'ngRoute', 'ui.bootstrap'])
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     5
	.config(function ($routeProvider) {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     6
		$routeProvider
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     7
		.when('/', {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     8
			templateUrl: 'search/search.html',
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
     9
			controller: 'searchCtrl'
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    10
		});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    11
	})
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    12
	.controller('searchCtrl', function($scope, $location, $routeParams, searchApi, $modal){
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    13
		$scope.q = $routeParams.q || '';
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    14
		$scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    15
		
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    16
		$scope.toggleModal = function (index) {
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    17
47
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    18
			var modalInstance = $modal.open({
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    19
				templateUrl: 'search/modal.html',
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    20
				controller: 'ModalInstanceCtrl',
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    21
				size: 'sm'
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    22
			});
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    23
47
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    24
			modalInstance.result.then(function (idBook) {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    25
				var newSlide = {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    26
					book: idBook,
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    27
					idInventory: $scope.results.hits[index].metas_dict.inventorynumber
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    28
				};
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    29
				searchApi.listSlides.save(newSlide);
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    30
			});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    31
		};
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    32
	})
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    33
	.controller('ModalInstanceCtrl', function ($scope, searchApi, $modalInstance) {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    34
		$scope.books = searchApi.listBooks.query({format:'json'});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    35
		
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    36
		$scope.addToBook = function(idBook){
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    37
			$modalInstance.close(idBook);
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    38
		};
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    39
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    40
		$scope.cancel = function () {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    41
			$modalInstance.dismiss('cancel');
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    42
		};
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 8
diff changeset
    43
	});
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    44
})();