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 = "http://192.168.1.36:3000/api/";
 11var urlapi = "http://51.255.193.106:3000/api/";
 12
 13angular.module('starter', [
 14    'ionic',
 15    'ngCordova',
 16    'pascalprecht.translate',
 17    'app.login',
 18    'app.signup',
 19    'app.menu',
 20    'app.footerMenu',
 21    'app.main',
 22    'app.search',
 23    'app.travels',
 24    'app.travel',
 25    'app.newTravel',
 26    'app.offerCar',
 27    /*    'app.askCar',
 28        'app.askPackage',*/
 29    'app.users',
 30    'app.user',
 31    'app.userTravels',
 32    'app.userLikes',
 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        cache: false,
 60        url: '/app',
 61        abstract: true,
 62        templateUrl: 'templates/menu.html',
 63        controller: 'MenuCtrl'
 64      })
 65      .state('app.main', {
 66        cache: false,
 67        url: '/main',
 68        views: {
 69          'menuContent': {
 70            templateUrl: 'templates/main.html',
 71            controller: 'MainCtrl'
 72          }
 73        }
 74      })
 75      .state('app.login', {
 76        url: '/login',
 77        views: {
 78          'menuContent': {
 79            templateUrl: 'templates/login.html',
 80            controller: 'LoginCtrl'
 81          }
 82        }
 83      })
 84      .state('app.signup', {
 85        url: '/signup',
 86        views: {
 87          'menuContent': {
 88            templateUrl: 'templates/signup.html',
 89            controller: 'SignupCtrl'
 90          }
 91        }
 92      })
 93      .state('app.search', {
 94        url: '/search',
 95        views: {
 96          'menuContent': {
 97            templateUrl: 'templates/search.html',
 98            controller: 'SearchCtrl'
 99          }
100        }
101      })
102      .state('app.travels', {
103        url: '/travels',
104        views: {
105          'menuContent': {
106            templateUrl: 'templates/travels.html',
107            controller: 'TravelsCtrl'
108          }
109        }
110      })
111
112      .state('app.travel', {
113        url: '/travels/:travelid',
114        views: {
115          'menuContent': {
116            templateUrl: 'templates/travel.html',
117            controller: 'TravelCtrl'
118          }
119        }
120      })
121
122      .state('app.newTravel', {
123        url: '/newTravel',
124        views: {
125          'menuContent': {
126            templateUrl: 'templates/newTravel.html',
127            controller: 'NewTravelCtrl'
128          }
129        }
130      })
131      .state('app.offerCar', {
132        url: '/offerCar',
133        views: {
134          'menuContent': {
135            templateUrl: 'templates/offerCar.html',
136            controller: 'OfferCarCtrl'
137          }
138        }
139      })
140      .state('app.users', {
141        url: '/users',
142        views: {
143          'menuContent': {
144            templateUrl: 'templates/users.html',
145            controller: 'UsersCtrl'
146          }
147        }
148      })
149      .state('app.user', {
150        url: '/users/:userid',
151        views: {
152          'menuContent': {
153            templateUrl: 'templates/user.html',
154            controller: 'UserCtrl'
155          }
156        }
157      })
158      .state('app.userTravels', {
159        url: '/users/userTravels/:userid',
160        views: {
161          'menuContent': {
162            templateUrl: 'templates/userTravels.html',
163            controller: 'UserTravelsCtrl'
164          }
165        }
166      })
167      .state('app.userLikes', {
168        url: '/users/userLikes/:userid',
169        views: {
170          'menuContent': {
171            templateUrl: 'templates/userLikes.html',
172            controller: 'UserLikesCtrl'
173          }
174        }
175      })
176      .state('app.editUser', {
177        url: '/editUser',
178        views: {
179          'menuContent': {
180            templateUrl: 'templates/editUser.html',
181            controller: 'EditUserCtrl'
182          }
183        }
184      })
185      .state('app.notifications', {
186        url: '/notifications',
187        views: {
188          'menuContent': {
189            templateUrl: 'templates/notifications.html',
190            controller: 'NotificationsCtrl'
191          }
192        }
193      })
194      .state('app.settings', {
195        url: '/settings',
196        views: {
197          'menuContent': {
198            templateUrl: 'templates/settings.html',
199            controller: 'SettingsCtrl'
200          }
201        }
202      })
203      .state('app.help', {
204        url: '/help',
205        views: {
206          'menuContent': {
207            templateUrl: 'templates/help.html',
208            controller: 'HelpCtrl'
209          }
210        }
211      });
212    // if none of the above states are matched, use this as the fallback
213    if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
214      if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
215        window.location = '#/app/main';
216      }
217      $urlRouterProvider.otherwise('/app/main');
218    } else {
219      if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
220        console.log("removing data, and going to login");
221        localStorage.removeItem("cim_app_token");
222        localStorage.removeItem("cim_app_userdata");
223        window.location = "#/app/login";
224        $urlRouterProvider.otherwise('/app/login');
225      }
226    }
227  })
228
229
230
231  /* translator */
232  .config(['$translateProvider', function($translateProvider) {
233
234    /* get lang from the file translations.js */
235    for (lang in translations) {
236      $translateProvider.translations(lang, translations[lang]);
237    }
238
239    if (window.localStorage.getItem('lang')) {
240      $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
241    } else {
242      $translateProvider.preferredLanguage('english');
243    };
244
245    $translateProvider.useSanitizeValueStrategy('escape');
246
247  }])
248  .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
249    return {
250      request: function(config) {
251        return config;
252      },
253      requestError: function(config) {
254        return config;
255      },
256      response: function(res) {
257        return res;
258      },
259      responseError: function(res) {
260        return res;
261      }
262    }
263  })
264  .factory('api', function($http) {
265    return {
266      init: function() {
267        $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
268        $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
269      }
270    };
271  })
272  .run(function(api) {
273    api.init();
274  });