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