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.

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