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