diff --git a/www/js/users.js b/www/js/users.js index e0afc0b..6e49f9a 100644 --- a/www/js/users.js +++ b/www/js/users.js @@ -24,4 +24,32 @@ angular.module('app.users', ['pascalprecht.translate']) }; $scope.doRefresh(); + $scope.followingUsers=[]; + $scope.$on('$ionicView.enter', function(){//per executar-ho cada cop que es carrega el view + if (localStorage.getItem("events_app_followingUsers")) { + $scope.followingUsers = JSON.parse(localStorage.getItem("events_app_followingUsers")); + console.log("followingUsers"); + console.log($scope.followingUsers); + } + }); + $scope.followUser = function(user){ + $scope.followingUsers.push(user); + localStorage.setItem("events_app_followingUsers", JSON.stringify($scope.followingUsers)); + }; + $scope.unfollowUser = function(user){ + for(var i=0; i<$scope.followingUsers.length; i++) { + if ($scope.followingUsers[i]._id === user._id){ + $scope.followingUsers.splice(i, 1); + } + } + localStorage.setItem("events_app_followingUsers", JSON.stringify($scope.followingUsers)); + }; + $scope.isUserFollowed = function(user) { + for(var i=0; i<$scope.followingUsers.length; i++) { + if ($scope.followingUsers[i]._id === user._id){ + return true; + } + } + return false; + }; }); diff --git a/www/templates/users.html b/www/templates/users.html index 452b32b..f73fa75 100644 --- a/www/templates/users.html +++ b/www/templates/users.html @@ -5,14 +5,27 @@ on-refresh="doRefresh()"> - - -

{{user.username}}

-

{{user.shortDescription}}

+
+
+
+ Unfollow +
+
+ Follow +
+
+ + - Following - +

{{user.username}}

+

{{user.shortDescription}}

+ +