arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/www/js/app.js
www/js/app.jsRaw
  1var urlapi = "http://localhost:3000/api/";
  2//var urlapi = "http://192.168.1.33:3000/api/";
  3
  4
  5
  6angular.module('app', [
  7    'ionic',
  8    'pascalprecht.translate',
  9    'ngCordova',
 10    'app.menu',
 11    'app.main',
 12    'app.events',
 13    'app.mapEvents',
 14    'app.event',
 15    'app.alerts',
 16    'app.savedEvents',
 17    'app.categories',
 18    'app.byCategory',
 19    'app.place',
 20    'app.byPlace',
 21    'app.users',
 22    'app.user',
 23    'app.login',
 24    'app.userZone',
 25    'app.newEvent'
 26  ])
 27
 28.run(function($ionicPlatform) {
 29  $ionicPlatform.ready(function() {
 30    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
 31    // for form inputs)
 32    if (window.cordova && window.cordova.plugins.Keyboard) {
 33      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 34      cordova.plugins.Keyboard.disableScroll(true);
 35
 36    }
 37    if (window.StatusBar) {
 38      // org.apache.cordova.statusbar required
 39      StatusBar.styleDefault();
 40    }
 41  });
 42})
 43
 44.config(function($stateProvider, $urlRouterProvider) {
 45  $stateProvider
 46
 47  // setup an abstract state for the tabs directive
 48    .state('app', {
 49        url: '/app',
 50        abstract: true,
 51        templateUrl: 'templates/menu.html',
 52        controller: 'MenuCtrl'
 53    })
 54
 55    .state('app.main', {
 56      url: '/main',
 57      views: {
 58        'menuContent': {
 59          templateUrl: 'templates/main.html',
 60          controller: 'MainCtrl'
 61        }
 62      }
 63    })
 64    .state('app.events', {
 65      url: '/events',
 66      views: {
 67        'menuContent': {
 68          templateUrl: 'templates/events.html',
 69          controller: 'EventsCtrl'
 70        }
 71      }
 72    })
 73    .state('app.mapEvents', {
 74      url: '/mapEvents',
 75      views: {
 76        'menuContent': {
 77          templateUrl: 'templates/mapEvents.html',
 78          controller: 'MapEventsCtrl'
 79        }
 80      }
 81    })
 82    .state('app.event', {
 83      url: '/events/:eventid',
 84      views: {
 85        'menuContent': {
 86          templateUrl: 'templates/event.html',
 87          controller: 'EventCtrl'
 88        }
 89      }
 90    })
 91    .state('app.alerts', {
 92      url: '/alerts',
 93      views: {
 94        'menuContent': {
 95          templateUrl: 'templates/alerts.html',
 96          controller: 'AlertsCtrl'
 97        }
 98      }
 99    })
100    .state('app.savedEvents', {
101      url: '/savedEvents',
102      views: {
103        'menuContent': {
104          templateUrl: 'templates/savedEvents.html',
105          controller: 'SavedEventsCtrl'
106        }
107      }
108    })
109    .state('app.categories', {
110      url: '/categories',
111      views: {
112        'menuContent': {
113          templateUrl: 'templates/categories.html',
114          controller: 'CategoriesCtrl'
115        }
116      }
117    })
118    .state('app.byCategory', {
119      url: '/byCategory/:categoryname',
120      views: {
121        'menuContent': {
122          templateUrl: 'templates/byCategory.html',
123          controller: 'ByCategoryCtrl'
124        }
125      }
126    })
127    .state('app.place', {
128      url: '/place',
129      views: {
130        'menuContent': {
131          templateUrl: 'templates/place.html',
132          controller: 'PlaceCtrl'
133        }
134      }
135    })
136    .state('app.byPlace', {
137      url: '/byPlace/:place',
138      views: {
139        'menuContent': {
140          templateUrl: 'templates/byPlace.html',
141          controller: 'ByPlaceCtrl'
142        }
143      }
144    })
145    .state('app.users', {
146      url: '/users',
147      views: {
148        'menuContent': {
149          templateUrl: 'templates/users.html',
150          controller: 'UsersCtrl'
151        }
152      }
153    })
154    .state('app.user', {
155      url: '/users/:userid',
156      views: {
157        'menuContent': {
158          templateUrl: 'templates/user.html',
159          controller: 'UserCtrl'
160        }
161      }
162    })
163    .state('app.login', {
164      url: '/login',
165      views: {
166        'menuContent': {
167          templateUrl: 'templates/login.html',
168          controller: 'LoginCtrl'
169        }
170      }
171    })
172    .state('app.userZone', {
173      url: '/userZone',
174      views: {
175        'menuContent': {
176          templateUrl: 'templates/userZone.html',
177          controller: 'UserZoneCtrl'
178        }
179      }
180    })
181    .state('app.newEvent', {
182      url: '/newEvent',
183      views: {
184        'menuContent': {
185          templateUrl: 'templates/newEvent.html',
186          controller: 'NewEventCtrl'
187        }
188      }
189    });
190
191  // if none of the above states are matched, use this as the fallback
192  $urlRouterProvider.otherwise('/app/main');
193})
194  /* translator */
195  .config(['$translateProvider', function($translateProvider) {
196
197    /* get lang from the file translations.js */
198    for (lang in translations) {
199      $translateProvider.translations(lang, translations[lang]);
200    }
201
202    if (window.localStorage.getItem('lang')) {
203      $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
204    } else {
205      $translateProvider.preferredLanguage('english');
206    };
207
208    $translateProvider.useSanitizeValueStrategy('escape');
209
210  }])
211  .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
212    return {
213      request: function(config) {
214        return config;
215      },
216      requestError: function(config) {
217        return config;
218      },
219      response: function(res) {
220        return res;
221      },
222      responseError: function(res) {
223        return res;
224      }
225    }
226  })
227  .factory('api', function($http) {
228    return {
229      init: function() {
230        $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("events_app_token");
231        $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("events_app_token");
232      }
233    };
234  })
235  .run(function(api) {
236    api.init();
237  });