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