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