# HG changeset patch # User rougeronj # Date 1432291636 -7200 # Node ID f7a844a9079e8a176e575d0d3aef105e23592674 # Parent faf2cdb47813c0dd888713e767cd13ed4ea4dea2 merge the changes of Camille diff -r faf2cdb47813 -r f7a844a9079e client/app/app.js --- a/client/app/app.js Fri May 22 12:37:37 2015 +0200 +++ b/client/app/app.js Fri May 22 12:47:16 2015 +0200 @@ -1,116 +1,130 @@ (function(){ - 'use strict'; + 'use strict'; - angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoBooks', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'templates' ]) - .config(function($routeProvider) { - $routeProvider. - when('/', { - controller: 'homeCtrl', - templateUrl: 'home/home.html', - authRequired: false - }). - when('/books', { - controller: 'booksCtrl', - templateUrl: 'books/books.html', - authRequired: true - }). - when('/books/:idBook', { - controller: 'bookCtrl', - templateUrl: 'books/book.html', - authRequired: true - }). - when('/slide/:idSlide', { - controller: 'slidesCtrl', - templateUrl: 'slides/slides.html', - authRequired: true - }). - when('/slideshow/', { - controller: 'slideshowCtrl', - templateUrl: 'slideshow/slideshow.html', - authRequired: true - }). - when('/slideshow/:iSlide', { - controller: 'slideshowCtrl', - templateUrl: 'slideshow/slideshow.html', - authRequired: true - }). - when('/search/:q', { - controller: 'searchCtrl', - templateUrl: 'search/search.html', - authRequired: true - }). - when('/auth/:action', { - controller: 'authCtrl', - templateUrl: 'home/home.html', - authRequired: false - }). - otherwise({ - redirectTo: '/' - }); - }) - .run( function($rootScope, $location, $window, $http) { - $rootScope.globals = {}; - if ($window.sessionStorage.token) { - $rootScope.globals.userLogged = true; - $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token; - } - $rootScope.$on( '$routeChangeStart', function(event, next) { - if (next.authRequired && !$rootScope.globals.userLogged) { - $location.path( '/auth/login' ); - } - }); - }) - .service('searchApi', function($resource, context) { - this.searchResource = function(params){ - return $resource(context.urls.searchUrl, - { - callback: 'JSON_CALLBACK' - }, - { - getJsonp: { - method: 'JSONP', - params: params, - isArray: false, - transformResponse: function(data){ - // Transform meta list into meta dict - var nb = data.hits.length; - for(var i=0;i + + + + + + \ No newline at end of file diff -r faf2cdb47813 -r f7a844a9079e client/app/books/book.html --- a/client/app/books/book.html Fri May 22 12:37:37 2015 +0200 +++ b/client/app/books/book.html Fri May 22 12:47:16 2015 +0200 @@ -1,14 +1,31 @@ -

Books {{idBook}} :

+ + + + {{ parentBook.title }} + + + + + + {{parentBook.slides.length}} objets + - +
+ {{book.title}} +
+
+
diff -r faf2cdb47813 -r f7a844a9079e client/app/books/books.html --- a/client/app/books/books.html Fri May 22 12:37:37 2015 +0200 +++ b/client/app/books/books.html Fri May 22 12:47:16 2015 +0200 @@ -1,27 +1,50 @@ -

Liste des books :

+ - + + - {{ parentBook.title }} - - - + + {{ parentBook.title }} + + + + Nouveau Book + + + {{parentBook.slides.length}} objets + + + +
+ {{book.title }} +
+ + + +
- - - Autres Books - - - +
\ No newline at end of file diff -r faf2cdb47813 -r f7a844a9079e client/app/books/books_controller.js --- a/client/app/books/books_controller.js Fri May 22 12:37:37 2015 +0200 +++ b/client/app/books/books_controller.js Fri May 22 12:47:16 2015 +0200 @@ -7,7 +7,30 @@ data.sort(function (a, b) { return a.date < b.date; }); + + for (var i = 0; i < data.length; i++) { + if (data[i].idArticle === null){ + data[i].slides = ammicoApi.booksSlides.query({idBook:data[i].id, format:'json'}); + } + } }); + + $scope.toggleModal = function (index) { + + var modalInstance = $modal.open({ + templateUrl: 'books/add_book_modal.html', + controller: 'ModalAddBookCtrl', + size: 'sm' + }); + + modalInstance.result.then(function (idBook) { + var newSlide = { + book: idBook, + idInventory: $scope.results.hits[index].metas_dict.inventorynumber + }; + ammicoApi.listSlides.save(newSlide); + }); + }; $scope.searchSubmit = function(){ $location.path('/search/' + $scope.q); @@ -36,15 +59,43 @@ } }; }) - .controller('bookCtrl', function($scope, ammicoApi, $routeParams) { - $scope.slides = ammicoApi.booksSlides.query({idBook:$routeParams.idBook, format:'json'}, function(data){ - data.sort(function (a, b) { - return a.orderIndex > b.orderIndex; + + .controller('bookCtrl', function($scope, $location, ammicoApi, $routeParams, $modal) { + $scope.parentBook = ammicoApi.book.get({idBook:$routeParams.idBook, format:'json'}, function(data){ + data.slides = ammicoApi.booksSlides.query({idBook: data.id, format:'json'}, function(data){ + data.sort(function (a, b) { + return a.orderIndex > b.orderIndex; + }); }); }); + + $scope.toggleFavorite = function (index) { + + $scope.parentBook.slides[index].favorite = !$scope.parentBook.slides[index].favorite; + $scope.parentBook.slides[index].$save({format:'json'}); + //$scope.slide.$save({idSlide:$scope.slide.id, format:'json'}); + }; + + $scope.toggleModal = function (index) { + + var modalInstance = $modal.open({ + templateUrl: 'books/add_book_modal.html', + controller: 'ModalAddBookCtrl', + size: 'sm' + }); + + modalInstance.result.then(function (idBook) { + var newSlide = { + book: idBook, + idInventory: $scope.results.hits[index].metas_dict.inventorynumber + }; + ammicoApi.listSlides.save(newSlide); + }); + }; + $scope.sortableOptions = { stop: function() { - var order = $scope.slides.map(function(i){ + var order = $scope.parentBook.slides.map(function(i){ return i.id; }); ammicoApi.order.save({idBook:$routeParams.idBook}, {order: order}); @@ -52,17 +103,18 @@ }; $scope.deleteItem = function(i){ - if(0<=i && i<$scope.slides.length){ - if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ - ammicoApi.slide.delete({idSlide: $scope.slides[i].id}, function(){ - $scope.slides.splice(i, 1); - }, - function(error) { - if (error.status === 404){ - $scope.slides.splice(i, 1); - } - }); - } + if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ + $scope.parentBook.slides[i].$delete(); + //if(0<=i && i<$scope.slides.length){ +// ammicoApi.slide.delete({idSlide: $scope.slides[i].id}, function(){ +// $scope.slides.splice(i, 1); +// }, +// function(error) { +// if (error.status === 404){ +// $scope.slides.splice(i, 1); +// } +// }); +// } } }; }) @@ -75,6 +127,16 @@ }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); + } + ; + $scope.books = ammicoApi.listBooks.query({format:'json'}); + + $scope.addToBook = function(idBook){ + $modalInstance.close(idBook); + }; + + $scope.cancel = function () { + $modalInstance.dismiss('cancel'); }; }); })(); diff -r faf2cdb47813 -r f7a844a9079e client/app/index.html --- a/client/app/index.html Fri May 22 12:37:37 2015 +0200 +++ b/client/app/index.html Fri May 22 12:47:16 2015 +0200 @@ -23,7 +23,7 @@ -