diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index e69de29bb..29d7ddeb1 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -0,0 +1,358 @@ +(function(context,$) { + + "use strict"; + + context.JK = context.JK || {}; + context.JK.BandProfileScreen = function(app) { + var logger = context.JK.logger; + var bandId; + var band = {}; + + function beforeShow(data) { + bandId = data.id; + } + + function afterShow(data) { + resetForm(); + events(); + renderActive(); + } + + function resetForm() { + $('#band-profile-instruments').empty(); + + $('#band-profile-about').show(); + $('#band-profile-history').hide(); + $('#band-profile-members').hide(); + $('#band-profile-social').hide(); + + $('.band-profile-nav a.active').removeClass('active'); + $('.band-profile-nav a.#band-profile-about-link').addClass('active'); + } + + /****************** MAIN PORTION OF SCREEN *****************/ + + function addFollowing() { + var newFollowing = {}; + newFollowing.band_id = userId; + + var url = "/api/users/" + context.JK.currentUserId + "/band_followings"; + $.ajax({ + type: "POST", + dataType: "json", + contentType: 'application/json', + url: url, + data: JSON.stringify(newFollowing), + processData: false, + success: function(response) { + renderActive(); // refresh stats + configureFollowingButton(true); + }, + error: app.ajaxError + }); + } + + function removeFollowing(bandId) { + var following = {}; + following.band_id = id; + + var url = "/api/users/" + context.JK.currentUserId + "/followings"; + $.ajax({ + type: "DELETE", + dataType: "json", + contentType: 'application/json', + url: url, + data: JSON.stringify(following), + processData: false, + success: function(response) { + renderActive(); // refresh stats + configureBandFollowingButton(id); + }, + error: app.ajaxError + }); + } + + function isFollowing() { + var alreadyFollowing = false; + + var url = "/api/users/" + context.JK.currentUserId + "/band_followings/" + bandId; + $.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 configureFollowingButton(following, bandId) { + var $btnFollowBand = $('div[band-id=' + bandId + ']', '#profile-bands').find('#btn-follow-band'); + $btnFollowBand.unbind("click"); + + if (following) { + $btnFollowBand.text('UN-FOLLOW'); + $btnFollowBand.click(function() { + removeFollowing(true, bandId); + }); + } + else { + $btnFollowBand.text('FOLLOW'); + $btnFollowBand.click(addBandFollowing); + } + } + + // refreshes the currently active tab + function renderActive() { + if ($('#band-profile-about-link').hasClass('active')) { + renderAbout(); + } + else if ($('#band-profile-history-link').hasClass('active')) { + renderHistory(); + } + else if ($('#band-profile-members-link').hasClass('active')) { + renderMembers(); + } + else if ($('#band-profile-social-link').hasClass('active')) { + renderSocial(); + } + } + + /****************** ABOUT TAB *****************/ + function renderAbout() { + + $('#band-profile-about').show(); + $('#band-profile-history').hide(); + $('#band-profile-members').hide(); + $('#band-profile-social').hide(); + + $('.band-profile-nav a.active').removeClass('active'); + $('.band-profile-nav a.#band-profile-about-link').addClass('active'); + + bindAbout(); + } + + function bindAbout() { + var url = "/api/bands/" + bandId; + $.ajax({ + type: "GET", + dataType: "json", + url: url, + async: false, + processData:false, + success: function(response) { + band = response; + }, + error: app.ajaxError + }); + + if (band) { + + // name + $('#band-profile-name').html(band.name); + + // avatar + $('#band-profile-avatar').attr('src', context.JK.resolveAvatarUrl(band.photo_url)); + + // instruments + // if (user.instruments) { + // for (var i=0; i < user.instruments.length; i++) { + // var instrument = user.instruments[i]; + // var description = instrument.instrument_id; + // var proficiency = instrument.proficiency_level; + // var instrument_icon_url = context.JK.getInstrumentIcon45(description); + + // // add instrument info to layout + // var template = $('#template-profile-instruments').html(); + // var instrumentHtml = context.JK.fillTemplate(template, { + // instrument_logo_url: instrument_icon_url, + // instrument_description: description, + // proficiency_level: proficiencyDescriptionMap[proficiency], + // proficiency_level_css: proficiencyCssMap[proficiency] + // }); + + // $('#profile-instruments').append(instrumentHtml); + // } + // } + + // location + $('#band-profile-location').html(band.location); + + // stats + var text = band.follower_count > 1 || band.follower_count == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(band.follower_count + text); + + text = band.session_count > 1 || band.session_count == 0 ? " Sessions" : " Session"; + $('#band-profile-session-stats').html(band.session_count + text); + + text = band.recording_count > 1 || band.recording_count == 0 ? " Recordings" : " Recording"; + $('#band-profile-recording-stats').html(band.recording_count + text); + + $('#band-profile-biography').html(band.biography); + } + else { + + } + } + + /****************** SOCIAL TAB *****************/ + function renderSocial() { + $('#profile-social-friends').empty(); + $('#profile-social-followings').empty(); + $('#profile-social-followers').empty(); + + $('#profile-about').hide(); + $('#profile-history').hide(); + $('#profile-bands').hide(); + $('#profile-social').show(); + $('#profile-favorites').hide(); + + $('.profile-nav a.active').removeClass('active'); + $('.profile-nav a.#profile-social-link').addClass('active'); + + bindSocial(); + } + + function bindSocial() { + // FOLLOWERS + url = "/api/users/" + userId + "/followers"; + $.ajax({ + type: "GET", + dataType: "json", + url: url, + async: false, + processData:false, + success: function(response) { + $.each(response, function(index, val) { + var template = $('#template-band-profile-social').html(); + var followerHtml = context.JK.fillTemplate(template, { + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + userName: val.name, + location: val.location + }); + + $('#profile-social-followers').append(followerHtml); + }); + }, + error: app.ajaxError + }); + } + + /****************** HISTORY TAB *****************/ + function renderHistory() { + $('#profile-about').hide(); + $('#profile-history').show(); + $('#profile-bands').hide(); + $('#profile-social').hide(); + $('#profile-favorites').hide(); + + $('.profile-nav a.active').removeClass('active'); + $('.profile-nav a.#profile-history-link').addClass('active'); + + bindHistory(); + } + + function bindHistory() { + + } + + /****************** BANDS TAB *****************/ + function renderMembers() { + $('#band-profile-members').empty(); + + $('#band-profile-about').hide(); + $('#band-profile-history').hide(); + $('#band-profile-members').show(); + $('#band-profile-social').hide(); + + $('.band-profile-nav a.active').removeClass('active'); + $('.band-profile-nav a.#band-profile-bands-link').addClass('active'); + + bindMembers(); + } + + function bindMembers() { + var url = "/api/bands/" + bandId + "/musicians"; + $.ajax({ + type: "GET", + dataType: "json", + url: url, + async: false, + processData:false, + success: function(response) { + $.each(response, function(index, val) { + var template = $('#template-band-profile-members').html(); + var bandHtml = context.JK.fillTemplate(template, { + bandId: val.id, + band_url: "/#/bandProfile/" + val.id, + avatar_url: context.JK.resolveAvatarUrl(val.logo_url), + name: val.name, + location: val.location, + genres: formatGenres(val.genres) + }); + + $('#profile-bands').append(bandHtml); + + // wire up Band Follow button click handler + var following = isFollowingBand(val.id); + configureBandFollowingButton(following, val.id); + }); + }, + error: app.ajaxError + }); + } + + function formatGenres(genres) { + var formattedGenres = ''; + if (genres) { + for (var i=0; i < genres.length; i++) { + var genre = genres[i]; + formattedGenres += genre.description; + if (i < genres.length -1) { + formattedGenres += ', '; + } + } + } + return formattedGenres; + } + + // events for main screen + function events() { + // wire up panel clicks + $('#band-profile-about-link').click(renderAbout); + $('#band-profile-history-link').click(renderHistory); + $('#band-profile-bands-link').click(renderBands); + $('#band-profile-social-link').click(renderSocial); + $('#band-profile-favorites-link').click(renderFavorites); + + // wire up Follow click + var following = isFollowing(); + configureFollowingButton(following); + } + + function initialize() { + var screenBindings = { + 'beforeShow': beforeShow, + 'afterShow': afterShow + }; + app.bindScreen('profile', screenBindings); + } + + + this.initialize = initialize; + this.beforeShow = beforeShow; + this.afterShow = afterShow; + return this; + }; + + })(window,jQuery); \ No newline at end of file diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 3268d1834..6a9e7dde2 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -484,6 +484,7 @@ var template = $('#template-profile-bands').html(); var bandHtml = context.JK.fillTemplate(template, { bandId: val.id, + band_url: "/#/bandProfile/" + val.id, avatar_url: context.JK.resolveAvatarUrl(val.logo_url), name: val.name, location: val.location, @@ -503,11 +504,13 @@ function formatGenres(genres) { var formattedGenres = ''; - for (var i=0; i < genres.length; i++) { - var genre = genres[i]; - formattedGenres += genre.description; - if (i < genres.length -1) { - formattedGenres += ', '; + if (genres) { + for (var i=0; i < genres.length; i++) { + var genre = genres[i]; + formattedGenres += genre.description; + if (i < genres.length -1) { + formattedGenres += ', '; + } } } return formattedGenres; diff --git a/web/app/assets/stylesheets/client/bandProfile.css.scss b/web/app/assets/stylesheets/client/bandProfile.css.scss new file mode 100644 index 000000000..ada3d0a5c --- /dev/null +++ b/web/app/assets/stylesheets/client/bandProfile.css.scss @@ -0,0 +1,218 @@ +@import "client/common.css.scss"; + +.band-profile-header { + padding:20px; + height:120px; +} + +.band-profile-header h2 { + font-weight:200; + font-size: 28px; + float:left; + margin: 0px 150px 0px 0px; +} + +.band-profile-status { + font-size:12px; + float:left; + display:inline-block; + vertical-align:middle; + line-height:30px; +} + +.band-profile-photo { + height: 95px; + width: 15%; + float:left; +} + +.band-profile-nav { + width:85%; + position:relative; + float:right; + margin-right:-10px; +} + +.band-profile-nav a { + width:19%; + text-align:center; + height: 27px; + display: block; + float:left; + margin-right:5px; + vertical-align:bottom; + padding-top:65px; + background-color:#535353; + color:#ccc; + font-size:17px; + text-decoration:none; +} + +.band-profile-nav a:hover { + background-color:#666; + color:#fff; +} + +.band-profile-nav a.active { + background-color:#ed3618; + color:#fff; +} + +.band-profile-nav a.active:hover { + background-color:#ed3618; + cursor:default; +} + +.band-profile-nav a.last { + margin-right:0px !important; +} + +.avatar-profile { + float:left; + padding:2px; + width:88px; + height:88px; + background-color:#ed3618; + -webkit-border-radius:44px; + -moz-border-radius:44px; + border-radius:44px; +} + +.avatar-profile img { + width:88px; + height:88px; + -webkit-border-radius:44px; + -moz-border-radius:44px; + border-radius:44px; +} + +.band-profile-wrapper { + padding:10px 25px 10px 25px; + font-size:15px; + color:#ccc; + border-bottom: dotted 1px #444; + position:relative; + display:block; +} + +.band-profile-about-left { + width:16%; + float:left; + font-size:13px; + line-height:140%; + display:block; +} + +.band-profile-about-left h3 { + color:#fff; + margin-bottom:0px; + font-size:13px; + font-weight:bold; + display:inline; +} + +.band-profile-about-right { + float:right; + font-size:13px; + width:84%; + line-height:140%; + display:block; +} + +.band-profile-about-right .band-profile-instrument { + text-align:center; + margin-right:15px; + float:left; +} + +.proficiency-beginner { + font-size:10px; + color:#8ea415; + font-weight:600; +} + +.proficiency-intermediate { + font-size:10px; + color:#0b6672; + font-weight:600; +} + +.proficiency-expert { + font-size:10px; + color:#ed3618; + font-weight:600; +} + +.band-profile-members { + width:215px; + min-height:90px; + background-color:#242323; + position:relative; + float:left; + margin:10px 20px 10px 0px; + padding-bottom:5px; +} + +.band-profile-member-name { + float:left; + font-size:12px; + margin-top:12px; + font-weight:bold; +} + +.band-profile-member-location { + font-size:12px; + font-weight:200; +} + +.band-profile-member-genres { + float:left; + width:40%; + font-size:10px; + margin-left:10px; + padding-right:5px; +} + +.band-profile-social-left { + float:left; + width:32%; + margin-right:12px; + border-right:solid 1px #666; +} + +.band-profile-social-mid { + float:left; + width:31%; + margin-right:12px; + border-right:solid 1px #666; +} + +.band-profile-social-right { + float:left; + width:31%; +} + +.band-profile-social-left h2, .band-profile-social-mid h2, .band-profile-social-right h2 { + font-weight:200; + color:#fff; + font-size:20px; +} + +.band-profile-block { + clear:left; + white-space:nowrap; + display:block; + margin-bottom:10px; +} + +.band-profile-block-name { + display:inline-block; + margin-top:13px; + font-size:14px; + color:#fff; + font-weight:bold; +} + +.band-profile-block-city { + font-size:12px; +} diff --git a/web/app/views/api_bands/show.rabl b/web/app/views/api_bands/show.rabl index fc4b171d9..bcd2ed486 100644 --- a/web/app/views/api_bands/show.rabl +++ b/web/app/views/api_bands/show.rabl @@ -1,6 +1,6 @@ object @band -attributes :id, :name, :city, :state, :country, :website, :biography, :photo_url, :logo_url, :liker_count, :follower_count, :recording_count, :session_count +attributes :id, :name, :city, :state, :country, :location, :website, :biography, :photo_url, :logo_url, :liker_count, :follower_count, :recording_count, :session_count unless @band.users.nil? || @band.users.size == 0 child :users => :musicians do diff --git a/web/app/views/clients/_bandProfile.html.erb b/web/app/views/clients/_bandProfile.html.erb index ab0cbdbee..9b2389a1a 100644 --- a/web/app/views/clients/_bandProfile.html.erb +++ b/web/app/views/clients/_bandProfile.html.erb @@ -8,4 +8,92 @@

musician profile

<%= render "screen_navigation" %> - \ No newline at end of file + +
+
+

+ +
+
+ +
+ FOLLOW +
+ +

+ +
+
+ +
+
+ + + +
+
+
+
+ +
+

Location:


+


+

Stats:


+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+

Followers

+
+
+
+
+
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index 70ec227df..790c44cee 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -106,7 +106,7 @@
-
{name}
+
{name}
{location}

diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index f8f109faa..4ea476efc 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -20,6 +20,7 @@ <%= render "findSession" %> <%= render "session" %> <%= render "profile" %> +<%= render "bandProfile" %> <%= render "feed" %> <%= render "bands" %> <%= render "musicians" %>