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.

55 lines
2.0 KiB

  1. angular.module('app.users', ['pascalprecht.translate'])
  2. .controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) {
  3. $scope.users=[];
  4. $scope.page=0;
  5. $scope.doRefresh = function() {
  6. /* users refresh: */
  7. $http.get(urlapi + 'users?page=' + $scope.page)
  8. .then(function(data){
  9. console.log('data success users');
  10. console.log(data); // for browser console
  11. //$scope.users = data.data; // for UI
  12. $scope.users=data.data;
  13. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  14. }, function(data){
  15. console.log('data error');
  16. $scope.$broadcast('scroll.refreshComplete');//refresher stop
  17. $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
  18. });
  19. };
  20. $scope.doRefresh();
  21. $scope.followingUsers=[];
  22. $scope.$on('$ionicView.enter', function(){//per executar-ho cada cop que es carrega el view
  23. if (localStorage.getItem("events_app_followingUsers")) {
  24. $scope.followingUsers = JSON.parse(localStorage.getItem("events_app_followingUsers"));
  25. console.log("followingUsers");
  26. console.log($scope.followingUsers);
  27. }
  28. });
  29. $scope.followUser = function(user){
  30. $scope.followingUsers.push(user);
  31. localStorage.setItem("events_app_followingUsers", JSON.stringify($scope.followingUsers));
  32. };
  33. $scope.unfollowUser = function(user){
  34. for(var i=0; i<$scope.followingUsers.length; i++) {
  35. if ($scope.followingUsers[i]._id === user._id){
  36. $scope.followingUsers.splice(i, 1);
  37. }
  38. }
  39. localStorage.setItem("events_app_followingUsers", JSON.stringify($scope.followingUsers));
  40. };
  41. $scope.isUserFollowed = function(user) {
  42. for(var i=0; i<$scope.followingUsers.length; i++) {
  43. if ($scope.followingUsers[i]._id === user._id){
  44. return true;
  45. }
  46. }
  47. return false;
  48. };
  49. });