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