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