VRFS-689 show pending band invitations on Band Profile Members tab

This commit is contained in:
Brian Smith 2013-12-01 01:11:23 -05:00
parent 419ff2793d
commit 4824ca4eb3
4 changed files with 80 additions and 48 deletions

View File

@ -65,6 +65,12 @@ module JamRuby
@musicians = User.joins(:band_musicians).where(:bands_musicians => {:band_id => "#{band_id}"})
end
def self.pending_musicians(band_id)
@musicians = User.joins(:received_band_invitations)
.where(:band_invitations => {:band_id => "#{band_id}"})
.where(:band_invitations => {:accepted => nil})
end
def self.recording_index(current_user, band_id)
hide_private = false
band = Band.find(band_id)

View File

@ -6,11 +6,13 @@
context.JK.BandProfileScreen = function(app) {
var logger = context.JK.logger;
var bandId;
var isMember = false;
var band = {};
var instrument_logo_map = context.JK.getInstrumentIconMap24();
function beforeShow(data) {
bandId = data.id;
setIsMember();
}
function afterShow(data) {
@ -337,53 +339,76 @@
async: false,
processData:false,
success: function(response) {
$.each(response, function(index, val) {
var instrumentLogoHtml = '';
var musician = val;
if ("instruments" in musician) {
for (var j=0; j < musician.instruments.length; j++) {
var instrument = musician.instruments[j];
var inst = '../assets/content/icon_instrument_default24.png';
if (instrument.instrument_id in instrument_logo_map) {
inst = instrument_logo_map[instrument.instrument_id];
}
instrumentLogoHtml += '<img src="' + inst + '" width="24" height="24" />&nbsp;';
}
}
bindMusicians(response);
},
error: app.ajaxError
});
var template = $('#template-band-profile-members').html();
var memberHtml = context.JK.fillTemplate(template, {
userId: musician.id,
profile_url: "/#/profile/" + musician.id,
avatar_url: context.JK.resolveAvatarUrl(musician.photo_url),
name: musician.name,
location: musician.location,
biography: musician.biography,
friend_count: musician.friend_count,
follower_count: musician.follower_count,
recording_count: musician.recording_count,
session_count: musician.session_count,
instruments: instrumentLogoHtml
});
if (isMember) {
bindPendingMembers();
}
}
$('#band-profile-members').append(memberHtml);
// wire up Follow button click handler
var following = isFollowingMember(musician.id);
configureMemberFollowingButton(following, musician.id);
// TODO: wire up Friend button click handler
// var friend = isFriend(musician.id);
// configureMemberFriendButton(friend, musician.id);
});
function bindPendingMembers() {
$("#band-profile-members").append("<br/><br/><h2><b>Pending Band Invitations</b></h2>");
var url = "/api/bands/" + bandId + "/musicians?pending=true";
$.ajax({
type: "GET",
dataType: "json",
url: url,
async: false,
processData:false,
success: function(response) {
bindMusicians(response);
},
error: app.ajaxError
});
}
function bindMusicians(musicians) {
$.each(musicians, function(index, musician) {
var instrumentLogoHtml = '';
if ("instruments" in musician) {
for (var j=0; j < musician.instruments.length; j++) {
var instrument = musician.instruments[j];
var inst = '../assets/content/icon_instrument_default24.png';
if (instrument.instrument_id in instrument_logo_map) {
inst = instrument_logo_map[instrument.instrument_id];
}
instrumentLogoHtml += '<img src="' + inst + '" width="24" height="24" />&nbsp;';
}
}
var template = $('#template-band-profile-members').html();
var memberHtml = context.JK.fillTemplate(template, {
userId: musician.id,
profile_url: "/#/profile/" + musician.id,
avatar_url: context.JK.resolveAvatarUrl(musician.photo_url),
name: musician.name,
location: musician.location,
biography: musician.biography,
friend_count: musician.friend_count,
follower_count: musician.follower_count,
recording_count: musician.recording_count,
session_count: musician.session_count,
instruments: instrumentLogoHtml
});
$('#band-profile-members').append(memberHtml);
// wire up Follow button click handler
var following = isFollowingMember(musician.id);
configureMemberFollowingButton(following, musician.id);
// TODO: wire up Friend button click handler
// var friend = isFriend(musician.id);
// configureMemberFriendButton(friend, musician.id);
});
}
// TODO: refactor
function isMember() {
var isMember = false;
// checks if person viewing the profile is also a band member
function setIsMember() {
var url = "/api/bands/" + bandId + "/musicians";
$.ajax({
type: "GET",
@ -400,8 +425,6 @@
},
error: app.ajaxError
});
return isMember;
}
// events for main screen
@ -416,8 +439,7 @@
var following = isFollowing();
configureBandFollowingButton(following);
var member = isMember();
if (member) {
if (isMember) {
$("#btn-follow-band").hide();
$("#btn-edit-band-members").show();
}

View File

@ -48,11 +48,15 @@ class ApiBandsController < ApiController
end
def musician_index
unless params[:id].blank?
@musicians = Band.musician_index(params[:id])
if !params[:pending].blank?
@musicians = Band.pending_musicians(params[:id])
else
render :json => { :message => "Band ID is required." }, :status => 400
unless params[:id].blank?
@musicians = Band.musician_index(params[:id])
else
render :json => { :message => "Band ID is required." }, :status => 400
end
end
end

View File

@ -204,7 +204,7 @@ SampleApp::Application.routes.draw do
match '/bands' => 'api_bands#create', :via => :post
match '/bands/:id' => 'api_bands#update', :via => :post
# band members (NOT DONE)
# band members
match '/bands/:id/musicians' => 'api_bands#musician_index', :via => :get
match '/bands/:id/musicians' => 'api_bands#musician_create', :via => :post
match '/bands/:id/musicians/:user_id' => 'api_bands#musician_destroy', :via => :delete