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.

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