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.

232 lines
6.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. // Ionic Starter App
  2. // angular.module is a global place for creating, registering and retrieving Angular modules
  3. // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
  4. // the 2nd parameter is an array of 'requires'
  5. // 'starter.controllers' is found in controllers.js
  6. var urlapi = "http://localhost:3000/api/";
  7. //var urlapi="https://collectivecar.paas.primustech.io/api/";
  8. angular.module('starter', [
  9. 'ionic',
  10. 'ngMaterial',
  11. 'pascalprecht.translate',
  12. 'app.login',
  13. 'app.signup',
  14. 'app.menu',
  15. 'app.footerMenu',
  16. 'app.main',
  17. 'app.travels',
  18. 'app.travel',
  19. 'app.newPublication',
  20. 'app.offerCar',
  21. /* 'app.askCar',
  22. 'app.askPackage',*/
  23. 'app.users',
  24. 'app.user',
  25. 'app.notifications',
  26. 'app.settings',
  27. 'app.help'
  28. ])
  29. .run(function($ionicPlatform) {
  30. $ionicPlatform.ready(function() {
  31. // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
  32. // for form inputs)
  33. if (window.cordova && window.cordova.plugins.Keyboard) {
  34. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  35. cordova.plugins.Keyboard.disableScroll(true);
  36. }
  37. if (window.StatusBar) {
  38. // org.apache.cordova.statusbar required
  39. StatusBar.styleDefault();
  40. }
  41. });
  42. })
  43. .config(function($stateProvider, $urlRouterProvider) {
  44. $stateProvider
  45. .state('app', {
  46. url: '/app',
  47. abstract: true,
  48. templateUrl: 'templates/menu.html',
  49. controller: 'MenuCtrl'
  50. })
  51. .state('app.main', {
  52. url: '/main',
  53. views: {
  54. 'menuContent': {
  55. templateUrl: 'templates/main.html',
  56. controller: 'MainCtrl'
  57. }
  58. }
  59. })
  60. .state('app.login', {
  61. url: '/login',
  62. views: {
  63. 'menuContent': {
  64. templateUrl: 'templates/login.html',
  65. controller: 'LoginCtrl'
  66. }
  67. }
  68. })
  69. .state('app.signup', {
  70. url: '/signup',
  71. views: {
  72. 'menuContent': {
  73. templateUrl: 'templates/signup.html',
  74. controller: 'SignupCtrl'
  75. }
  76. }
  77. })
  78. .state('app.travels', {
  79. url: '/travels',
  80. views: {
  81. 'menuContent': {
  82. templateUrl: 'templates/travels.html',
  83. controller: 'TravelsCtrl'
  84. }
  85. }
  86. })
  87. .state('app.travel', {
  88. url: '/travels/:travelid',
  89. views: {
  90. 'menuContent': {
  91. templateUrl: 'templates/travel.html',
  92. controller: 'TravelCtrl'
  93. }
  94. }
  95. })
  96. .state('app.newPublication', {
  97. url: '/newPublication',
  98. views: {
  99. 'menuContent': {
  100. templateUrl: 'templates/newPublication.html',
  101. controller: 'NewPublicationCtrl'
  102. }
  103. }
  104. })
  105. .state('app.offerCar', {
  106. url: '/offerCar',
  107. views: {
  108. 'menuContent': {
  109. templateUrl: 'templates/offerCar.html',
  110. controller: 'OfferCarCtrl'
  111. }
  112. }
  113. })
  114. .state('app.users', {
  115. url: '/users',
  116. views: {
  117. 'menuContent': {
  118. templateUrl: 'templates/users.html',
  119. controller: 'UsersCtrl'
  120. }
  121. }
  122. })
  123. .state('app.user', {
  124. url: '/users/:userid',
  125. views: {
  126. 'menuContent': {
  127. templateUrl: 'templates/user.html',
  128. controller: 'UserCtrl'
  129. }
  130. }
  131. })
  132. .state('app.notifications', {
  133. url: '/notifications',
  134. views: {
  135. 'menuContent': {
  136. templateUrl: 'templates/notifications.html',
  137. controller: 'NotificationsCtrl'
  138. }
  139. }
  140. })
  141. .state('app.settings', {
  142. url: '/settings',
  143. views: {
  144. 'menuContent': {
  145. templateUrl: 'templates/settings.html',
  146. controller: 'SettingsCtrl'
  147. }
  148. }
  149. })
  150. .state('app.help', {
  151. url: '/help',
  152. views: {
  153. 'menuContent': {
  154. templateUrl: 'templates/help.html',
  155. controller: 'HelpCtrl'
  156. }
  157. }
  158. });
  159. // if none of the above states are matched, use this as the fallback
  160. if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
  161. if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
  162. window.location = '#/app/main';
  163. }
  164. $urlRouterProvider.otherwise('/app/main');
  165. } else {
  166. if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
  167. console.log("removing data, and going to login");
  168. localStorage.removeItem("cim_app_token");
  169. localStorage.removeItem("cim_app_userdata");
  170. window.location = "#/app/login";
  171. $urlRouterProvider.otherwise('/app/login');
  172. }
  173. }
  174. })
  175. /* translator */
  176. .config(['$translateProvider', function($translateProvider) {
  177. /* get lang from the file translations.js */
  178. for (lang in translations) {
  179. $translateProvider.translations(lang, translations[lang]);
  180. }
  181. if (window.localStorage.getItem('lang')) {
  182. $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
  183. } else {
  184. $translateProvider.preferredLanguage('english');
  185. };
  186. $translateProvider.useSanitizeValueStrategy('escape');
  187. }])
  188. .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
  189. return {
  190. request: function (config) {
  191. return config;
  192. },
  193. requestError: function (config) {
  194. return config;
  195. },
  196. response: function (res) {
  197. return res;
  198. },
  199. responseError: function (res) {
  200. return res;
  201. }
  202. }
  203. })
  204. .factory('api', function ($http) {
  205. return {
  206. init: function () {
  207. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
  208. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
  209. }
  210. };
  211. })
  212. .run(function (api) {
  213. api.init();
  214. });