diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 7fe0dffa9..2f76d9809 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -477,20 +477,25 @@ // FRIENDS rest.getFriends({id: userId}) .done(function (response) { - $.each(response, function (index, val) { - var template = $('#template-profile-social').html(); - var friendHtml = context.JK.fillTemplate(template, { - userId: val.id, - hoverAttributeId: "user-id", - hoverAction: val.musician ? "musician" : "fan", - avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - userName: val.name, - location: val.location, - type: "Friends" - }); + if (response && response.length > 0) { + $.each(response, function (index, val) { + var template = $('#template-profile-social').html(); + var friendHtml = context.JK.fillTemplate(template, { + userId: val.id, + hoverAttributeId: "user-id", + hoverAction: val.musician ? "musician" : "fan", + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + userName: val.name, + location: val.location, + type: "Friends" + }); - $('#profile-social-friends').append(friendHtml); - }); + $('#profile-social-friends').append(friendHtml); + }); + } + else { + $('#profile-social-friends').html(' '); + } context.JK.bindHoverEvents(); }) .fail(app.ajaxError) @@ -498,19 +503,24 @@ rest.getFollowings({id: userId}) .done(function (response) { - $.each(response, function (index, val) { - var template = $('#template-profile-social').html(); - var followingHtml = context.JK.fillTemplate(template, { - userId: val.id, - hoverAttributeId: val.type === "user" ? "user-id" : "band-id", - hoverAction: val.type === "user" ? (val.musician ? "musician" : "fan") : "band", - avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - userName: val.name, - location: val.location - }); + if (response && response.length > 0) { + $.each(response, function (index, val) { + var template = $('#template-profile-social').html(); + var followingHtml = context.JK.fillTemplate(template, { + userId: val.id, + hoverAttributeId: val.type === "user" ? "user-id" : "band-id", + hoverAction: val.type === "user" ? (val.musician ? "musician" : "fan") : "band", + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + userName: val.name, + location: val.location + }); - $('#profile-social-followings').append(followingHtml); - }); + $('#profile-social-followings').append(followingHtml); + }); + } + else { + $('#profile-social-followings').html(' '); + } context.JK.bindHoverEvents(); }) .fail(app.ajaxError);