client/app/search/search_controller.js
author nowmad@23.1.168.192.in-addr.arpa
Wed, 02 Dec 2015 19:34:44 +0100
changeset 201 5f54f408cc44
parent 197 8b87432acffc
permissions -rw-r--r--
send all the stop info to the server
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
    })
188
fd75c66c8e30 fix unused var
rougeronj
parents: 184
diff changeset
    12
    .controller('searchCtrl', function($scope, $location, $routeParams, searchApi, $modal, Slide){
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    13
        $scope.q = $routeParams.q || '';
184
4d01c2d04359 update client version to handle "musée de l'immigration"
rougeronj
parents: 146
diff changeset
    14
        if ($scope.q !== ''){
197
8b87432acffc Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents: 188
diff changeset
    15
          $scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'10', callback: 'JSON_CALLBACK'}).getJsonp();
184
4d01c2d04359 update client version to handle "musée de l'immigration"
rougeronj
parents: 146
diff changeset
    16
        }
197
8b87432acffc Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents: 188
diff changeset
    17
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    18
        $scope.toggleModal = function (index) {
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    19
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    20
            var modalInstance = $modal.open({
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    21
                templateUrl: 'search/modal.html',
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    22
                controller: 'ModalInstanceCtrl',
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    23
                size: 'sm'
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    24
            });
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    25
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    26
            modalInstance.result.then(function (idBook) {
201
5f54f408cc44 send all the stop info to the server
nowmad@23.1.168.192.in-addr.arpa
parents: 197
diff changeset
    27
              var newSlide = $scope.results.collect[index];
5f54f408cc44 send all the stop info to the server
nowmad@23.1.168.192.in-addr.arpa
parents: 197
diff changeset
    28
              delete newSlide.date;
5f54f408cc44 send all the stop info to the server
nowmad@23.1.168.192.in-addr.arpa
parents: 197
diff changeset
    29
              newSlide.book = idBook;
5f54f408cc44 send all the stop info to the server
nowmad@23.1.168.192.in-addr.arpa
parents: 197
diff changeset
    30
              newSlide.research_id = (newSlide.inventorynumber || newSlide.id_stop);
5f54f408cc44 send all the stop info to the server
nowmad@23.1.168.192.in-addr.arpa
parents: 197
diff changeset
    31
              Slide.save(newSlide);
97
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
        };
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    34
    })
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    35
    .controller('ModalInstanceCtrl', function ($scope, $modalInstance, Book) {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    36
        $scope.books = Book.query({format:'json'});
197
8b87432acffc Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents: 188
diff changeset
    37
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    38
        $scope.addToBook = function(idBook){
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    39
            $modalInstance.close(idBook);
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    40
        };
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
    41
97
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    42
        $scope.cancel = function () {
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    43
            $modalInstance.dismiss('cancel');
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    44
        };
0afdaa004ee1 replace all the tab by spaces
rougeronj
parents: 82
diff changeset
    45
    });
1
74bbdd739878 views, path, search...
cavaliet
parents:
diff changeset
    46
})();