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