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.

303 lines
7.9 KiB

6 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
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://37.59.123.45:3000/api/";
  9. var urlapi = "http://routes.fair.coop:3000/api/";
  10. angular.module('starter', [
  11. 'ionic',
  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.askForCar',
  25. 'app.askForPackage',
  26. 'app.users',
  27. 'app.user',
  28. 'app.userTravels',
  29. 'app.userLikes',
  30. 'app.editUser',
  31. 'app.notifications',
  32. 'app.settings',
  33. 'app.password',
  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. cache: false,
  54. url: '/app',
  55. abstract: true,
  56. templateUrl: 'templates/menu.html',
  57. controller: 'MenuCtrl'
  58. })
  59. .state('app.main', {
  60. cache: false,
  61. url: '/main',
  62. views: {
  63. 'menuContent': {
  64. templateUrl: 'templates/main.html',
  65. controller: 'MainCtrl'
  66. }
  67. }
  68. })
  69. .state('app.login', {
  70. url: '/login',
  71. views: {
  72. 'menuContent': {
  73. templateUrl: 'templates/login.html',
  74. controller: 'LoginCtrl'
  75. }
  76. }
  77. })
  78. .state('app.signup', {
  79. url: '/signup',
  80. views: {
  81. 'menuContent': {
  82. templateUrl: 'templates/signup.html',
  83. controller: 'SignupCtrl'
  84. }
  85. }
  86. })
  87. .state('app.search', {
  88. url: '/search',
  89. views: {
  90. 'menuContent': {
  91. templateUrl: 'templates/search.html',
  92. controller: 'SearchCtrl'
  93. }
  94. }
  95. })
  96. .state('app.travels', {
  97. url: '/travels',
  98. views: {
  99. 'menuContent': {
  100. templateUrl: 'templates/travels.html',
  101. controller: 'TravelsCtrl'
  102. }
  103. }
  104. })
  105. .state('app.travel', {
  106. url: '/travels/:travelid',
  107. views: {
  108. 'menuContent': {
  109. templateUrl: 'templates/travel.html',
  110. controller: 'TravelCtrl'
  111. }
  112. }
  113. })
  114. .state('app.newTravel', {
  115. url: '/newTravel',
  116. views: {
  117. 'menuContent': {
  118. templateUrl: 'templates/newTravel.html',
  119. controller: 'NewTravelCtrl'
  120. }
  121. }
  122. })
  123. .state('app.offerCar', {
  124. url: '/offerCar',
  125. views: {
  126. 'menuContent': {
  127. templateUrl: 'templates/offerCar.html',
  128. controller: 'OfferCarCtrl'
  129. }
  130. }
  131. })
  132. .state('app.askForCar', {
  133. url: '/askForCar',
  134. views: {
  135. 'menuContent': {
  136. templateUrl: 'templates/askForCar.html',
  137. controller: 'AskForCarCtrl'
  138. }
  139. }
  140. })
  141. .state('app.askForPackage', {
  142. url: '/askForPackage',
  143. views: {
  144. 'menuContent': {
  145. templateUrl: 'templates/askForPackage.html',
  146. controller: 'AskForPackageCtrl'
  147. }
  148. }
  149. })
  150. .state('app.users', {
  151. url: '/users',
  152. views: {
  153. 'menuContent': {
  154. templateUrl: 'templates/users.html',
  155. controller: 'UsersCtrl'
  156. }
  157. }
  158. })
  159. .state('app.user', {
  160. url: '/users/:userid',
  161. views: {
  162. 'menuContent': {
  163. templateUrl: 'templates/user.html',
  164. controller: 'UserCtrl'
  165. }
  166. }
  167. })
  168. .state('app.userTravels', {
  169. url: '/users/userTravels/:userid',
  170. views: {
  171. 'menuContent': {
  172. templateUrl: 'templates/userTravels.html',
  173. controller: 'UserTravelsCtrl'
  174. }
  175. }
  176. })
  177. .state('app.userLikes', {
  178. url: '/users/userLikes/:userid',
  179. views: {
  180. 'menuContent': {
  181. templateUrl: 'templates/userLikes.html',
  182. controller: 'UserLikesCtrl'
  183. }
  184. }
  185. })
  186. .state('app.editUser', {
  187. url: '/editUser',
  188. views: {
  189. 'menuContent': {
  190. templateUrl: 'templates/editUser.html',
  191. controller: 'EditUserCtrl'
  192. }
  193. }
  194. })
  195. .state('app.notifications', {
  196. url: '/notifications',
  197. views: {
  198. 'menuContent': {
  199. templateUrl: 'templates/notifications.html',
  200. controller: 'NotificationsCtrl'
  201. }
  202. }
  203. })
  204. .state('app.settings', {
  205. url: '/settings',
  206. views: {
  207. 'menuContent': {
  208. templateUrl: 'templates/settings.html',
  209. controller: 'SettingsCtrl'
  210. }
  211. }
  212. })
  213. .state('app.password', {
  214. url: '/password',
  215. views: {
  216. 'menuContent': {
  217. templateUrl: 'templates/password.html',
  218. controller: 'PasswordCtrl'
  219. }
  220. }
  221. })
  222. .state('app.help', {
  223. url: '/help',
  224. views: {
  225. 'menuContent': {
  226. templateUrl: 'templates/help.html',
  227. controller: 'HelpCtrl'
  228. }
  229. }
  230. });
  231. // if none of the above states are matched, use this as the fallback
  232. if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) {
  233. if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) {
  234. window.location = '#/app/main';
  235. }
  236. $urlRouterProvider.otherwise('/app/main');
  237. } else {
  238. if ((window.location != "#/app/login") || (window.location != "#/app/signup")) {
  239. console.log("removing data, and going to login");
  240. localStorage.removeItem("cim_app_token");
  241. localStorage.removeItem("cim_app_userdata");
  242. window.location = "#/app/login";
  243. $urlRouterProvider.otherwise('/app/login');
  244. }
  245. }
  246. })
  247. /* translator */
  248. .config(['$translateProvider', function($translateProvider) {
  249. /* get lang from the file translations.js */
  250. for (lang in translations) {
  251. $translateProvider.translations(lang, translations[lang]);
  252. }
  253. if (window.localStorage.getItem('lang')) {
  254. $translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
  255. } else {
  256. $translateProvider.preferredLanguage('english');
  257. };
  258. $translateProvider.useSanitizeValueStrategy('escape');
  259. }])
  260. .factory('httpInterceptor', function httpInterceptor($q, $window, $location) {
  261. return {
  262. request: function(config) {
  263. return config;
  264. },
  265. requestError: function(config) {
  266. return config;
  267. },
  268. response: function(res) {
  269. return res;
  270. },
  271. responseError: function(res) {
  272. return res;
  273. }
  274. }
  275. })
  276. .factory('api', function($http) {
  277. return {
  278. init: function() {
  279. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token");
  280. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token");
  281. }
  282. };
  283. })
  284. .run(function(api) {
  285. api.init();
  286. });