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