diff --git a/web/app/assets/javascripts/accounts_profile_interests.js b/web/app/assets/javascripts/accounts_profile_interests.js index 84b205777..48674efd6 100644 --- a/web/app/assets/javascripts/accounts_profile_interests.js +++ b/web/app/assets/javascripts/accounts_profile_interests.js @@ -121,19 +121,24 @@ // Column 2 - genres var genres = profileUtils.virtualBandGenreList(userDetail.genres) - $virtualBandGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) + var genreIds = profileUtils.getGenreIds(profileUtils.virtualBandGenres(userDetail.genres)); + $virtualBandGenreList.data('genres', genreIds).html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) genres = profileUtils.traditionalBandGenreList(userDetail.genres) - $traditionalBandGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) + var genreIds = profileUtils.getGenreIds(profileUtils.traditionalBandGenres(userDetail.genres)); + $traditionalBandGenreList.data('genres', genreIds).html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) genres = profileUtils.paidSessionGenreList(userDetail.genres) - $paidSessionsGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) + var genreIds = profileUtils.getGenreIds(profileUtils.paidSessionGenres(userDetail.genres)); + $paidSessionsGenreList.data('genres', genreIds).html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) genres = profileUtils.freeSessionGenreList(userDetail.genres) - $freeSessionsGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) + var genreIds = profileUtils.getGenreIds(profileUtils.freeSessionGenres(userDetail.genres)); + $freeSessionsGenreList.data('genres', genreIds).html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) genres = profileUtils.cowritingGenreList(userDetail.genres) - $cowritingGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) + var genreIds = profileUtils.getGenreIds(profileUtils.cowritingGenres(userDetail.genres)); + $cowritingGenreList.data('genres', genreIds).html(genres && genres.length > 0 ? genres : NONE_SPECIFIED) // Column 3 - misc (play commitment, rates, cowriting purpose) $virtualBandCommitment.val(userDetail.virtual_band_commitment) @@ -165,7 +170,7 @@ } ui.launchGenreSelectorDialog(type, genres, function(selectedGenres) { - $genreList.html(selectedGenres && selectedGenres.length > 0 ? selectedGenres.join(GENRE_LIST_DELIMITER) : NONE_SPECIFIED) + $genreList.data('genres', selectedGenres).html(selectedGenres && selectedGenres.length > 0 ? selectedGenres.join(GENRE_LIST_DELIMITER) : NONE_SPECIFIED) }) return false @@ -278,24 +283,24 @@ api.updateUser({ virtual_band: $screen.find('input[name=virtual_band]:checked').val(), - virtual_band_genres: $virtualBandGenreList.html() === NONE_SPECIFIED ? [] : $virtualBandGenreList.html().split(GENRE_LIST_DELIMITER), + virtual_band_genres: $virtualBandGenreList.data('genres'), virtual_band_commitment: $virtualBandCommitment.val(), traditional_band: $screen.find('input[name=traditional_band]:checked').val(), - traditional_band_genres: $traditionalBandGenreList.html() === NONE_SPECIFIED ? [] : $traditionalBandGenreList.html().split(GENRE_LIST_DELIMITER), + traditional_band_genres: $traditionalBandGenreList.data('genres'), traditional_band_commitment: $traditionalBandCommitment.val(), traditional_band_touring: $traditionalTouringOption.val(), paid_sessions: $screen.find('input[name=paid_sessions]:checked').val(), - paid_session_genres: $paidSessionsGenreList.html() === NONE_SPECIFIED ? [] : $paidSessionsGenreList.html().split(GENRE_LIST_DELIMITER), + paid_session_genres: $paidSessionsGenreList.data('genres'), paid_sessions_hourly_rate: profileUtils.normalizeMoneyForSubmit($hourlyRate.val()), paid_sessions_daily_rate: profileUtils.normalizeMoneyForSubmit($dailyRate.val()), free_sessions: $screen.find('input[name=free_sessions]:checked').val(), - free_session_genres: $freeSessionsGenreList.html() === NONE_SPECIFIED ? [] : $freeSessionsGenreList.html().split(GENRE_LIST_DELIMITER), + free_session_genres: $freeSessionsGenreList.data('genres'), cowriting: $screen.find('input[name=cowriting]:checked').val(), - cowriting_genres: $cowritingGenreList.html() === NONE_SPECIFIED ? [] : $cowritingGenreList.html().split(GENRE_LIST_DELIMITER), + cowriting_genres: $cowritingGenreList.data('genres'), cowriting_purpose: $cowritingPurpose.val() }) .done(postUpdateProfileSuccess) diff --git a/web/app/assets/javascripts/dialog/genreSelectorDialog.js b/web/app/assets/javascripts/dialog/genreSelectorDialog.js index 3a9bf4c4f..c119cfb06 100644 --- a/web/app/assets/javascripts/dialog/genreSelectorDialog.js +++ b/web/app/assets/javascripts/dialog/genreSelectorDialog.js @@ -28,7 +28,14 @@ checked = 'checked'; } - $genres.append('' + val.description); + var $input = $('') + $input.val(val.id) + if(checked == 'checked') { + $input.attr('checked', 'checked') + } + + $genres.append($input); + $genres.append(val.description); $genres.append(''); }); } diff --git a/web/app/assets/javascripts/profile_utils.js b/web/app/assets/javascripts/profile_utils.js index c25035936..8629a738c 100644 --- a/web/app/assets/javascripts/profile_utils.js +++ b/web/app/assets/javascripts/profile_utils.js @@ -97,6 +97,17 @@ return list; } + + profileUtils.getGenreIds = function(genres) { + var list = [] + + for (var i=0; i < genres.length; i++) { + list.push(genres[i].genre_id); + } + + return list; + } + // the server stores money in cents; display it as such profileUtils.normalizeMoneyForDisplay = function(serverValue) { if (!serverValue || serverValue==="") {