VRFS-303 fix toggling of Add Friend / Follow buttons
This commit is contained in:
parent
4c10ad3df6
commit
54f5a34cda
|
|
@ -41,11 +41,11 @@
|
|||
if (userId != context.JK.currentUserId) {
|
||||
// wire up Add Friend click
|
||||
var friend = isFriend();
|
||||
configureFriendButton(isFriend);
|
||||
configureFriendButton(friend);
|
||||
|
||||
// wire up Follow click
|
||||
var following = isFollowing();
|
||||
configureFollowingButton(isFollowing);
|
||||
configureFollowingButton(following);
|
||||
}
|
||||
else {
|
||||
$('#btn-add-friend').hide();
|
||||
|
|
@ -77,6 +77,8 @@
|
|||
}
|
||||
|
||||
function isFriend() {
|
||||
var alreadyFriend = false;
|
||||
|
||||
var url = "/api/users/" + context.JK.currentUserId + "/friends/" + userId;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
|
|
@ -85,20 +87,27 @@
|
|||
async: false,
|
||||
processData: false,
|
||||
success: function(response) {
|
||||
logger.debug("response=" + response);
|
||||
if (response.id !== undefined) {
|
||||
alreadyFriend = true;
|
||||
}
|
||||
else {
|
||||
alreadyFriend = false;
|
||||
}
|
||||
},
|
||||
error: app.ajaxError
|
||||
});
|
||||
|
||||
return alreadyFriend;
|
||||
}
|
||||
|
||||
function friendRequestCallback() {
|
||||
configureFriendButton(true);
|
||||
}
|
||||
|
||||
function configureFriendButton(isFriend) {
|
||||
function configureFriendButton(friend) {
|
||||
$('#btn-add-friend').unbind("click");
|
||||
|
||||
if (isFriend) {
|
||||
|
||||
if (friend) {
|
||||
$('#btn-add-friend').text('REMOVE FRIEND');
|
||||
$('#btn-add-friend').click(removeFriend);
|
||||
}
|
||||
|
|
@ -151,6 +160,8 @@
|
|||
}
|
||||
|
||||
function isFollowing() {
|
||||
var alreadyFollowing = false;
|
||||
|
||||
var url = "/api/users/" + context.JK.currentUserId + "/followings/" + userId;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
|
|
@ -159,16 +170,23 @@
|
|||
async: false,
|
||||
processData: false,
|
||||
success: function(response) {
|
||||
logger.debug("response=" + response);
|
||||
if (response.id !== undefined) {
|
||||
alreadyFollowing = true;
|
||||
}
|
||||
else {
|
||||
alreadyFollowing = false;
|
||||
}
|
||||
},
|
||||
error: app.ajaxError
|
||||
});
|
||||
|
||||
return alreadyFollowing;
|
||||
}
|
||||
|
||||
function configureFollowingButton(isFollowing) {
|
||||
function configureFollowingButton(following) {
|
||||
$('#btn-follow').unbind("click");
|
||||
|
||||
if (isFollowing) {
|
||||
if (following) {
|
||||
$('#btn-follow').text('STOP FOLLOWING');
|
||||
$('#btn-follow').click(removeFollowing);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ class ApiUsersController < ApiController
|
|||
end
|
||||
|
||||
def following_show
|
||||
@following = UserFollowing.where("user_id='#{params[:user_id]}' AND follower_id='#{params[:id]}'")
|
||||
@following = UserFollowing.find_by_user_id_and_follower_id(params[:user_id], params[:id])
|
||||
end
|
||||
|
||||
def band_following_index
|
||||
|
|
@ -335,7 +335,7 @@ class ApiUsersController < ApiController
|
|||
end
|
||||
|
||||
def friend_show
|
||||
@friend = Friendship.where("user_id='#{params[:id]}' AND friend_id='#{params[:friend_id]}'")
|
||||
@friend = Friendship.find_by_user_id_and_friend_id(params[:id], params[:friend_id])
|
||||
end
|
||||
|
||||
def friend_destroy
|
||||
|
|
|
|||
Loading…
Reference in New Issue