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="https://collectivecar.paas.primustech.io/api/";
11
12
13angular.module('starter', [
14 'ionic',
15 'pascalprecht.translate',
16 'app.login',
17 'app.signup',
18 'app.menu',
19 'app.footerMenu',
20 'app.main',
21 'app.travels',
22 'app.travel',
23 'app.newPublication',
24 'app.offerCar',
25/* 'app.askCar',
26 'app.askPackage',*/
27 'app.users',
28 'app.user',
29 'app.notifications',
30 'app.settings',
31 'app.help'
32 ])
33
34 .run(function($ionicPlatform) {
35 $ionicPlatform.ready(function() {
36 // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
37 // for form inputs)
38 if (window.cordova && window.cordova.plugins.Keyboard) {
39 cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
40 cordova.plugins.Keyboard.disableScroll(true);
41
42 }
43 if (window.StatusBar) {
44 // org.apache.cordova.statusbar required
45 StatusBar.styleDefault();
46 }
47 });
48 })
49
50 .config(function($stateProvider, $urlRouterProvider) {
51 $stateProvider
52
53 .state('app', {
54 url: '/app',
55 abstract: true,
56 templateUrl: 'templates/menu.html',
57 controller: 'MenuCtrl'
58 })
59 .state('app.main', {
60 url: '/main',
61 views: {
62 'menuContent': {
63 templateUrl: 'templates/main.html',
64 controller: 'MainCtrl'
65 }
66 }
67 })
68 .state('app.login', {
69 url: '/login',
70 views: {
71 'menuContent': {
72 templateUrl: 'templates/login.html',
73 controller: 'LoginCtrl'
74 }
75 }
76 })
77 .state('app.signup', {
78 url: '/signup',
79 views: {
80 'menuContent': {
81 templateUrl: 'templates/signup.html',
82 controller: 'SignupCtrl'
83 }
84 }
85 })
86 .state('app.travels', {
87 url: '/travels',
88 views: {
89 'menuContent': {
90 templateUrl: 'templates/travels.html',
91 controller: 'TravelsCtrl'
92 }
93 }
94 })
95
96 .state('app.travel', {
97 url: '/travels/:travelid',
98 views: {
99 'menuContent': {
100 templateUrl: 'templates/travel.html',
101 controller: 'TravelCtrl'
102 }
103 }
104 })
105
106 .state('app.newPublication', {
107 url: '/newPublication',
108 views: {
109 'menuContent': {
110 templateUrl: 'templates/newPublication.html',
111 controller: 'NewPublicationCtrl'
112 }
113 }
114 })
115 .state('app.offerCar', {
116 url: '/offerCar',
117 views: {
118 'menuContent': {
119 templateUrl: 'templates/offerCar.html',
120 controller: 'OfferCarCtrl'
121 }
122 }
123 })
124 .state('app.users', {
125 url: '/users',
126 views: {
127 'menuContent': {
128 templateUrl: 'templates/users.html',
129 controller: 'UsersCtrl'
130 }
131 }
132 })
133 .state('app.user', {
134 url: '/users/:userid',
135 views: {
136 'menuContent': {
137 templateUrl: 'templates/user.html',
138 controller: 'UserCtrl'
139 }
140 }
141 })
142 .state('app.notifications', {
143 url: '/notifications',
144 views: {
145 'menuContent': {
146 templateUrl: 'templates/notifications.html',
147 controller: 'NotificationsCtrl'
148 }
149 }
150 })
151 .state('app.settings', {
152 url: '/settings',
153 views: {
154 'menuContent': {
155 templateUrl: 'templates/settings.html',
156 controller: 'SettingsCtrl'
157 }
158 }
159 })
160 .state('app.help', {
161 url: '/help',
162 views: {
163 'menuContent': {
164 templateUrl: 'templates/help.html',
165 controller: 'HelpCtrl'
166 }
167 }
168 });
169 // if none of the above states are matched, use this as the fallback
170 if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
171 if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
172 window.location = '#/app/main';
173 }
174 $urlRouterProvider.otherwise('/app/main');
175 } else {
176 if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
177 console.log("removing data, and going to login");
178 localStorage.removeItem("cim_app_token");
179 localStorage.removeItem("cim_app_userdata");
180 window.location = "#/app/login";
181 $urlRouterProvider.otherwise('/app/login');
182 }
183 }
184 })
185
186
187
188 /* translator */
189 .config(['$translateProvider', function($translateProvider) {
190
191 /* get lang from the file translations.js */
192 for (lang in translations) {
193 $translateProvider.translations(lang, translations[lang]);
194 }
195
196 if (window.localStorage.getItem('lang')) {
197 $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
198 } else {
199 $translateProvider.preferredLanguage('english');
200 };
201
202 $translateProvider.useSanitizeValueStrategy('escape');
203
204 }])
205 .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
206 return {
207 request: function (config) {
208 return config;
209 },
210 requestError: function (config) {
211 return config;
212 },
213 response: function (res) {
214 return res;
215 },
216 responseError: function (res) {
217 return res;
218 }
219 }
220 })
221 .factory('api', function ($http) {
222 return {
223 init: function () {
224 $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
225 $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
226 }
227 };
228 })
229 .run(function (api) {
230 api.init();
231 });