commonroutesApp/www/js/app.js
www/js/app.jsRaw
1// Ionic Starter App
2
3// angular.module is a global place for creating, registering and retrieving Angular modules
4// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
5// the 2nd parameter is an array of 'requires'
6// 'starter.controllers' is found in controllers.js
7
8
9//var urlapi = "http://localhost:3000/api/";
10//var urlapi = "http://192.168.1.36:3000/api/";
11//var urlapi = "http://37.59.123.45:3000/api/";
12var urlapi = "http://routes.fair.coop:3000/api/";
13
14angular.module('starter', [
15 'ionic',
16 'ngCordova',
17 'pascalprecht.translate',
18 'app.login',
19 'app.signup',
20 'app.menu',
21 'app.footerMenu',
22 'app.main',
23 'app.search',
24 'app.travels',
25 'app.travel',
26 'app.newTravel',
27 'app.offerCar',
28 'app.askForCar',
29 'app.askForPackage',
30 'app.users',
31 'app.user',
32 'app.userTravels',
33 'app.userLikes',
34 'app.editUser',
35 'app.notifications',
36 'app.settings',
37 'app.password',
38 'app.help'
39 ])
40
41 .run(function($ionicPlatform) {
42 $ionicPlatform.ready(function() {
43 // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
44 // for form inputs)
45 if (window.cordova && window.cordova.plugins.Keyboard) {
46 cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
47 cordova.plugins.Keyboard.disableScroll(true);
48
49 }
50 if (window.StatusBar) {
51 // org.apache.cordova.statusbar required
52 StatusBar.styleDefault();
53 }
54 });
55 })
56
57 .config(function($stateProvider, $urlRouterProvider) {
58 $stateProvider
59
60 .state('app', {
61 cache: false,
62 url: '/app',
63 abstract: true,
64 templateUrl: 'templates/menu.html',
65 controller: 'MenuCtrl'
66 })
67 .state('app.main', {
68 cache: false,
69 url: '/main',
70 views: {
71 'menuContent': {
72 templateUrl: 'templates/main.html',
73 controller: 'MainCtrl'
74 }
75 }
76 })
77 .state('app.login', {
78 url: '/login',
79 views: {
80 'menuContent': {
81 templateUrl: 'templates/login.html',
82 controller: 'LoginCtrl'
83 }
84 }
85 })
86 .state('app.signup', {
87 url: '/signup',
88 views: {
89 'menuContent': {
90 templateUrl: 'templates/signup.html',
91 controller: 'SignupCtrl'
92 }
93 }
94 })
95 .state('app.search', {
96 url: '/search',
97 views: {
98 'menuContent': {
99 templateUrl: 'templates/search.html',
100 controller: 'SearchCtrl'
101 }
102 }
103 })
104 .state('app.travels', {
105 url: '/travels',
106 views: {
107 'menuContent': {
108 templateUrl: 'templates/travels.html',
109 controller: 'TravelsCtrl'
110 }
111 }
112 })
113
114 .state('app.travel', {
115 url: '/travels/:travelid',
116 views: {
117 'menuContent': {
118 templateUrl: 'templates/travel.html',
119 controller: 'TravelCtrl'
120 }
121 }
122 })
123
124 .state('app.newTravel', {
125 url: '/newTravel',
126 views: {
127 'menuContent': {
128 templateUrl: 'templates/newTravel.html',
129 controller: 'NewTravelCtrl'
130 }
131 }
132 })
133 .state('app.offerCar', {
134 url: '/offerCar',
135 views: {
136 'menuContent': {
137 templateUrl: 'templates/offerCar.html',
138 controller: 'OfferCarCtrl'
139 }
140 }
141 })
142 .state('app.askForCar', {
143 url: '/askForCar',
144 views: {
145 'menuContent': {
146 templateUrl: 'templates/askForCar.html',
147 controller: 'AskForCarCtrl'
148 }
149 }
150 })
151 .state('app.askForPackage', {
152 url: '/askForPackage',
153 views: {
154 'menuContent': {
155 templateUrl: 'templates/askForPackage.html',
156 controller: 'AskForPackageCtrl'
157 }
158 }
159 })
160 .state('app.users', {
161 url: '/users',
162 views: {
163 'menuContent': {
164 templateUrl: 'templates/users.html',
165 controller: 'UsersCtrl'
166 }
167 }
168 })
169 .state('app.user', {
170 url: '/users/:userid',
171 views: {
172 'menuContent': {
173 templateUrl: 'templates/user.html',
174 controller: 'UserCtrl'
175 }
176 }
177 })
178 .state('app.userTravels', {
179 url: '/users/userTravels/:userid',
180 views: {
181 'menuContent': {
182 templateUrl: 'templates/userTravels.html',
183 controller: 'UserTravelsCtrl'
184 }
185 }
186 })
187 .state('app.userLikes', {
188 url: '/users/userLikes/:userid',
189 views: {
190 'menuContent': {
191 templateUrl: 'templates/userLikes.html',
192 controller: 'UserLikesCtrl'
193 }
194 }
195 })
196 .state('app.editUser', {
197 url: '/editUser',
198 views: {
199 'menuContent': {
200 templateUrl: 'templates/editUser.html',
201 controller: 'EditUserCtrl'
202 }
203 }
204 })
205 .state('app.notifications', {
206 url: '/notifications',
207 views: {
208 'menuContent': {
209 templateUrl: 'templates/notifications.html',
210 controller: 'NotificationsCtrl'
211 }
212 }
213 })
214 .state('app.settings', {
215 url: '/settings',
216 views: {
217 'menuContent': {
218 templateUrl: 'templates/settings.html',
219 controller: 'SettingsCtrl'
220 }
221 }
222 })
223 .state('app.password', {
224 url: '/password',
225 views: {
226 'menuContent': {
227 templateUrl: 'templates/password.html',
228 controller: 'PasswordCtrl'
229 }
230 }
231 })
232 .state('app.help', {
233 url: '/help',
234 views: {
235 'menuContent': {
236 templateUrl: 'templates/help.html',
237 controller: 'HelpCtrl'
238 }
239 }
240 });
241 // if none of the above states are matched, use this as the fallback
242 if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
243 if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
244 window.location = '#/app/main';
245 }
246 $urlRouterProvider.otherwise('/app/main');
247 } else {
248 if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
249 console.log("removing data, and going to login");
250 localStorage.removeItem("cim_app_token");
251 localStorage.removeItem("cim_app_userdata");
252 window.location = "#/app/login";
253 $urlRouterProvider.otherwise('/app/login');
254 }
255 }
256 })
257
258
259
260 /* translator */
261 .config(['$translateProvider', function($translateProvider) {
262
263 /* get lang from the file translations.js */
264 for (lang in translations) {
265 $translateProvider.translations(lang, translations[lang]);
266 }
267
268 if (window.localStorage.getItem('lang')) {
269 $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
270 } else {
271 $translateProvider.preferredLanguage('english');
272 };
273
274 $translateProvider.useSanitizeValueStrategy('escape');
275
276 }])
277 .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
278 return {
279 request: function(config) {
280 return config;
281 },
282 requestError: function(config) {
283 return config;
284 },
285 response: function(res) {
286 return res;
287 },
288 responseError: function(res) {
289 return res;
290 }
291 }
292 })
293 .factory('api', function($http) {
294 return {
295 init: function() {
296 $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
297 $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
298 }
299 };
300 })
301 .run(function(api) {
302 api.init();
303 });