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.

292 lines
7.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
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 = "http://192.168.1.36:3000/api/";
  8. //var urlapi = "http://51.255.193.106:3000/api/";
  9. angular.module('starter', [
  10. 'ionic',
  11. 'ngCordova',
  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.askForCar',
  24. 'app.askForPackage',
  25. 'app.users',
  26. 'app.user',
  27. 'app.userTravels',
  28. 'app.userLikes',
  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. cache: false,
  52. url: '/app',
  53. abstract: true,
  54. templateUrl: 'templates/menu.html',
  55. controller: 'MenuCtrl'
  56. })
  57. .state('app.main', {
  58. cache: false,
  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.askForCar', {
  131. url: '/askForCar',
  132. views: {
  133. 'menuContent': {
  134. templateUrl: 'templates/askForCar.html',
  135. controller: 'AskForCarCtrl'
  136. }
  137. }
  138. })
  139. .state('app.askForPackage', {
  140. url: '/askForPackage',
  141. views: {
  142. 'menuContent': {
  143. templateUrl: 'templates/askForPackage.html',
  144. controller: 'AskForPackageCtrl'
  145. }
  146. }
  147. })
  148. .state('app.users', {
  149. url: '/users',
  150. views: {
  151. 'menuContent': {
  152. templateUrl: 'templates/users.html',
  153. controller: 'UsersCtrl'
  154. }
  155. }
  156. })
  157. .state('app.user', {
  158. url: '/users/:userid',
  159. views: {
  160. 'menuContent': {
  161. templateUrl: 'templates/user.html',
  162. controller: 'UserCtrl'
  163. }
  164. }
  165. })
  166. .state('app.userTravels', {
  167. url: '/users/userTravels/:userid',
  168. views: {
  169. 'menuContent': {
  170. templateUrl: 'templates/userTravels.html',
  171. controller: 'UserTravelsCtrl'
  172. }
  173. }
  174. })
  175. .state('app.userLikes', {
  176. url: '/users/userLikes/:userid',
  177. views: {
  178. 'menuContent': {
  179. templateUrl: 'templates/userLikes.html',
  180. controller: 'UserLikesCtrl'
  181. }
  182. }
  183. })
  184. .state('app.editUser', {
  185. url: '/editUser',
  186. views: {
  187. 'menuContent': {
  188. templateUrl: 'templates/editUser.html',
  189. controller: 'EditUserCtrl'
  190. }
  191. }
  192. })
  193. .state('app.notifications', {
  194. url: '/notifications',
  195. views: {
  196. 'menuContent': {
  197. templateUrl: 'templates/notifications.html',
  198. controller: 'NotificationsCtrl'
  199. }
  200. }
  201. })
  202. .state('app.settings', {
  203. url: '/settings',
  204. views: {
  205. 'menuContent': {
  206. templateUrl: 'templates/settings.html',
  207. controller: 'SettingsCtrl'
  208. }
  209. }
  210. })
  211. .state('app.help', {
  212. url: '/help',
  213. views: {
  214. 'menuContent': {
  215. templateUrl: 'templates/help.html',
  216. controller: 'HelpCtrl'
  217. }
  218. }
  219. });
  220. // if none of the above states are matched, use this as the fallback
  221. if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
  222. if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
  223. window.location = '#/app/main';
  224. }
  225. $urlRouterProvider.otherwise('/app/main');
  226. } else {
  227. if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
  228. console.log("removing data, and going to login");
  229. localStorage.removeItem("cim_app_token");
  230. localStorage.removeItem("cim_app_userdata");
  231. window.location = "#/app/login";
  232. $urlRouterProvider.otherwise('/app/login');
  233. }
  234. }
  235. })
  236. /* translator */
  237. .config(['$translateProvider', function($translateProvider) {
  238. /* get lang from the file translations.js */
  239. for (lang in translations) {
  240. $translateProvider.translations(lang, translations[lang]);
  241. }
  242. if (window.localStorage.getItem('lang')) {
  243. $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
  244. } else {
  245. $translateProvider.preferredLanguage('english');
  246. };
  247. $translateProvider.useSanitizeValueStrategy('escape');
  248. }])
  249. .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
  250. return {
  251. request: function(config) {
  252. return config;
  253. },
  254. requestError: function(config) {
  255. return config;
  256. },
  257. response: function(res) {
  258. return res;
  259. },
  260. responseError: function(res) {
  261. return res;
  262. }
  263. }
  264. })
  265. .factory('api', function($http) {
  266. return {
  267. init: function() {
  268. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
  269. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
  270. }
  271. };
  272. })
  273. .run(function(api) {
  274. api.init();
  275. });