diff --git a/ruby/lib/jam_ruby/models/like.rb b/ruby/lib/jam_ruby/models/like.rb index f0d104d71..cddf26ce9 100644 --- a/ruby/lib/jam_ruby/models/like.rb +++ b/ruby/lib/jam_ruby/models/like.rb @@ -4,5 +4,10 @@ module JamRuby belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id" belongs_to :likable, :polymorphic => true + def type + type = self.likable_type.gsub("JamRuby::", "").downcase + type + end + end end \ No newline at end of file diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 4738620b3..cdb49ae8b 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -80,30 +80,6 @@ .fail(app.ajaxError); } - function isFollowingMember(userId) { - var alreadyFollowing = false; - - var url = "/api/users/" + context.JK.currentUserId + "/followings/" + userId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData: false, - success: function(response) { - if (response.id !== undefined) { - alreadyFollowing = true; - } - else { - alreadyFollowing = false; - } - }, - error: app.ajaxError - }); - - return alreadyFollowing; - } - function configureBandFollowingButton(following) { $('#btn-follow-band').unbind("click"); @@ -372,9 +348,7 @@ $('#band-profile-members').append(memberHtml); // wire up Follow button click handler - var following = isFollowingMember(musician.id); - configureMemberFollowingButton(following, musician.id); - + configureMemberFollowingButton(musician.is_following, musician.id); configureRemoveMemberButton(musician.id); // TODO: wire up Friend button click handler diff --git a/web/app/assets/javascripts/hoverFan.js b/web/app/assets/javascripts/hoverFan.js index 69af6ee01..b23342180 100644 --- a/web/app/assets/javascripts/hoverFan.js +++ b/web/app/assets/javascripts/hoverFan.js @@ -25,8 +25,19 @@ followingHtml += ''; } - followingHtml += ''; - followingHtml += '' + val.name + ''; + var avatarUrl, profilePath; + + if (val.type === "band") { + avatarUrl = context.JK.resolveBandAvatarUrl(val.photo_url); + profilePath = "bandProfile"; + } + else { + avatarUrl = context.JK.resolveAvatarUrl(val.photo_url); + profilePath = "profile"; + } + + followingHtml += ''; + followingHtml += '' + val.name + ''; if (index % 2 > 0) { followingHtml += ''; diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index 63280f2ff..5a1e6d427 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -26,7 +26,7 @@ // followings var followingHtml = ''; $.each(response.followings, function(index, val) { - if (index < 4) { // display max of 4 followings (NOTE: this only displays USER followings, not BAND followings) + if (index < 4) { // display max of 4 followings if (index % 2 === 0) { followingHtml += ''; } @@ -35,7 +35,7 @@ if (val.type === "band") { avatarUrl = context.JK.resolveBandAvatarUrl(val.photo_url); - profilePath = "bandProfile" + profilePath = "bandProfile"; } else { avatarUrl = context.JK.resolveAvatarUrl(val.photo_url); diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index d7d4a959f..b4d011775 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -578,7 +578,7 @@ function addBandFollowing(evt) { evt.stopPropagation(); - var bandId = $(this).parent().parent().attr('band-id'); + var bandId = $(this).parent().parent().parent().parent().attr('band-id'); var newFollowing = {}; newFollowing.band_id = bandId; diff --git a/web/app/views/api_bands/musician_index.rabl b/web/app/views/api_bands/musician_index.rabl index 905fb9273..f47fe7f5e 100644 --- a/web/app/views/api_bands/musician_index.rabl +++ b/web/app/views/api_bands/musician_index.rabl @@ -14,3 +14,12 @@ node :biography do |musician| musician.biography.nil? ? "" : musician.biography end +if current_user + node :is_following do |musician| + current_user.following?(musician) + end + + node :is_liking do |musician| + current_user.likes?(musician) + end +end diff --git a/web/app/views/api_bands/show.rabl b/web/app/views/api_bands/show.rabl index 8bd3ca76a..74d8dd08d 100644 --- a/web/app/views/api_bands/show.rabl +++ b/web/app/views/api_bands/show.rabl @@ -25,4 +25,7 @@ if current_user node :is_following do |uu| current_user.following?(@band) end + node :is_liking do |uu| + current_user.likes?(@band) + end end \ No newline at end of file diff --git a/web/app/views/api_users/following_index.rabl b/web/app/views/api_users/following_index.rabl index 09ab85c06..58f33c335 100644 --- a/web/app/views/api_users/following_index.rabl +++ b/web/app/views/api_users/following_index.rabl @@ -20,4 +20,8 @@ end node :photo_url do |following| following.followable.photo_url +end + +node :type do |following| + following.type end \ No newline at end of file diff --git a/web/app/views/api_users/following_show.rabl b/web/app/views/api_users/following_show.rabl index fff81526b..c12929647 100644 --- a/web/app/views/api_users/following_show.rabl +++ b/web/app/views/api_users/following_show.rabl @@ -1,3 +1,3 @@ object @following -attributes :id, :user_id, :follower_id \ No newline at end of file +attributes :id, :user_id, :followable_id \ No newline at end of file diff --git a/web/app/views/api_users/liking_index.rabl b/web/app/views/api_users/liking_index.rabl index 84f047016..5f3184cb7 100644 --- a/web/app/views/api_users/liking_index.rabl +++ b/web/app/views/api_users/liking_index.rabl @@ -20,4 +20,8 @@ end node :photo_url do |liking| liking.likable.photo_url +end + +node :type do |liking| + liking.type end \ No newline at end of file diff --git a/web/app/views/api_users/show.rabl b/web/app/views/api_users/show.rabl index 1ed5202e9..9c1d18422 100644 --- a/web/app/views/api_users/show.rabl +++ b/web/app/views/api_users/show.rabl @@ -32,7 +32,6 @@ child :friends => :friends do end child :followings => :followings do - attributes :type node :id do |f| @@ -50,7 +49,6 @@ child :followings => :followings do node :photo_url do |f| f.followable.photo_url end - end child :band_musicians => :bands do diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index eb69f0ef5..76e887592 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -154,7 +154,7 @@
{musicians}
-
+