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.34: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.event',
 14    'app.alerts',
 15    'app.savedEvents',
 16    'app.byCategories',
 17    'app.users',
 18    'app.user',
 19    'app.login',
 20    'app.userZone',
 21    'app.newEvent'
 22  ])
 23
 24.run(function($ionicPlatform) {
 25  $ionicPlatform.ready(function() {
 26    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
 27    // for form inputs)
 28    if (window.cordova && window.cordova.plugins.Keyboard) {
 29      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 30      cordova.plugins.Keyboard.disableScroll(true);
 31
 32    }
 33    if (window.StatusBar) {
 34      // org.apache.cordova.statusbar required
 35      StatusBar.styleDefault();
 36    }
 37  });
 38})
 39
 40.config(function($stateProvider, $urlRouterProvider) {
 41  $stateProvider
 42
 43  // setup an abstract state for the tabs directive
 44    .state('app', {
 45        url: '/app',
 46        abstract: true,
 47        templateUrl: 'templates/menu.html',
 48        controller: 'MenuCtrl'
 49    })
 50
 51    .state('app.main', {
 52      url: '/main',
 53      views: {
 54        'menuContent': {
 55          templateUrl: 'templates/main.html',
 56          controller: 'MainCtrl'
 57        }
 58      }
 59    })
 60    .state('app.events', {
 61      url: '/events',
 62      views: {
 63        'menuContent': {
 64          templateUrl: 'templates/events.html',
 65          controller: 'EventsCtrl'
 66        }
 67      }
 68    })
 69    .state('app.event', {
 70      url: '/events/:eventid',
 71      views: {
 72        'menuContent': {
 73          templateUrl: 'templates/event.html',
 74          controller: 'EventCtrl'
 75        }
 76      }
 77    })
 78    .state('app.alerts', {
 79      url: '/alerts',
 80      views: {
 81        'menuContent': {
 82          templateUrl: 'templates/alerts.html',
 83          controller: 'AlertsCtrl'
 84        }
 85      }
 86    })
 87    .state('app.savedEvents', {
 88      url: '/savedEvents',
 89      views: {
 90        'menuContent': {
 91          templateUrl: 'templates/savedEvents.html',
 92          controller: 'SavedEventsCtrl'
 93        }
 94      }
 95    })
 96    .state('app.byCategories', {
 97      url: '/byCategories',
 98      views: {
 99        'menuContent': {
100          templateUrl: 'templates/byCategories.html',
101          controller: 'ByCategoriesCtrl'
102        }
103      }
104    })
105    .state('app.users', {
106      url: '/users',
107      views: {
108        'menuContent': {
109          templateUrl: 'templates/users.html',
110          controller: 'UsersCtrl'
111        }
112      }
113    })
114    .state('app.user', {
115      url: '/users/:userid',
116      views: {
117        'menuContent': {
118          templateUrl: 'templates/user.html',
119          controller: 'UserCtrl'
120        }
121      }
122    })
123    .state('app.login', {
124      url: '/login',
125      views: {
126        'menuContent': {
127          templateUrl: 'templates/login.html',
128          controller: 'LoginCtrl'
129        }
130      }
131    })
132    .state('app.userZone', {
133      url: '/userZone',
134      views: {
135        'menuContent': {
136          templateUrl: 'templates/userZone.html',
137          controller: 'UserZoneCtrl'
138        }
139      }
140    })
141    .state('app.newEvent', {
142      url: '/newEvent',
143      views: {
144        'menuContent': {
145          templateUrl: 'templates/newEvent.html',
146          controller: 'NewEventCtrl'
147        }
148      }
149    });
150
151  // if none of the above states are matched, use this as the fallback
152  $urlRouterProvider.otherwise('/app/main');
153})
154  /* translator */
155  .config(['$translateProvider', function($translateProvider) {
156
157    /* get lang from the file translations.js */
158    for (lang in translations) {
159      $translateProvider.translations(lang, translations[lang]);
160    }
161
162    if (window.localStorage.getItem('lang')) {
163      $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
164    } else {
165      $translateProvider.preferredLanguage('english');
166    };
167
168    $translateProvider.useSanitizeValueStrategy('escape');
169
170  }])
171  .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
172    return {
173      request: function(config) {
174        return config;
175      },
176      requestError: function(config) {
177        return config;
178      },
179      response: function(res) {
180        return res;
181      },
182      responseError: function(res) {
183        return res;
184      }
185    }
186  })
187  .factory('api', function($http) {
188    return {
189      init: function() {
190        $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("events_app_token");
191        $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("events_app_token");
192      }
193    };
194  })
195  .run(function(api) {
196    api.init();
197  });