From f7c08ce472ea22be9cdd6917b4e296ca963a038c Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 18 Dec 2013 17:59:02 -0600 Subject: [PATCH] vrfs-916: added fan page branching logic --- web/app/assets/javascripts/profile.js | 185 +++++++++++++----------- web/app/views/api_users/show.rabl | 16 +- web/app/views/clients/_profile.html.erb | 7 +- 3 files changed, 120 insertions(+), 88 deletions(-) diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 273d88fa9..a5db58050 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -6,7 +6,7 @@ context.JK.ProfileScreen = function(app) { var logger = context.JK.logger; var userId; - var user = {}; + var user = null; var instrument_logo_map = context.JK.getInstrumentIconMap24(); @@ -24,6 +24,7 @@ function beforeShow(data) { userId = data.id; + user = null; } function afterShow(data) { @@ -45,6 +46,69 @@ $('.profile-nav a.#profile-about-link').addClass('active'); } + function getUser() { + if (user === null) { + var url = "/api/users/" + userId; + $.ajax({ + type: "GET", + dataType: "json", + url: url, + async: false, + processData:false, + success: function(response) { + user = response; + }, + error: function(jqXHR, textStatus, errorMessage) { + user = null; + app.ajaxError(jqXHR, textStatus, errorMessage); + } + }); + } + return user; + } + + function isMusician() { + if (getUser()) { + return user.musician === true; + } + return false; + } + + function configUserType() { + if (isMusician()) { + $('#profile-history-link').show(); + $('#profile-bands-link').show(); + $('#profile-instruments').show(); + $('#profile-session-stats').show(); + $('#profile-recording-stats').show(); + + $('#profile-following-stats').hide(); + $('#profile-favorites-stats').hide(); + + $('#btn-add-friend').show(); + $('#profile-social-left').show(); + + $('#profile-type-label').text('musician'); + $('#profile-location-label').text('Location'); + + } else { + $('#profile-history-link').hide(); + $('#profile-bands-link').hide(); + $('#profile-instruments').hide(); + $('#profile-session-stats').hide(); + $('#profile-recording-stats').hide(); + + $('#profile-following-stats').show(); + $('#profile-favorites-stats').show(); + + $('#btn-add-friend').hide(); + $('#profile-social-left').hide(); + + $('#profile-type-label').text('fan'); + $('#profile-location-label').text('Presence'); + } + } + /****************** MAIN PORTION OF SCREEN *****************/ // events for main screen function events() { @@ -94,27 +158,7 @@ } function isFriend() { - var alreadyFriend = false; - - var url = "/api/users/" + context.JK.currentUserId + "/friends/" + userId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData: false, - success: function(response) { - if (response.id !== undefined) { - alreadyFriend = true; - } - else { - alreadyFriend = false; - } - }, - error: app.ajaxError - }); - - return alreadyFriend; + return getUser() ? user.is_friend : false; } function friendRequestCallback() { @@ -186,27 +230,7 @@ } function isFollowing() { - 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; + return getUser() ? user.is_following : false; } function configureFollowingButton(following) { @@ -261,21 +285,9 @@ function bindAbout() { $('#profile-instruments').empty(); - var url = "/api/users/" + userId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { - user = response; - }, - error: app.ajaxError - }); - - if (user) { + if (getUser()) { + configUserType(); // name $('#profile-username').html(user.name); @@ -313,11 +325,16 @@ text = user.follower_count > 1 || user.follower_count === 0 ? " Followers" : " Follower"; $('#profile-follower-stats').html(user.follower_count + text); - text = user.session_count > 1 || user.session_count === 0 ? " Sessions" : " Session"; - $('#profile-session-stats').html(user.session_count + text); + if (user.musician === true) { + text = user.session_count > 1 || user.session_count === 0 ? " Sessions" : " Session"; + $('#profile-session-stats').html(user.session_count + text); - text = user.recording_count > 1 || user.recording_count === 0 ? " Recordings" : " Recording"; - $('#profile-recording-stats').html(user.recording_count + text); + text = user.recording_count > 1 || user.recording_count === 0 ? " Recordings" : " Recording"; + $('#profile-recording-stats').html(user.recording_count + text); + } else { + text = " Following"; + $('#profile-following-stats').html(user.following_count + text); + } $('#profile-biography').html(user.biography); } @@ -345,29 +362,31 @@ } function bindSocial() { - // FRIENDS - var url = "/api/users/" + userId + "/friends"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { - $.each(response, function(index, val) { - var template = $('#template-profile-social').html(); - var friendHtml = context.JK.fillTemplate(template, { - avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - userName: val.name, - location: val.location, - type: "Friends" - }); + if (isMusician()) { + // FRIENDS + var url = "/api/users/" + userId + "/friends"; + $.ajax({ + type: "GET", + dataType: "json", + url: url, + async: false, + processData:false, + success: function(response) { + $.each(response, function(index, val) { + var template = $('#template-profile-social').html(); + var friendHtml = context.JK.fillTemplate(template, { + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + userName: val.name, + location: val.location, + type: "Friends" + }); - $('#profile-social-friends').append(friendHtml); - }); - }, - error: app.ajaxError - }); + $('#profile-social-friends').append(friendHtml); + }); + }, + error: app.ajaxError + }); + } // FOLLOWINGS (USERS) url = "/api/users/" + userId + "/followings"; diff --git a/web/app/views/api_users/show.rabl b/web/app/views/api_users/show.rabl index 9a35978ef..4c63e2c39 100644 --- a/web/app/views/api_users/show.rabl +++ b/web/app/views/api_users/show.rabl @@ -1,11 +1,23 @@ object @user -attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :band_like_count, :follower_count, :following_count, :band_following_count, :recording_count, :session_count, -:biography +attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :band_like_count, :follower_count, :following_count, :band_following_count, :recording_count, :session_count, :biography + +if @user.musician? + node :location do @user.location end +else + node :location do @user.online ? 'Online' : 'Offline' end +end # give back more info if the user being fetched is yourself if @user == current_user attributes :email, :original_fpfile, :cropped_fpfile, :crop_selection, :session_settings, :show_whats_next, :subscribe_email +elsif current_user + node :is_friend do |uu| + @user.friends?(current_user) + end + node :is_following do |uu| + @user.following?(current_user) + end end unless @user.friends.nil? || @user.friends.size == 0 diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index 002a4add9..84b4ae9fe 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -5,7 +5,7 @@ <%= image_tag "content/icon_profile.png", :size => "19x19" %> -

musician profile

+

musician profile

<%= render "screen_navigation" %> @@ -47,11 +47,12 @@
-

Location:


+

Location:





Stats:




+


@@ -149,4 +150,4 @@
{userName}
{location}
- \ No newline at end of file +