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.

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