client/app/visites/visites_controller.js
author rougeronj
Tue, 09 Jun 2015 19:10:45 +0200
changeset 146 c6fa8ee3f562
parent 99 c7c424e9eed5
child 170 533a98367f99
permissions -rw-r--r--
refactor idArticle to id_article and idInventory to id_inventory remove "/" from resource path
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
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
     8
        $scope.books = Book.query({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
     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++) {
146
c6fa8ee3f562 refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents: 99
diff changeset
    14
                if (data[i].id_article){
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
                    data[i].slides = Slide.query({idBook:data[i].id, limit: 5, 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
    16
                }
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    17
            }    
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
        });
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
        $scope.toggleModal = function (index) {
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    21
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
    22
            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
    23
                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
    24
                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
    25
                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
    26
            });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    27
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
    28
            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
    29
                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
    30
                    book: idBook,
146
c6fa8ee3f562 refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents: 99
diff changeset
    31
                    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
    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
                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
    34
            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    35
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    36
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    37
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
    38
        $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
    39
            $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
    40
                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
    41
                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
    42
            }).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
    43
                //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
    44
                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
    45
                    $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
    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
        };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    49
        
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    50
    })
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    51
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    52
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
    53
    .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
    54
        //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
    55
      
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
       $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
    57
           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
    58
              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
    59
                  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
    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
          });
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
       });
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
       $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
    64
            $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
    65
                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
    66
                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
    67
            }).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
    68
                //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
    69
                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
    70
                    $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
    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
            });
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    73
        };
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    74
    })
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    75
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
    .controller('ModalAddVisitesCtrl', function($scope, $modalInstance, Book) {
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    78
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
    79
        $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
    80
            $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
    81
//            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
    82
//            });
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
        };
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
        $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
    85
            $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
    86
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    87
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
    88
        $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
    89
        
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
        $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
    91
            $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
    92
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    93
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
    94
        $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
    95
            $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
    96
        };
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
    97
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
    98
    
c7c424e9eed5 refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents: 91
diff changeset
    99
    });
91
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
   100
f7a844a9079e merge the changes of Camille
rougeronj
parents:
diff changeset
   101
})();