173 lines
4.2 KiB
JavaScript
173 lines
4.2 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_session';
|
|
var FREE_SESSION_GENRE_TYPE = 'free_session';
|
|
var COWRITING_GENRE_TYPE = 'cowriting';
|
|
|
|
// performance samples
|
|
var JAMKAZAM = 'jamkazam';
|
|
var SOUNDCLOUD = 'soundcloud';
|
|
var YOUTUBE = 'youtube';
|
|
|
|
var USER_TYPE = 'JamRuby::User';
|
|
|
|
profileUtils.skillLevelMap = {
|
|
"1": "Amateur",
|
|
"2": "Professional"
|
|
};
|
|
|
|
profileUtils.gigMap = {
|
|
"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.length > 0 ? list : 'None specified';
|
|
}
|
|
|
|
// 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 = $.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 = $.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 = $.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 = $.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 = $.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 === JAMKAZAM;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.soundCloudSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === SOUNDCLOUD;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.youTubeSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === YOUTUBE;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
})(window, jQuery); |