client/app/search/search_controller.js
author rougeronj
Wed, 27 May 2015 18:59:55 +0200
changeset 97 0afdaa004ee1
parent 82 6a5e84bf859c
child 146 c6fa8ee3f562
permissions -rw-r--r--
replace all the tab by spaces
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
     1
(function(){
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     2
    'use strict';
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
     3
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     4
    angular.module('ammicoSearch',['ngResource', 'ngRoute', 'ui.bootstrap'])
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     5
    .config(function ($routeProvider) {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     6
        $routeProvider
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     7
        .when('/', {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     8
            templateUrl: 'search/search.html',
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
     9
            controller: 'searchCtrl'
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    10
        });
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    11
    })
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    12
    .controller('searchCtrl', function($scope, $location, $routeParams, searchApi, $modal, Slide){
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    13
        $scope.q = $routeParams.q || '';
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    14
        $scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    15
        
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    16
        $scope.toggleModal = function (index) {
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    17
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    18
            var modalInstance = $modal.open({
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    19
                templateUrl: 'search/modal.html',
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    20
                controller: 'ModalInstanceCtrl',
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    21
                size: 'sm'
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    22
            });
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    23
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    24
            modalInstance.result.then(function (idBook) {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    25
                var newSlide = {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    26
                    book: idBook,
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    27
                    idInventory: $scope.results.hits[index].metas_dict.inventorynumber
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    28
                };
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    29
                Slide.save(newSlide);
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    30
            });
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    31
        };
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    32
    })
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    33
    .controller('ModalInstanceCtrl', function ($scope, $modalInstance, Book) {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    34
        $scope.books = Book.query({format:'json'});
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    35
        
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    36
        $scope.addToBook = function(idBook){
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    37
            $modalInstance.close(idBook);
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    38
        };
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
    39
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    40
        $scope.cancel = function () {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    41
            $modalInstance.dismiss('cancel');
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    42
        };
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    43
    });
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    44
})();