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="https://collectivecar.paas.primustech.io/api/";
11var urlapi="http://147.83.7.158:3000/api/";
12
13
14angular.module('starter', [
15 'ionic',
16 'ngMaterial',
17 'ngCordova',
18 'pascalprecht.translate',
19 'app.login',
20 'app.signup',
21 'app.menu',
22 'app.footerMenu',
23 'app.main',
24 'app.search',
25 'app.travels',
26 'app.travel',
27 'app.newTravel',
28 'app.offerCar',
29/* 'app.askCar',
30 'app.askPackage',*/
31 'app.users',
32 'app.user',
33 'app.userTravels',
34 'app.userLikes',
35 'app.editUser',
36 'app.notifications',
37 'app.settings',
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 url: '/app',
62 abstract: true,
63 templateUrl: 'templates/menu.html',
64 controller: 'MenuCtrl'
65 })
66 .state('app.main', {
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.users', {
141 url: '/users',
142 views: {
143 'menuContent': {
144 templateUrl: 'templates/users.html',
145 controller: 'UsersCtrl'
146 }
147 }
148 })
149 .state('app.user', {
150 url: '/users/:userid',
151 views: {
152 'menuContent': {
153 templateUrl: 'templates/user.html',
154 controller: 'UserCtrl'
155 }
156 }
157 })
158 .state('app.userTravels', {
159 url: '/users/userTravels/:userid',
160 views: {
161 'menuContent': {
162 templateUrl: 'templates/userTravels.html',
163 controller: 'UserTravelsCtrl'
164 }
165 }
166 })
167 .state('app.userLikes', {
168 url: '/users/userLikes/:userid',
169 views: {
170 'menuContent': {
171 templateUrl: 'templates/userLikes.html',
172 controller: 'UserLikesCtrl'
173 }
174 }
175 })
176 .state('app.editUser', {
177 url: '/editUser',
178 views: {
179 'menuContent': {
180 templateUrl: 'templates/editUser.html',
181 controller: 'EditUserCtrl'
182 }
183 }
184 })
185 .state('app.notifications', {
186 url: '/notifications',
187 views: {
188 'menuContent': {
189 templateUrl: 'templates/notifications.html',
190 controller: 'NotificationsCtrl'
191 }
192 }
193 })
194 .state('app.settings', {
195 url: '/settings',
196 views: {
197 'menuContent': {
198 templateUrl: 'templates/settings.html',
199 controller: 'SettingsCtrl'
200 }
201 }
202 })
203 .state('app.help', {
204 url: '/help',
205 views: {
206 'menuContent': {
207 templateUrl: 'templates/help.html',
208 controller: 'HelpCtrl'
209 }
210 }
211 });
212 // if none of the above states are matched, use this as the fallback
213 if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
214 if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
215 window.location = '#/app/main';
216 }
217 $urlRouterProvider.otherwise('/app/main');
218 } else {
219 if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
220 console.log("removing data, and going to login");
221 localStorage.removeItem("cim_app_token");
222 localStorage.removeItem("cim_app_userdata");
223 window.location = "#/app/login";
224 $urlRouterProvider.otherwise('/app/login');
225 }
226 }
227 })
228
229
230
231 /* translator */
232 .config(['$translateProvider', function($translateProvider) {
233
234 /* get lang from the file translations.js */
235 for (lang in translations) {
236 $translateProvider.translations(lang, translations[lang]);
237 }
238
239 if (window.localStorage.getItem('lang')) {
240 $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
241 } else {
242 $translateProvider.preferredLanguage('english');
243 };
244
245 $translateProvider.useSanitizeValueStrategy('escape');
246
247 }])
248 .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
249 return {
250 request: function (config) {
251 return config;
252 },
253 requestError: function (config) {
254 return config;
255 },
256 response: function (res) {
257 return res;
258 },
259 responseError: function (res) {
260 return res;
261 }
262 }
263 })
264 .factory('api', function ($http) {
265 return {
266 init: function () {
267 $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
268 $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
269 }
270 };
271 })
272 .run(function (api) {
273 api.init();
274 });