You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.2 KiB

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