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.

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