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