From c0dcbcce75ded2b206c0ba4d6028804ec90b5afb Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Tue, 17 Mar 2015 03:08:40 -0400 Subject: [PATCH] VRFS-2701 edit current interests working --- .../javascripts/accounts_profile_interests.js | 125 +++++++++++++++--- web/app/assets/javascripts/profile_utils.js | 45 ++++--- .../client/accountProfileExperience.css.scss | 2 +- .../client/accountProfileInterests.css.scss | 2 +- .../_account_profile_interests.html.erb | 47 +++---- web/app/views/dialogs/_dialogs.html.haml | 3 +- 6 files changed, 164 insertions(+), 60 deletions(-) diff --git a/web/app/assets/javascripts/accounts_profile_interests.js b/web/app/assets/javascripts/accounts_profile_interests.js index 7252eacb7..35f2ba1ee 100644 --- a/web/app/assets/javascripts/accounts_profile_interests.js +++ b/web/app/assets/javascripts/accounts_profile_interests.js @@ -9,7 +9,6 @@ var EVENTS = context.JK.EVENTS; var api = context.JK.Rest(); var ui = new context.JK.UIHelper(JK.app); - var userId; var user = {}; var profileUtils = context.JK.ProfileUtils; var masterGenreList = []; @@ -23,37 +22,51 @@ var GENRE_LIST_SELECTOR = '.genre-list'; // virtual bands + var $virtualBandYes = $screen.find('#virtual-band-yes'); + var $virtualBandNo = $screen.find('#virtual-band-no'); var $virtualBandGenres = $screen.find('#virtual-band-genres'); var $btnVirtualBandGenreSelect = $virtualBandGenres.find(SELECT_GENRE_SELECTOR); var $virtualBandGenreList = $virtualBandGenres.find(GENRE_LIST_SELECTOR); + var $virtualBandCommitment = $screen.find('#virtual-band-commitment'); // traditional bands + var $traditionalBandYes = $screen.find('#traditional-band-yes'); + var $traditionalBandNo = $screen.find('#traditional-band-no'); var $traditionalBandGenres = $screen.find('#traditional-band-genres'); var $btnTraditionalBandGenreSelect = $traditionalBandGenres.find(SELECT_GENRE_SELECTOR); var $traditionalBandGenreList = $traditionalBandGenres.find(GENRE_LIST_SELECTOR); + var $traditionalBandCommitment = $screen.find('#traditional-band-commitment'); + var $traditionalTouringOption = $screen.find('#traditional-band-touring'); // paid sessions + var $paidSessionsYes = $screen.find('#paid-sessions-yes'); + var $paidSessionsNo = $screen.find('#paid-sessions-no'); var $paidSessionsGenres = $screen.find('#paid-sessions-genres'); var $btnPaidSessionsGenreSelect = $paidSessionsGenres.find(SELECT_GENRE_SELECTOR); var $paidSessionsGenreList = $paidSessionsGenres.find(GENRE_LIST_SELECTOR); + var $hourlyRate = $screen.find('#hourly-rate'); + var $dailyRate = $screen.find('#daily-rate'); // free sessions + var $freeSessionsYes = $screen.find('#free-sessions-yes'); + var $freeSessionsNo = $screen.find('#free-sessions-no'); var $freeSessionsGenres = $screen.find('#free-sessions-genres'); var $btnFreeSessionsGenreSelect = $freeSessionsGenres.find(SELECT_GENRE_SELECTOR); var $freeSessionsGenreList = $freeSessionsGenres.find(GENRE_LIST_SELECTOR); // cowriting + var $cowritingYes = $screen.find('#cowriting-yes'); + var $cowritingNo = $screen.find('#cowriting-no'); var $cowritingGenres = $screen.find('#cowriting-genres'); var $btnCowritingGenreSelect = $cowritingGenres.find(SELECT_GENRE_SELECTOR); var $cowritingGenreList = $cowritingGenres.find(GENRE_LIST_SELECTOR); + var $cowritingPurpose = $screen.find('#cowriting-purpose'); - var $scroller = $screen.find('#account-profile-content-scroller'); - var $btnCancel = $scroller.find('#account-edit-profile-cancel'); - var $btnBack = $scroller.find('#account-edit-profile-back'); - var $btnSubmit = $scroller.find('#account-edit-profile-submit'); + var $btnCancel = $screen.find('#account-edit-profile-cancel'); + var $btnBack = $screen.find('#account-edit-profile-back'); + var $btnSubmit = $screen.find('#account-edit-profile-submit'); function beforeShow(data) { - userId = data.id; } function afterShow(data) { @@ -61,14 +74,74 @@ } function resetForm() { - $scroller.find('form .error-text').remove(); - $scroller.find('form .error').removeClass("error"); + $screen.find('form .error-text').remove(); + $screen.find('form .error').removeClass("error"); } function populateAccountProfile(userDetail) { + // Column 1 - options + if (userDetail) { - context.JK.dropdown($('select', $scroller)); + if (userDetail.virtual_band) { + $virtualBandYes.iCheck('check').attr('checked', 'checked'); + } + else { + $virtualBandNo.iCheck('check').attr('checked', 'checked'); + } + + if (userDetail.traditional_band) { + $traditionalBandYes.iCheck('check').attr('checked', 'checked'); + } + else { + $traditionalBandNo.iCheck('check').attr('checked', 'checked'); + } + + if (userDetail.paid_sessions) { + $paidSessionsYes.iCheck('check').attr('checked', 'checked'); + } + else { + $paidSessionsNo.iCheck('check').attr('checked', 'checked'); + } + + if (userDetail.free_sessions) { + $freeSessionsYes.iCheck('check').attr('checked', 'checked'); + } + else { + $freeSessionsNo.iCheck('check').attr('checked', 'checked'); + } + + if (userDetail.cowriting) { + $cowritingYes.iCheck('check').attr('checked', 'checked'); + } + else { + $cowritingNo.iCheck('check').attr('checked', 'checked'); + } + } + + // Column 2 - genres + var genres = profileUtils.virtualBandGenreList(userDetail.genres); + $virtualBandGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED); + + genres = profileUtils.traditionalBandGenreList(userDetail.genres); + $traditionalBandGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED); + + genres = profileUtils.paidSessionGenreList(userDetail.genres); + $paidSessionsGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED); + + genres = profileUtils.freeSessionGenreList(userDetail.genres); + $freeSessionsGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED); + + genres = profileUtils.cowritingGenreList(userDetail.genres); + $cowritingGenreList.html(genres && genres.length > 0 ? genres : NONE_SPECIFIED); + + // Column 3 - misc (play commitment, rates, cowriting purpose) + $virtualBandCommitment.val(userDetail.virtual_band_commitment); + $traditionalBandCommitment.val(userDetail.traditional_band_commitment); + $traditionalTouringOption.val(userDetail.traditional_band_touring ? '1' : '0'); + $hourlyRate.val(userDetail.paid_sessions_hourly_rate); + $dailyRate.val(userDetail.paid_sessions_daily_rate); + $cowritingPurpose.val(userDetail.cowriting_purpose); } function bindGenreSelector($btnSelect, $genreList) { @@ -97,16 +170,15 @@ $btnCancel.on('click', function(evt) { evt.stopPropagation(); navigateTo('/client#/account'); return false; } ); $btnBack.on('click', function(evt) { evt.stopPropagation(); navigateTo('/client#/account/profile/experience'); return false; } ); $btnSubmit.on('click', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } ); + + context.JK.dropdown($('select', $screen)); } function renderInterests() { $.when(api.getUserProfile()) - .done(function(userDetailResponse) { - var userDetail = userDetailResponse[0]; + .done(function(userDetail) { populateAccountProfile(userDetail); }); - - context.JK.dropdown($('select')); } function navigateTo(targetLocation) { @@ -117,11 +189,26 @@ resetForm(); api.updateUser({ - instruments: instruments, - genres: genres, - skill_level: $scroller.find('select[name=skill_level]').val(), - concert_count: $scroller.find('select[name=concert_count]').val(), - studio_session_count: $scroller.find('select[name=studio_session_count]').val() + 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_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_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_sessions_hourly_rate: $hourlyRate.val(), + paid_sessions_daily_rate: $dailyRate.val(), + + free_sessions: $screen.find('input[name=free_sessions]:checked').val(), + free_session_genre: $freeSessionsGenreList.html() === NONE_SPECIFIED ? [] : $freeSessionsGenreList.html().split(GENRE_LIST_DELIMITER), + + cowriting: $screen.find('input[name=cowriting]:checked').val(), + cowriting_genres: $cowritingGenreList.html() === NONE_SPECIFIED ? [] : $cowritingGenreList.html().split(GENRE_LIST_DELIMITER), + cowriting_purpose: $cowritingPurpose.val() }) .done(postUpdateProfileSuccess) .fail(postUpdateProfileFailure); @@ -154,7 +241,7 @@ events(); - $screen.iCheck({ + $screen.find('.interest-options').iCheck({ checkboxClass: 'icheckbox_minimal', radioClass: 'iradio_minimal', inheritClass: true diff --git a/web/app/assets/javascripts/profile_utils.js b/web/app/assets/javascripts/profile_utils.js index 2c9129dc3..126e60be8 100644 --- a/web/app/assets/javascripts/profile_utils.js +++ b/web/app/assets/javascripts/profile_utils.js @@ -90,9 +90,12 @@ // 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; - }); + var matches = []; + if (genres) { + matches = $.grep(genres, function(g) { + return g.player_type === USER_TYPE && g.genre_type === VIRTUAL_BAND_GENRE_TYPE; + }); + } return matches; } @@ -104,9 +107,12 @@ // 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; - }); + var matches = []; + if (genres) { + matches = $.grep(genres, function(g) { + return g.player_type === USER_TYPE && g.genre_type === TRADITIONAL_BAND_GENRE_TYPE; + }); + } return matches; } @@ -118,9 +124,12 @@ // 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; - }); + var matches = []; + if (genres) { + matches = $.grep(genres, function(g) { + return g.player_type === USER_TYPE && g.genre_type === PAID_SESSION_GENRE_TYPE; + }); + } return matches; } @@ -132,9 +141,12 @@ // 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; - }); + var matches = []; + if (genres) { + matches = $.grep(genres, function(g) { + return g.player_type === USER_TYPE && g.genre_type === FREE_SESSION_GENRE_TYPE; + }); + } return matches; } @@ -146,9 +158,12 @@ // cowriting genres profileUtils.cowritingGenres = function(genres) { - var matches = $.grep(genres, function(g) { - return g.player_type === USER_TYPE && g.genre_type === COWRITING_GENRE_TYPE; - }); + var matches = []; + if (genres) { + matches = $.grep(genres, function(g) { + return g.player_type === USER_TYPE && g.genre_type === COWRITING_GENRE_TYPE; + }); + } return matches; } diff --git a/web/app/assets/stylesheets/client/accountProfileExperience.css.scss b/web/app/assets/stylesheets/client/accountProfileExperience.css.scss index 1f21ad04a..a5d9171c9 100644 --- a/web/app/assets/stylesheets/client/accountProfileExperience.css.scss +++ b/web/app/assets/stylesheets/client/accountProfileExperience.css.scss @@ -1,4 +1,4 @@ -@import "client/common.css.scss"; +@import "common.css.scss"; #account-profile-experience { diff --git a/web/app/assets/stylesheets/client/accountProfileInterests.css.scss b/web/app/assets/stylesheets/client/accountProfileInterests.css.scss index 0ae312516..230a1f4b0 100644 --- a/web/app/assets/stylesheets/client/accountProfileInterests.css.scss +++ b/web/app/assets/stylesheets/client/accountProfileInterests.css.scss @@ -1,4 +1,4 @@ -@import "client/common.css.scss"; +@import "common.css.scss"; #account-profile-interests { diff --git a/web/app/views/clients/_account_profile_interests.html.erb b/web/app/views/clients/_account_profile_interests.html.erb index 17026c863..a6a221543 100644 --- a/web/app/views/clients/_account_profile_interests.html.erb +++ b/web/app/views/clients/_account_profile_interests.html.erb @@ -20,7 +20,7 @@
- +
@@ -28,7 +28,7 @@
- +
@@ -38,12 +38,12 @@
- None specified +
- @@ -59,7 +59,7 @@
- +
@@ -67,7 +67,7 @@
- +
@@ -77,12 +77,12 @@
- None specified +
- @@ -92,7 +92,7 @@
- @@ -106,7 +106,7 @@
- +
@@ -114,7 +114,7 @@
- +
@@ -124,17 +124,17 @@
- +
- +
@@ -145,7 +145,7 @@
- +
@@ -153,7 +153,7 @@
- +
@@ -163,7 +163,7 @@
- None specified +
@@ -174,7 +174,7 @@
- +
@@ -182,7 +182,7 @@
- +
@@ -192,14 +192,14 @@
- None specified +
- +
@@ -219,4 +219,5 @@
-
\ No newline at end of file +
+ diff --git a/web/app/views/dialogs/_dialogs.html.haml b/web/app/views/dialogs/_dialogs.html.haml index fc22bff4b..809181660 100644 --- a/web/app/views/dialogs/_dialogs.html.haml +++ b/web/app/views/dialogs/_dialogs.html.haml @@ -33,4 +33,5 @@ = render 'dialogs/allSyncsDialog' = render 'dialogs/adjustGearSpeedDialog' = render 'dialogs/openJamTrackDialog' -= render 'dialogs/openBackingTrackDialog' \ No newline at end of file += render 'dialogs/openBackingTrackDialog' += render 'dialogs/genreSelectorDialog' \ No newline at end of file