arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/www/js/app.js
www/js/app.jsRaw
  1var urlapi = "http://localhost:3000/api/";
  2
  3
  4angular.module('app', [
  5    'ionic',
  6    'pascalprecht.translate',
  7    'app.menu',
  8    'app.main',
  9    'app.events',
 10    'app.event',
 11    'app.users',
 12    'app.user'
 13  ])
 14
 15.run(function($ionicPlatform) {
 16  $ionicPlatform.ready(function() {
 17    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
 18    // for form inputs)
 19    if (window.cordova && window.cordova.plugins.Keyboard) {
 20      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 21      cordova.plugins.Keyboard.disableScroll(true);
 22
 23    }
 24    if (window.StatusBar) {
 25      // org.apache.cordova.statusbar required
 26      StatusBar.styleDefault();
 27    }
 28  });
 29})
 30
 31.config(function($stateProvider, $urlRouterProvider) {
 32  $stateProvider
 33
 34  // setup an abstract state for the tabs directive
 35    .state('app', {
 36        url: '/app',
 37        abstract: true,
 38        templateUrl: 'templates/menu.html',
 39        controller: 'MenuCtrl'
 40    })
 41
 42    .state('app.main', {
 43      url: '/main',
 44      views: {
 45        'menuContent': {
 46          templateUrl: 'templates/main.html',
 47          controller: 'MainCtrl'
 48        }
 49      }
 50    })
 51    .state('app.events', {
 52      url: '/events',
 53      views: {
 54        'menuContent': {
 55          templateUrl: 'templates/events.html',
 56          controller: 'EventsCtrl'
 57        }
 58      }
 59    })
 60    .state('app.event', {
 61      url: '/events/:eventid',
 62      views: {
 63        'menuContent': {
 64          templateUrl: 'templates/event.html',
 65          controller: 'EventCtrl'
 66        }
 67      }
 68    })
 69    .state('app.users', {
 70      url: '/users',
 71      views: {
 72        'menuContent': {
 73          templateUrl: 'templates/users.html',
 74          controller: 'UsersCtrl'
 75        }
 76      }
 77    })
 78    .state('app.user', {
 79      url: '/users/:userid',
 80      views: {
 81        'menuContent': {
 82          templateUrl: 'templates/user.html',
 83          controller: 'UserCtrl'
 84        }
 85      }
 86    });
 87
 88  // if none of the above states are matched, use this as the fallback
 89  $urlRouterProvider.otherwise('/app/events');
 90})
 91  /* translator */
 92  .config(['$translateProvider', function($translateProvider) {
 93
 94    /* get lang from the file translations.js */
 95    for (lang in translations) {
 96      $translateProvider.translations(lang, translations[lang]);
 97    }
 98
 99    if (window.localStorage.getItem('lang')) {
100      $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
101    } else {
102      $translateProvider.preferredLanguage('english');
103    };
104
105    $translateProvider.useSanitizeValueStrategy('escape');
106
107  }])
108  .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
109    return {
110      request: function(config) {
111        return config;
112      },
113      requestError: function(config) {
114        return config;
115      },
116      response: function(res) {
117        return res;
118      },
119      responseError: function(res) {
120        return res;
121      }
122    }
123  })
124  .factory('api', function($http) {
125    return {
126      init: function() {
127        $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
128        $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
129      }
130    };
131  })
132  .run(function(api) {
133    api.init();
134  });