489 lines
15 KiB
JavaScript
489 lines
15 KiB
JavaScript
/**
|
|
* Common utility functions.
|
|
*/
|
|
(function (context, $) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
var profileUtils = {};
|
|
context.JK.ProfileUtils = profileUtils;
|
|
|
|
// genre types
|
|
var PROFILE_GENRE_TYPE = 'profile';
|
|
var VIRTUAL_BAND_GENRE_TYPE = 'virtual_band';
|
|
var TRADITIONAL_BAND_GENRE_TYPE = 'traditional_band';
|
|
var PAID_SESSION_GENRE_TYPE = 'paid_sessions';
|
|
var FREE_SESSION_GENRE_TYPE = 'free_sessions';
|
|
var COWRITING_GENRE_TYPE = 'cowriting';
|
|
|
|
var NOT_SPECIFIED_TEXT = 'Not specified';
|
|
|
|
var proficiencyDescriptionMap = {
|
|
"1": "BEGINNER",
|
|
"2": "INTERMEDIATE",
|
|
"3": "EXPERT"
|
|
};
|
|
|
|
var proficiencyCssMap = {
|
|
"1": "proficiency-beginner",
|
|
"2": "proficiency-intermediate",
|
|
"3": "proficiency-expert"
|
|
};
|
|
|
|
|
|
// performance sample types
|
|
profileUtils.SAMPLE_TYPES = {
|
|
JAMKAZAM: {description: "jamkazam"},
|
|
SOUNDCLOUD: {description: "soundcloud"},
|
|
YOUTUBE: {description: "youtube"}
|
|
};
|
|
|
|
// online presence types
|
|
profileUtils.ONLINE_PRESENCE_TYPES = {
|
|
SOUNDCLOUD: {description: "soundcloud"},
|
|
REVERBNATION: {description: "reverbnation"},
|
|
BANDCAMP: {description: "bandcamp"},
|
|
FANDALISM: {description: "fandalism"},
|
|
YOUTUBE: {description: "youtube"},
|
|
FACEBOOK: {description: "facebook"},
|
|
TWITTER: {description: "twitter"}
|
|
};
|
|
|
|
var USER_TYPE = 'JamRuby::User';
|
|
|
|
profileUtils.skillLevelMap = {
|
|
"1": "Amateur",
|
|
"2": "Professional"
|
|
};
|
|
|
|
profileUtils.gigMap = {
|
|
"": "not specified",
|
|
"0": "zero",
|
|
"1": "under 10",
|
|
"2": "10 to 50",
|
|
"3": "50 to 100",
|
|
"4": "over 100"
|
|
};
|
|
|
|
profileUtils.studioMap = {
|
|
"0": "zero",
|
|
"1": "under 10",
|
|
"2": "10 to 50",
|
|
"3": "50 to 100",
|
|
"4": "over 100"
|
|
};
|
|
|
|
profileUtils.cowritingPurposeMap = {
|
|
"1": "just for fun",
|
|
"2": "sell music"
|
|
};
|
|
|
|
profileUtils.bandCommitmentMap = {
|
|
"1": "infrequent",
|
|
"2": "once a week",
|
|
"3": "2-3 times a week",
|
|
"4": "4+ times a week"
|
|
}
|
|
|
|
function buildGenreList(genres) {
|
|
var list = '';
|
|
|
|
for (var i=0; i < genres.length; i++) {
|
|
list = list.concat(genres[i].genre_id);
|
|
if (i !== genres.length - 1) {
|
|
list = list.concat(', ');
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
// Initialize standard profile help bubbles (topics stored as attributes on element):
|
|
profileUtils.initializeHelpBubbles = function(parentElement) {
|
|
$(".help", parentElement).each(function( index ) {
|
|
context.JK.helpBubble($(this), $(this).attr("help-topic"), {}, {})
|
|
})
|
|
}
|
|
|
|
// profile genres
|
|
profileUtils.profileGenres = function(genres) {
|
|
var matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === PROFILE_GENRE_TYPE;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.profileGenreList = function(genres) {
|
|
var matches = profileUtils.profileGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
// virtual band genres
|
|
profileUtils.virtualBandGenres = function(genres) {
|
|
var matches = [];
|
|
if (genres) {
|
|
matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === VIRTUAL_BAND_GENRE_TYPE;
|
|
});
|
|
}
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.virtualBandGenreList = function(genres) {
|
|
var matches = profileUtils.virtualBandGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
// traditional band genres
|
|
profileUtils.traditionalBandGenres = function(genres) {
|
|
var matches = [];
|
|
if (genres) {
|
|
matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === TRADITIONAL_BAND_GENRE_TYPE;
|
|
});
|
|
}
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.traditionalBandGenreList = function(genres) {
|
|
var matches = profileUtils.traditionalBandGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
// paid session genres
|
|
profileUtils.paidSessionGenres = function(genres) {
|
|
var matches = [];
|
|
if (genres) {
|
|
matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === PAID_SESSION_GENRE_TYPE;
|
|
});
|
|
}
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.paidSessionGenreList = function(genres) {
|
|
var matches = profileUtils.paidSessionGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
// free session genres
|
|
profileUtils.freeSessionGenres = function(genres) {
|
|
var matches = [];
|
|
if (genres) {
|
|
matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === FREE_SESSION_GENRE_TYPE;
|
|
});
|
|
}
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.freeSessionGenreList = function(genres) {
|
|
var matches = profileUtils.freeSessionGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
// cowriting genres
|
|
profileUtils.cowritingGenres = function(genres) {
|
|
var matches = [];
|
|
if (genres) {
|
|
matches = $.grep(genres, function(g) {
|
|
return g.player_type === USER_TYPE && g.genre_type === COWRITING_GENRE_TYPE;
|
|
});
|
|
}
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.cowritingGenreList = function(genres) {
|
|
var matches = profileUtils.cowritingGenres(genres);
|
|
return buildGenreList(matches);
|
|
}
|
|
|
|
profileUtils.jamkazamSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === profileUtils.SAMPLE_TYPES.JAMKAZAM.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.soundCloudSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === profileUtils.SAMPLE_TYPES.SOUNDCLOUD.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.youTubeSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === profileUtils.SAMPLE_TYPES.YOUTUBE.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.soundCloudPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.SOUNDCLOUD.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.reverbNationPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.REVERBNATION.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.bandCampPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.BANDCAMP.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.fandalismPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.FANDALISM.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.youTubePresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.YOUTUBE.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.facebookPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.FACEBOOK.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.twitterPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === profileUtils.ONLINE_PRESENCE_TYPES.TWITTER.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
|
|
profileUtils.renderMusicalExperience = function(player, $root) {
|
|
var $instruments = $root.find('#instruments');
|
|
var $musicianStatus = $root.find('#musician-status');
|
|
var $genres = $root.find('#genres');
|
|
var $concertCount = $root.find('#concert-count');
|
|
var $studioCount = $root.find('#studio-count');
|
|
|
|
$instruments.empty();
|
|
|
|
if (player.instruments) {
|
|
for (var i = 0; i < player.instruments.length; i++) {
|
|
var instrument = player.instruments[i];
|
|
var description = instrument.instrument_id;
|
|
var proficiency = instrument.proficiency_level;
|
|
var instrument_icon_url = context.JK.getInstrumentIcon256(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]
|
|
});
|
|
|
|
$instruments.append(instrumentHtml);
|
|
}
|
|
}
|
|
|
|
// status
|
|
var status = player.skill_level;
|
|
$musicianStatus.html(status ? profileUtils.skillLevelMap[status] + ' musician' : NOT_SPECIFIED_TEXT)
|
|
|
|
// genres
|
|
$genres.empty();
|
|
var profileGenres = profileUtils.profileGenreList(player.genres);
|
|
$genres.append(profileGenres.length > 0 ? profileGenres : NOT_SPECIFIED_TEXT);
|
|
|
|
// concert gigs
|
|
var concertCount = player.concert_count;
|
|
$concertCount.html(concertCount > 0 ? 'Has played ' + profileUtils.gigMap[concertCount] + ' live concert gigs' : NOT_SPECIFIED_TEXT);
|
|
|
|
// studio gigs
|
|
var studioCount = player.studio_session_count;
|
|
$studioCount.html(studioCount > 0 ? 'Has played ' + profileUtils.gigMap[studioCount] + ' studio session gigs' : NOT_SPECIFIED_TEXT);
|
|
|
|
}// function renderMusicalExperience
|
|
|
|
profileUtils.renderPerformanceSamples = function(player, $root, isOwner) {
|
|
// performance samples
|
|
var performanceSamples = player.performance_samples;
|
|
var $noSamples = $root.find('#no-samples');
|
|
var $jamkazamSamples = $root.find('#jamkazam-samples');
|
|
var $soundCloudSamples = $root.find('#soundcloud-samples');
|
|
var $youTubeSamples = $root.find('#youtube-samples');
|
|
var $btnAddRecordings = $root.find('.add-recordings');
|
|
|
|
if (!performanceSamples || performanceSamples.length === 0) {
|
|
$noSamples.show()
|
|
$jamkazamSamples.hide()
|
|
$soundCloudSamples.hide()
|
|
$youTubeSamples.hide()
|
|
if (isOwner) {
|
|
$btnAddRecordings.show();
|
|
}
|
|
} else {
|
|
$btnAddRecordings.hide();
|
|
$noSamples.hide();
|
|
|
|
// show samples section
|
|
var jamkazamSamples = profileUtils.jamkazamSamples(player.performance_samples);
|
|
if (!jamkazamSamples || jamkazamSamples.length === 0) {
|
|
$jamkazamSamples.hide()
|
|
}
|
|
|
|
var soundCloudSamples = profileUtils.soundCloudSamples(player.performance_samples);
|
|
if (!soundCloudSamples || soundCloudSamples.length === 0) {
|
|
$soundCloudSamples.show()
|
|
}
|
|
|
|
var youTubeSamples = profileUtils.youTubeSamples(player.performance_samples);
|
|
if (!youTubeSamples || youTubeSamples.length === 0) {
|
|
$youTubeSamples.show()
|
|
}
|
|
|
|
$.each(jamkazamSamples, function(index, sample) {
|
|
$jamkazamSamples.append("<a class='jamkazam-playable' href='/recordings/" + sample.claimed_recording.id + "' rel='external'>" + formatTitle(sample.claimed_recording.name) + "</a><br/>");
|
|
});
|
|
|
|
$.each(soundCloudSamples, function(index, sample) {
|
|
$soundCloudSamples.append("<a class='sound-cloud-playable' href='' soundcloud_url='" + sample.url + "'>" + formatTitle(sample.description) + "</a><br/>");
|
|
});
|
|
|
|
$.each(youTubeSamples, function(index, sample) {
|
|
$youTubeSamples.append("<a class='youtube-playable' href='" + sample.url + "' rel='external'>" + formatTitle(sample.description) + "</a><br/>");
|
|
});
|
|
}
|
|
}// function renderPerformanceSamples
|
|
|
|
profileUtils.formatTitle = function(title) {
|
|
return title && title.length > 30 ? title.substring(0, 30) + "..." : title;
|
|
}
|
|
|
|
profileUtils.renderOnlinePresence = function(player, $root, isOwner) {
|
|
var $noOnlinePresence = $root.find('#no-online-presence');
|
|
var $userWebsite = $root.find('#user-website');
|
|
var $soundCloudPresence = $root.find('#soundcloud-presence');
|
|
var $reverbNationPresence = $root.find('#reverbnation-presence');
|
|
var $bandCampPresence = $root.find('#bandcamp-presence');
|
|
var $fandalismPresence = $root.find('#fandalism-presence');
|
|
var $youTubePresence = $root.find('#youtube-presence');
|
|
var $facebookPresence = $root.find('#facebook-presence');
|
|
var $twitterPresence = $root.find('#twitter-presence');
|
|
var $btnAddSites = $root.find('.add-sites');
|
|
|
|
|
|
|
|
// online presences
|
|
var onlinePresences = player.online_presences;
|
|
if ((!onlinePresences || onlinePresences.length === 0) && !player.website) {
|
|
$noOnlinePresence.show()
|
|
$userWebsite.show()
|
|
$soundCloudPresence.show()
|
|
$reverbNationPresence.show()
|
|
$bandCampPresence.show()
|
|
$fandalismPresence.show()
|
|
$youTubePresence.show()
|
|
$facebookPresence.show()
|
|
$twitterPresence.show()
|
|
|
|
if (isOwner) {
|
|
$btnAddSites.show();
|
|
} else {
|
|
$btnAddSites.hide();
|
|
}
|
|
} else {
|
|
$btnAddSites.hide();
|
|
$noOnlinePresence.hide();
|
|
|
|
if (player.website) {
|
|
$userWebsite.find('a').attr('href', player.website);
|
|
}
|
|
|
|
var soundCloudPresences = profileUtils.soundCloudPresences(onlinePresences);
|
|
if (soundCloudPresences && soundCloudPresences.length > 0) {
|
|
$soundCloudPresence.find('a').attr('href', 'http://www.soundcloud.com/' + soundCloudPresences[0].username);
|
|
$soundCloudPresence.show();
|
|
} else {
|
|
$soundCloudPresence.hide();
|
|
}
|
|
|
|
var reverbNationPresences = profileUtils.reverbNationPresences(onlinePresences);
|
|
if (reverbNationPresences && reverbNationPresences.length > 0) {
|
|
$reverbNationPresence.find('a').attr('href', 'http://www.reverbnation.com/' + reverbNationPresences[0].username);
|
|
$reverbNationPresence.show();
|
|
} else {
|
|
$reverbNationPresence.hide();
|
|
}
|
|
|
|
var bandCampPresences = profileUtils.bandCampPresences(onlinePresences);
|
|
if (bandCampPresences && bandCampPresences.length > 0) {
|
|
$bandCampPresence.find('a').attr('href', 'http://' + bandCampPresences[0].username + '.bandcamp.com/');
|
|
$bandCampPresence.show();
|
|
} else {
|
|
$bandCampPresence.hide();
|
|
}
|
|
|
|
var fandalismPresences = profileUtils.fandalismPresences(onlinePresences);
|
|
if (fandalismPresences && fandalismPresences.length > 0) {
|
|
$fandalismPresence.find('a').attr('href', 'http://www.fandalism.com/' + fandalismPresences[0].username);
|
|
$fandalismPresence.show();
|
|
} else {
|
|
$fandalismPresence.hide();
|
|
}
|
|
|
|
var youTubePresences = profileUtils.youTubePresences(onlinePresences);
|
|
if (youTubePresences && youTubePresences.length > 0) {
|
|
$youTubePresence.find('a').attr('href', 'http://www.youtube.com/' + youTubePresences[0].username);
|
|
$youTubePresence.show();
|
|
} else {
|
|
$youTubePresence.hide();
|
|
}
|
|
|
|
var facebookPresences = profileUtils.facebookPresences(onlinePresences);
|
|
if (facebookPresences && facebookPresences.length > 0) {
|
|
$facebookPresence.find('a').attr('href', 'http://www.facebook.com/' + facebookPresences[0].username);
|
|
$facebookPresence.show();
|
|
} else {
|
|
$facebookPresence.hide();
|
|
}
|
|
|
|
var twitterPresences = profileUtils.twitterPresences(onlinePresences);
|
|
if (twitterPresences && twitterPresences.length > 0) {
|
|
$twitterPresence.find('a').attr('href', 'http://www.twitter.com/' + twitterPresences[0].username);
|
|
$twitterPresence.show();
|
|
} else {
|
|
$twitterPresence.hide();
|
|
}
|
|
}
|
|
}// function renderOnlinePresence
|
|
})(window, jQuery); |