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.

54 lines
2.2 KiB

7 years ago
  1. angular.module('app.users', ['pascalprecht.translate'])
  2. .controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) {
  3. $scope.users="";
  4. $scope.users=JSON.parse(localStorage.getItem('c_users'));
  5. $scope.doRefresh = function() {
  6. /* travels refresh: */
  7. $http.get(urlapi + 'travels')
  8. .success(function(data, status, headers,config){
  9. console.log('data success');
  10. console.log(data); // for browser console
  11. $scope.travels = data; // for UI
  12. localStorage.setItem('c_travels', JSON.stringify($scope.travels));
  13. localStorage.setItem('c_travelsLastDate', JSON.stringify(new Date()));
  14. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  15. })
  16. .error(function(data, status, headers,config){
  17. console.log('data error');
  18. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  19. $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
  20. })
  21. .then(function(result){
  22. travels = result.data;
  23. $ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 });
  24. });
  25. /* users refresh: */
  26. $http.get(urlapi + 'users')
  27. .success(function(data, status, headers, config){
  28. console.log('data success');
  29. console.log(data); // for browser console
  30. $scope.users = data; // for UI
  31. localStorage.setItem('c_users', JSON.stringify($scope.users));
  32. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  33. //set userdata
  34. $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0];
  35. console.log("userdata");
  36. console.log($scope.userdata);
  37. localStorage.setItem("c_userdata", JSON.stringify($scope.userdata));
  38. })
  39. .error(function(data, status, headers,config){
  40. console.log('data error');
  41. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  42. })
  43. .then(function(result){
  44. users = result.data;
  45. });
  46. };
  47. });