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