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.

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