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