diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 20ff38afc..7027661ea 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -47,55 +47,53 @@ /****************** MAIN PORTION OF SCREEN *****************/ function addFollowing(isBand, id) { - var newFollowing = {}; + var newFollowing = {}; - if (!isBand) { - newFollowing.user_id = id; - } - else { - newFollowing.band_id = id; - } + if (!isBand) { + newFollowing.user_id = id; + } + else { + newFollowing.band_id = id; + } - rest.addFollowing(newFollowing) - .done(function() { - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(true); - } - else { - configureMemberFollowingButton(true, id); - } - }) - .fail(app.ajaxError); + rest.addFollowing(newFollowing) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(true); + } + else { + configureMemberFollowingButton(true, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) - .done(function() { - renderActive(); // refresh stats - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(false); - } - else { - configureMemberFollowingButton(false, id); - } - }) - .fail(app.ajaxError); + rest.removeFollowing(id) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(false); + } + else { + configureMemberFollowingButton(false, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function configureBandFollowingButton(following) { $('#btn-follow-band').unbind("click"); if (following) { - $('#btn-follow-band').text('STOP FOLLOWING'); + $('#btn-follow-band').text('UNFOLLOW'); $('#btn-follow-band').click(function() { removeFollowing(true, bandId); return false; @@ -121,7 +119,7 @@ $btnFollowMember.unbind("click"); if (following) { - $btnFollowMember.text('UN-FOLLOW'); + $btnFollowMember.text('UNFOLLOW'); $btnFollowMember.click(function() { removeFollowing(false, userId); return false; diff --git a/web/app/assets/javascripts/hoverBand.js b/web/app/assets/javascripts/hoverBand.js index f1324b217..2b98e8e62 100644 --- a/web/app/assets/javascripts/hoverBand.js +++ b/web/app/assets/javascripts/hoverBand.js @@ -49,21 +49,23 @@ }); var bandHtml = context.JK.fillTemplate(template, { - avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), - name: response.name, - location: response.location, - genres: genres.join(', '), - musicians: musicianHtml, - like_count: response.liker_count, - follower_count: response.follower_count, - recording_count: response.recording_count, - session_count: response.session_count, - biography: response.biography, - profile_url: "/client#/bandProfile/" + response.id + bandId: response.id, + avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), + name: response.name, + location: response.location, + genres: genres.join(', '), + musicians: musicianHtml, + like_count: response.liker_count, + follower_count: response.follower_count, + recording_count: response.recording_count, + session_count: response.session_count, + biography: response.biography, + followAction: response.is_following ? "removeBandFollowing" : "addBandFollowing", + profile_url: "/client#/bandProfile/" + response.id }); $(hoverSelector).append('

Band Detail

' + bandHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -78,9 +80,17 @@ }); }; - function toggleActionButtons() { + function configureActionButtons(band) { + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile if (!context.JK.currentUserId) { - $("#btnFollow", hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (band.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } } } diff --git a/web/app/assets/javascripts/hoverFan.js b/web/app/assets/javascripts/hoverFan.js index 8e5d0b367..44d6ba075 100644 --- a/web/app/assets/javascripts/hoverFan.js +++ b/web/app/assets/javascripts/hoverFan.js @@ -56,13 +56,15 @@ location: response.location, friend_count: response.friend_count, follower_count: response.follower_count, + friendAction: response.is_friend ? "removeFanFriend" : (response.pending_friend_request ? "" : "sendFanFriendRequest"), + followAction: response.is_following ? "removeFanFollowing" : "addFanFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Fan Detail

' + fanHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -77,10 +79,30 @@ }); }; - function toggleActionButtons() { - if (!context.JK.currentUserId) { - $("#btnFriend", hoverSelector).hide(); - $("#btnFollow", hoverSelector).hide(); + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + + $(btnFollowSelector, hoverSelector).click(function(evt) { + rest.removeFollowing(user.id); + }); + } + + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } } } diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index d73226fde..449e12380 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -75,13 +75,15 @@ session_count: response.session_count, session_display: sessionDisplayStyle, session_id: sessionId, + friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"), + followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Musician Detail

' + musicianHtml); - toggleActionButtons(); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -96,10 +98,25 @@ }); }; - function toggleActionButtons() { - if (!context.JK.currentUserId) { - $("#btnFriend", hoverSelector).hide(); - $("#btnFollow", hoverSelector).hide(); + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } } } diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 92fe43939..4363a11d8 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -451,7 +451,7 @@ }); } - function removeLike(options) { + function removeLike(likableId, options) { var id = getId(options); return $.ajax({ type: "DELETE", @@ -476,15 +476,13 @@ }); } - function removeFollowing(options) { + function removeFollowing(followableId, options) { var id = getId(options); - return $.ajax({ type: "DELETE", dataType: "json", contentType: 'application/json', - url: "/api/users/" + id + "/followings", - data: JSON.stringify(options), + url: "/api/users/" + id + "/followings/" + followableId, processData: false }); } diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index ff15ff574..2b5a9d509 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -193,10 +193,10 @@ function configureFriendButton() { if (isFriend()) { - $('#btn-add-friend').text('REMOVE FRIEND'); + $('#btn-add-friend').text('DISCONNECT'); } else { - $('#btn-add-friend').text('ADD FRIEND'); + $('#btn-add-friend').text('CONNECT'); } } @@ -213,10 +213,7 @@ } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) + rest.removeFollowing(id) .done(function() { if (!isBand) { updateFollowingCount(-1); @@ -242,7 +239,7 @@ function configureFollowingButton() { if (isFollowing()) { - $('#btn-follow-user').text('STOP FOLLOWING'); + $('#btn-follow-user').text('UNFOLLOW'); } else { $('#btn-follow-user').text('FOLLOW'); diff --git a/web/app/assets/javascripts/searchResults.js b/web/app/assets/javascripts/searchResults.js index 884c2dbda..2f32a697d 100644 --- a/web/app/assets/javascripts/searchResults.js +++ b/web/app/assets/javascripts/searchResults.js @@ -117,23 +117,23 @@ selector = isSidebar ? '#sidebar-search-results' : '#search-results'; $(selector).append(invitationSentHtml); - // wire up button click handler if search result is not a friend or the current use + // wire up button click handler if search result is not a friend or the current user if (isSidebar) { var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']'); - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $sidebar.find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + // hide the button if the search result is already a friend + $sidebar.find('.btn-connect-friend').hide(); } else { - // hide the button if the search result is already a friend - $sidebar.find('.btn-connect-friend').hide(); + $sidebar.find('.btn-connect-friend').click(sendFriendRequest); } } else { - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); } else { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); } } resultDivVisibility(val, isSidebar); diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 23b32f885..697bc2c95 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -202,7 +202,7 @@ class ApiUsersController < ApiController end def liking_destroy - User.delete_liking(params[:id], params[:target_entity_id]) + User.delete_liking(params[:id], params[:likable_id]) respond_with responder: ApiResponder, :status => 204 end @@ -230,7 +230,7 @@ class ApiUsersController < ApiController end def following_destroy - User.delete_following(params[:id], params[:target_entity_id]) + User.delete_following(params[:id], params[:followable_id]) respond_with responder: ApiResponder, :status => 204 end diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 8164c4549..b6a902199 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -23,6 +23,10 @@ if @search.musicians_text_search? musician.friends?(current_user) end + node :pending_friend_request do |musician| + musician.pending_friend_request?(current_user) + end + child :musician_instruments => :instruments do attributes :instrument_id, :description, :proficiency_level, :priority end @@ -50,6 +54,10 @@ if @search.musicians_filter_search? @search.is_follower?(musician) end + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end + node :biography do |musician| musician.biography.nil? ? "" : musician.biography end @@ -112,6 +120,10 @@ if @search.fans_text_search? node :is_friend do |fan| fan.friends?(current_user) end + + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end } end diff --git a/web/app/views/clients/_hoverBand.html.erb b/web/app/views/clients/_hoverBand.html.erb index ee8f0c5ff..7ee0fe2c2 100644 --- a/web/app/views/clients/_hoverBand.html.erb +++ b/web/app/views/clients/_hoverBand.html.erb @@ -5,25 +5,49 @@ @@ -54,9 +92,9 @@
PROFILE
-
LIKE
-
FRIEND
-
FOLLOW
+ +
CONNECT
+
FOLLOW


diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index a662c1c8e..12705cbee 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -53,7 +53,7 @@
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %> - + <%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %> <% end %> diff --git a/web/config/routes.rb b/web/config/routes.rb index 3fa2edf92..79286139c 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -161,7 +161,7 @@ SampleApp::Application.routes.draw do # user likes match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index' match '/users/:id/likings' => 'api_users#liking_create', :via => :post - match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete + match '/users/:id/likings/:likable_id' => 'api_users#liking_destroy', :via => :delete # user followers match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index' @@ -169,7 +169,7 @@ SampleApp::Application.routes.draw do # user followings match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index' match '/users/:id/followings' => 'api_users#following_create', :via => :post - match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete + match '/users/:id/followings/:followable_id' => 'api_users#following_destroy', :via => :delete # favorites match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index' diff --git a/web/spec/requests/users_api_spec.rb b/web/spec/requests/users_api_spec.rb index 80d8bd5a8..6e3df944a 100644 --- a/web/spec/requests/users_api_spec.rb +++ b/web/spec/requests/users_api_spec.rb @@ -56,7 +56,7 @@ describe "User API", :type => :api do def delete_user_like(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/likings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end @@ -99,7 +99,7 @@ describe "User API", :type => :api do def delete_user_following(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/followings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end