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