client/app/visites/visites_controller.js
author rougeronj
Thu, 11 Jun 2015 15:37:51 +0200
changeset 170 533a98367f99
parent 146 c6fa8ee3f562
child 184 4d01c2d04359
permissions -rw-r--r--
filter book in the request through 'type' parameter instead of filtering on client side
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
     1
(function(){
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     2
    'use strict';
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
     3
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     4
    angular.module('ammicoVisites',['ngRoute', 'ui.sortable'])
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     5
    .controller('visitesCtrl', function($scope, $location, $modal, Book, Slide){
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
     6
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     7
        //get list book
170
533a98367f99 filter book in the request through 'type' parameter instead of filtering on client side
rougeronj
parents: 146
diff changeset
     8
        $scope.visits = Book.query({type: 'visit', format:'json'}, function(data){
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     9
            data.sort(function (a, b) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    10
                return a.date < b.date;
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    11
            });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    12
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    13
            for (var i = 0; i < data.length; i++) {
170
533a98367f99 filter book in the request through 'type' parameter instead of filtering on client side
rougeronj
parents: 146
diff changeset
    14
                data[i].slides = Slide.query({idBook:data[i].id, limit: 5, format:'json'});
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    15
            }    
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    16
        });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    17
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    18
        $scope.toggleModal = function (index) {
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    19
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    20
            var modalInstance = $modal.open({
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    21
                templateUrl: 'visites/add_book_modal.html',
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    22
                controller: 'ModalAddVisitesCtrl',
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    23
                size: 'sm'
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    24
            });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    25
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    26
            modalInstance.result.then(function (idBook) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    27
                var newSlide = {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    28
                    book: idBook,
146
c6fa8ee3f562 refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents: 99
diff changeset
    29
                    id_inventory: $scope.results.hits[index].metas_dict.inventorynumber
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    30
                };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    31
                Slide.save(newSlide);
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    32
            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    33
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    34
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    35
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    36
        $scope.addBook = function (idParent) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    37
            $modal.open({
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    38
                templateUrl: 'visites/add_modal_visites.html',
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    39
                controller: 'ModalAddVisitesCtrl'
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    40
            }).result.then(function (title) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    41
                //add book with the title written in the modal
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    42
                Book.save({idParent:idParent, title: title}, function(newBook){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    43
                    $scope.books.push(newBook);
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    44
                });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    45
            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    46
        };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    47
        
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    48
    })
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    49
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    50
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    51
    .controller('visiteCtrl', function($scope, $routeParams, $modal, Book, Slide) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    52
        //get the slides of a book
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    53
      
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    54
       $scope.visit = Book.get({idBook:$routeParams.idVisit, format:'json'}, function(data){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    55
           data.slides = Slide.query({idBook: data.id, format:'json'}, function(data){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    56
              data.sort(function (a, b) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    57
                  return a.orderIndex > b.orderIndex;
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    58
              });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    59
          });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    60
       });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    61
       $scope.addBook = function (idParent) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    62
            $modal.open({
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    63
                templateUrl: 'visites/add_modal_visites.html',
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    64
                controller: 'ModalAddVisitesCtrl'
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    65
            }).result.then(function (title) {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    66
                //add book with the title written in the modal
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    67
                Book.save({idParent:idParent, title: title}, function(newBook){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    68
                    $scope.books.push(newBook);
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    69
                });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    70
            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    71
        };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    72
    })
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    73
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    74
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    75
    .controller('ModalAddVisitesCtrl', function($scope, $modalInstance, Book) {
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    76
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    77
        $scope.add = function(){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    78
            $modalInstance.close($scope.title);
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    79
//            ammicoApi.listBooks.save({title: $scope.title}, function(newBook){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    80
//            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    81
        };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    82
        $scope.cancel = function () {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    83
            $modalInstance.dismiss('cancel');
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    84
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    85
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    86
        $scope.books = Book.query({format:'json'});
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    87
        
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    88
        $scope.addToBook = function(idBook){
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    89
            $modalInstance.close(idBook);
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    90
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    91
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    92
        $scope.cancel = function () {
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    93
            $modalInstance.dismiss('cancel');
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    94
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    95
99
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    96
    
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    97
    });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    98
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    99
})();