VRFS-76 band profile work

This commit is contained in:
Brian Smith 2013-10-27 19:53:49 -04:00
parent a0d8c1e1b5
commit a6c1b0d79d
7 changed files with 676 additions and 8 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -8,4 +8,92 @@
<h1>musician profile</h1>
<%= render "screen_navigation" %>
</div>
</div>
<form id="band-profile-form">
<div class="band-profile-header">
<h2 id="band-profile-name"></h2>
<div class="band-profile-status">
</div>
<div class="right">
<a id="btn-follow-band" class="button-orange">FOLLOW</a>
</div>
<br clear="all" /><br />
<!-- avatar -->
<div class="band-profile-photo">
<div class="avatar-profile">
<img id="band-profile-avatar" width="200" height="200" />
</div>
</div>
<!-- profile navigation -->
<div class="band-profile-nav">
<a id="band-profile-about-link" class="active">about</a>
<a id="band-profile-history-link">history</a>
<a id="band-profile-members-link">members</a>
<a id="band-profile-social-link">social</a>
</div>
</div>
<br clear="all" />
<div class="content-scroller" style="height:350px;">
<div id="band-profile-about" class="band-profile-wrapper">
<!-- stats & location -->
<div class="band-profile-about-left">
<h3>Location:</h3><br />
<span id="band-profile-location"></span><br /><br /><br />
<h3>Stats:</h3><br />
<span id="band-profile-follower-stats"></span><br />
<span id="band-profile-session-stats"></span><br />
<span id="band-profile-recording-stats"></span><br />
</div>
<div class="band-profile-about-right">
<p id="band-profile-biography"></p><br />
</div>
<br clear="all" />
</div>
<div id="band-profile-history" class="band-profile-wrapper">
<br clear="all" />
</div>
<div id="band-profile-members" class="band-profile-wrapper">
<br clear="all" />
</div>
<div id="band-profile-social" class="band-profile-wrapper">
<div class="band-profile-social-right">
<h2>Followers</h2>
<div id="band-profile-social-followers">
</div>
</div>
<br clear="all" />
</div>
<div id="band-profile-favorites" class="band-profile-wrapper">
<br clear="all" />
</div>
</div>
</form>
</div>
<script type="text/template" id="template-band-profile-members">
<div user-id="{userId}" class="band-profile-members">
<div class="avatar-small">
<img src="{avatar_url}" width="275" height="183" />
</div>
<div class="band-profile-member-name"><a href="{band_url}">{name}</a><br />
<span class="band-profile-member-location">{location}</span>
</div>
<br clear="left" />
<div class="band-profile-member-genres">{genres}</div>
<a id="btn-follow-member" class="button-orange smallbutton right">FOLLOW</a>
</div>
</script>
<script type="text/template" id="template-band-profile-social">
<div class="profile-block">
<div class="avatar-small">
<img src="{avatar_url}" />
</div>
<div class="profile-block-name">{userName}</div>
<div class="profile-block-city">{location}</div>
</div>
</script>

View File

@ -106,7 +106,7 @@
<div class="avatar-small">
<img src="{avatar_url}" width="275" height="183" />
</div>
<div class="profile-band-name">{name}<br />
<div class="profile-band-name"><a href="{band_url}">{name}</a><br />
<span class="profile-band-location">{location}</span>
</div>
<br clear="left" />

View File

@ -20,6 +20,7 @@
<%= render "findSession" %>
<%= render "session" %>
<%= render "profile" %>
<%= render "bandProfile" %>
<%= render "feed" %>
<%= render "bands" %>
<%= render "musicians" %>