arnaucube
arnaucube/commonroutesAppPublic Self-hosted repository
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.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.editUser', {
157        url: '/editUser',
158        views: {
159          'menuContent': {
160            templateUrl: 'templates/editUser.html',
161            controller: 'EditUserCtrl'
162          }
163        }
164      })
165      .state('app.notifications', {
166        url: '/notifications',
167        views: {
168          'menuContent': {
169            templateUrl: 'templates/notifications.html',
170            controller: 'NotificationsCtrl'
171          }
172        }
173      })
174      .state('app.settings', {
175        url: '/settings',
176        views: {
177          'menuContent': {
178            templateUrl: 'templates/settings.html',
179            controller: 'SettingsCtrl'
180          }
181        }
182      })
183      .state('app.help', {
184        url: '/help',
185        views: {
186          'menuContent': {
187            templateUrl: 'templates/help.html',
188            controller: 'HelpCtrl'
189          }
190        }
191      });
192    // if none of the above states are matched, use this as the fallback
193    if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
194            if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
195                window.location = '#/app/main';
196            }
197            $urlRouterProvider.otherwise('/app/main');
198        } else {
199            if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
200                console.log("removing data, and going to login");
201                localStorage.removeItem("cim_app_token");
202                localStorage.removeItem("cim_app_userdata");
203                window.location = "#/app/login";
204                $urlRouterProvider.otherwise('/app/login');
205            }
206        }
207  })
208
209
210
211  /* translator */
212  .config(['$translateProvider', function($translateProvider) {
213
214    /* get lang from the file translations.js */
215    for (lang in translations) {
216      $translateProvider.translations(lang, translations[lang]);
217    }
218
219    if (window.localStorage.getItem('lang')) {
220      $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
221    } else {
222      $translateProvider.preferredLanguage('english');
223    };
224
225    $translateProvider.useSanitizeValueStrategy('escape');
226
227  }])
228  .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
229        return {
230            request: function (config) {
231                return config;
232            },
233            requestError: function (config) {
234                return config;
235            },
236            response: function (res) {
237                return res;
238            },
239            responseError: function (res) {
240                return res;
241            }
242        }
243    })
244    .factory('api', function ($http) {
245        return {
246            init: function () {
247                $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
248                $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
249            }
250        };
251    })
252    .run(function (api) {
253        api.init();
254    });