241 lines
6.2 KiB
JavaScript
241 lines
6.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 SAMPLE_TYPES = {
|
|
JAMKAZAM: {description: "jamkazam"},
|
|
SOUNDCLOUD: {description: "soundcloud"},
|
|
YOUTUBE: {description: "youtube"}
|
|
};
|
|
|
|
var 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 = {
|
|
"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;
|
|
}
|
|
|
|
// 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 === SAMPLE_TYPES.JAMKAZAM.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.soundCloudSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === SAMPLE_TYPES.SOUNDCLOUD.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.youTubeSamples = function(samples) {
|
|
var matches = $.grep(samples, function(s) {
|
|
return s.service_type === SAMPLE_TYPES.YOUTUBE.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.soundCloudPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.SOUNDCLOUD.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.reverbNationPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.REVERBNATION.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.bandCampPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.BANDCAMP.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.fandalismPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.FANDALISM.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.youTubePresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.YOUTUBE.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.facebookPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.FACEBOOK.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
profileUtils.twitterPresences = function(presences) {
|
|
var matches = $.grep(presences, function(p) {
|
|
return p.service_type === ONLINE_PRESENCE_TYPES.TWITTER.description;
|
|
});
|
|
|
|
return matches;
|
|
}
|
|
|
|
})(window, jQuery); |