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