client/app/app.js
changeset 91 f7a844a9079e
parent 57 388b29d38b44
child 93 4b167851ee7d
equal deleted inserted replaced
90:faf2cdb47813 91:f7a844a9079e
     1 (function(){
     1 (function(){
     2 	'use strict';
     2     'use strict';
     3 
     3 
     4 	angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoBooks', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'templates' ])
     4     angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoMyvisit', 'ammicoBooks', 'ammicoVisites', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'templates' ])
     5 	.config(function($routeProvider) {
     5     .config(function($routeProvider) {
     6 		$routeProvider.
     6         $routeProvider.
     7 		when('/', {
     7         when('/', {
     8 			controller: 'homeCtrl',
     8             controller: 'homeCtrl',
     9 			templateUrl: 'home/home.html',
     9             templateUrl: 'home/home.html',
    10 			authRequired: false
    10             authRequired: false
    11 		}).
    11         }).
    12 		when('/books', {
    12         when('/my_visit', {
    13 			controller: 'booksCtrl',
    13             controller: 'my_visitCtrl',
    14 			templateUrl: 'books/books.html',
    14             templateUrl: 'my_visit/my_visit.html',
    15 			authRequired: true
    15             authRequired: true
    16 		}).
    16         }).
    17 		when('/books/:idBook', {
    17         when('/books', {
    18 			controller: 'bookCtrl',
    18             controller: 'booksCtrl',
    19 			templateUrl: 'books/book.html',
    19             templateUrl: 'books/books.html'
    20 			authRequired: true
    20         }).
    21 		}).
    21         when('/books/:idBook', {
    22 		when('/slide/:idSlide', {
    22             controller: 'bookCtrl',
    23 			controller: 'slidesCtrl',
    23             templateUrl: 'books/book.html',
    24 			templateUrl: 'slides/slides.html',
    24             authRequired: true
    25 			authRequired: true
    25         }).
    26 		}).
    26         when('/visites', {
    27 		when('/slideshow/', {
    27             controller: 'visitesCtrl',
    28 			controller: 'slideshowCtrl',
    28             templateUrl: 'visites/visites.html',
    29 			templateUrl: 'slideshow/slideshow.html',
    29             authRequired: true
    30 			authRequired: true
    30         }).
    31 		}).
    31         when('/visites/:idVisit', {
    32 		when('/slideshow/:iSlide', {
    32             controller: 'visiteCtrl',
    33 			controller: 'slideshowCtrl',
    33             templateUrl: 'visites/visite.html',
    34 			templateUrl: 'slideshow/slideshow.html',
    34             authRequired: true
    35 			authRequired: true
    35         }).
    36 		}).
    36         when('/slide/:idSlide', {
    37 		when('/search/:q', {
    37             controller: 'slidesCtrl',
    38 			controller: 'searchCtrl',
    38             templateUrl: 'slides/slides.html',
    39 			templateUrl: 'search/search.html',
    39             authRequired: true
    40 			authRequired: true
    40         }).
    41 		}).
    41         when('/slideshow/', {
    42 		when('/auth/:action', {
    42             controller: 'slideshowCtrl',
    43 			controller: 'authCtrl',
    43             templateUrl: 'slideshow/slideshow.html',
    44 			templateUrl: 'home/home.html',
    44             authRequired: true
    45 			authRequired: false
    45         }).
    46 		}).
    46         when('/slideshow/:iSlide', {
    47 		otherwise({
    47             controller: 'slideshowCtrl',
    48 			redirectTo: '/'
    48             templateUrl: 'slideshow/slideshow.html',
    49 		});
    49             authRequired: true
    50 	})
    50         }).
    51 	.run( function($rootScope, $location, $window, $http) {
    51         when('/search/:q', {
    52 		$rootScope.globals = {};
    52             controller: 'searchCtrl',
    53 		if ($window.sessionStorage.token) {
    53             templateUrl: 'search/search.html',
    54 			$rootScope.globals.userLogged = true;
    54             authRequired: true
    55 			$http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token;
    55         }).
    56 		}
    56         when('/auth/:action', {
    57 		$rootScope.$on( '$routeChangeStart', function(event, next) {
    57             controller: 'authCtrl',
    58 			if (next.authRequired && !$rootScope.globals.userLogged) {
    58             templateUrl: 'home/home.html',
    59 				$location.path( '/auth/login' );
    59             authRequired: false
    60 			}
    60         }).
    61 		});
    61         otherwise({
    62 	})
    62             redirectTo: '/'
    63 	.service('searchApi', function($resource, context) {
    63         });
    64 		this.searchResource = function(params){
    64     })
    65 			return $resource(context.urls.searchUrl,  
    65     .run( function($rootScope, $location, $window, $http) {
    66 					{
    66         $rootScope.globals = {};
    67 				callback: 'JSON_CALLBACK'
    67         if ($window.sessionStorage.token) {
    68 					},
    68             $rootScope.globals.userLogged = true;
    69 					{
    69             $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token;
    70 						getJsonp: {
    70         }
    71 							method: 'JSONP',
    71         $rootScope.$on( '$routeChangeStart', function(event, next) {
    72 							params: params,
    72             if (next.authRequired && !$rootScope.globals.userLogged) {
    73 							isArray: false,
    73                 $location.path( '/auth/login' );
    74 							transformResponse: function(data){
    74             }
    75 								// Transform meta list into meta dict
    75         });
    76 								var nb = data.hits.length;
    76     })
    77 								for(var i=0;i<nb;i++){
    77     .service('searchApi', function($resource, context) {
    78 									var nb_metas = data.hits[i].metas.length;
    78         this.searchResource = function(params){
    79 									data.hits[i].metas_dict = {};
    79             return $resource(context.urls.searchUrl,  
    80 									for(var j=0;j<nb_metas;j++){
    80                     {
    81 										if(typeof data.hits[i].metas[j].images==='undefined'){
    81                 callback: 'JSON_CALLBACK'
    82 											data.hits[i].metas_dict[data.hits[i].metas[j].name] = data.hits[i].metas[j].value;
    82                     },
    83 										}
    83                     {
    84 										else{
    84                         getJsonp: {
    85 											data.hits[i].metas_dict.images = data.hits[i].metas[j].images[0].value;
    85                             method: 'JSONP',
    86 										}
    86                             params: params,
    87 									}
    87                             isArray: false,
    88 								}
    88                             transformResponse: function(data){
    89 								return data;
    89                                 // Transform meta list into meta dict
    90 							}
    90                                 var nb = data.hits.length;
    91 						}
    91                                 for(var i=0;i<nb;i++){
    92 					});
    92                                     var nb_metas = data.hits[i].metas.length;
    93 		};
    93                                     data.hits[i].metas_dict = {};
    94 	})
    94                                     for(var j=0;j<nb_metas;j++){
    95 	.service('ammicoApi', function($resource, context, $sce) {
    95                                         if(typeof data.hits[i].metas[j].images==='undefined'){
    96 		this.listBooks = $resource(context.urls.ammicoUrl+'/books');
    96                                             data.hits[i].metas_dict[data.hits[i].metas[j].name] = data.hits[i].metas[j].value;
    97 		this.book = $resource(context.urls.ammicoUrl+'/books/:idBook', {idBook:'@idBook'});
    97                                         }
    98 		this.order = $resource(context.urls.ammicoUrl+'/books/:idBook/order', {idBook:'@idBook'});
    98                                         else{
    99 		this.booksSlides = $resource(context.urls.ammicoUrl+'/books/:idBook/slides', {idBook:'@idBook'});
    99                                             data.hits[i].metas_dict.images = data.hits[i].metas[j].images[0].value;
   100 		this.listSlides= $resource(context.urls.ammicoUrl+'/slides');
   100                                         }
   101 		this.slide = $resource(context.urls.ammicoUrl+'/slides/:idSlide', {idSlide:'@idSlide'});
   101                                     }
   102 		this.sanitizeUrls = function(data){
   102                                 }
   103 			data.details.audio = $sce.trustAsResourceUrl(data.details.audio);
   103                                 return data;
   104 			data.details.video = $sce.trustAsResourceUrl(data.details.video);
   104                             }
   105 			data.audio = $sce.trustAsResourceUrl(data.audio);
   105                         }
   106 			data.video = $sce.trustAsResourceUrl(data.video);
   106                     });
   107 			return data;
   107         };
   108 		};
   108     })
   109 	})
   109     .service('ammicoApi', function($resource, context, $sce) {
   110 	.service('authApi', function($resource, context) {
   110         this.listBooks = $resource(context.urls.ammicoUrl+'/books');
   111 		this.login = $resource(context.urls.ammicoUrl+'/auth/api-token-auth');
   111         this.book = $resource(context.urls.ammicoUrl+'/books/:idBook', {idBook:'@id'});
   112 		this.logout = $resource(context.urls.ammicoUrl+'/auth/logout');
   112         this.order = $resource(context.urls.ammicoUrl+'/books/:idBook/order', {idBook:'@id'});
   113 		this.user = $resource(context.urls.ammicoUrl+'/auth/user');
   113         this.booksSlides = $resource(context.urls.ammicoUrl+'/books/:idBook/slides', {idBook:'@id'});
   114 		this.test = $resource(context.urls.ammicoUrl+'/auth/auth');
   114         this.listSlides= $resource(context.urls.ammicoUrl+'/slides');
   115 	});
   115         this.slide = $resource(context.urls.ammicoUrl+'/slides/:idSlide', {idSlide:'@id'});
       
   116         this.sanitizeUrls = function(data){
       
   117             data.details.audio = $sce.trustAsResourceUrl(data.details.audio);
       
   118             data.details.video = $sce.trustAsResourceUrl(data.details.video);
       
   119             data.audio = $sce.trustAsResourceUrl(data.audio);
       
   120             data.video = $sce.trustAsResourceUrl(data.video);
       
   121             return data;
       
   122         };
       
   123     })
       
   124     .service('authApi', function($resource, context) {
       
   125         this.login = $resource(context.urls.ammicoUrl+'/auth/api-token-auth');
       
   126         this.logout = $resource(context.urls.ammicoUrl+'/auth/logout');
       
   127         this.user = $resource(context.urls.ammicoUrl+'/auth/user');
       
   128         this.test = $resource(context.urls.ammicoUrl+'/auth/auth');
       
   129     });
   116 })();
   130 })();