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