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