diff --git a/web/app/assets/javascripts/accounts_profile.js b/web/app/assets/javascripts/accounts_profile.js
index 79b8389fe..289e1236f 100644
--- a/web/app/assets/javascripts/accounts_profile.js
+++ b/web/app/assets/javascripts/accounts_profile.js
@@ -1,104 +1,104 @@
(function(context,$) {
- "use strict";
+ "use strict";
- context.JK = context.JK || {};
- context.JK.AccountProfileScreen = function(app) {
- var $document = $(document);
- var logger = context.JK.logger;
- var EVENTS = context.JK.EVENTS;
- var api = context.JK.Rest();
- var userId;
- var user = {};
- var selectLocation = null;
- var recentUserDetail = null;
- var loadingCitiesData = false;
- var loadingRegionsData = false;
- var loadingCountriesData = false;
- var nilOptionStr = '';
- var nilOptionText = 'n/a';
+ context.JK = context.JK || {};
+ context.JK.AccountProfileScreen = function(app) {
+ var $document = $(document);
+ var logger = context.JK.logger;
+ var EVENTS = context.JK.EVENTS;
+ var api = context.JK.Rest();
+ var userId;
+ var user = {};
+ var selectLocation = null;
+ var recentUserDetail = null;
+ var loadingCitiesData = false;
+ var loadingRegionsData = false;
+ var loadingCountriesData = false;
+ var nilOptionStr = '';
+ var nilOptionText = 'n/a';
- function beforeShow(data) {
- userId = data.id;
- }
-
- function afterShow(data) {
- resetForm();
- renderAccountProfile();
- }
-
- function resetForm() {
- // remove all display errors
- $('#account-profile-content-scroller form .error-text').remove()
- $('#account-profile-content-scroller form .error').removeClass("error")
- }
-
- function populateAccountProfile(userDetail, instruments) {
- var template = context.JK.fillTemplate($('#template-account-profile').html(), {
- country: userDetail.country,
- region: userDetail.state,
- city: userDetail.city,
- first_name: userDetail.first_name,
- last_name: userDetail.last_name,
- photoUrl: context.JK.resolveAvatarUrl(userDetail.photo_url),
- user_instruments: userDetail.instruments,
- birth_date : userDetail.birth_date,
- gender: userDetail.gender,
- subscribe_email: userDetail.subscribe_email ? "checked=checked" : ""
- });
-
- var content_root = $('#account-profile-content-scroller')
- content_root.html(template);
-
- // now use javascript to fix up values too hard to do with templating
- // set gender
- $('select[name=gender]', content_root).val(userDetail.gender)
-
- // set birth_date
- if(userDetail.birth_date) {
- var birthDateFields = userDetail.birth_date.split('-')
- var birthDateYear = birthDateFields[0];
- var birthDateMonth = birthDateFields[1];
- var birthDateDay = birthDateFields[2];
-
- $('select#user_birth_date_1i', content_root).val(parseInt(birthDateYear));
- $('select#user_birth_date_2i', content_root).val(parseInt(birthDateMonth));
- $('select#user_birth_date_3i', content_root).val(parseInt(birthDateDay));
- }
-
- loadGenres(userDetail.genres);
-
- // update instruments
- $.each(instruments, function(index, instrument) {
- var template = context.JK.fillTemplate($('#account-profile-instrument').html(), {
- checked : isUserInstrument(instrument, userDetail.instruments) ? "checked=\"checked\"" :"",
- description : instrument.description,
- id : instrument.id
- })
- $('.instrument_selector', content_root).append(template)
- })
- // and fill in the proficiency for the instruments that the user can play
- if(userDetail.instruments) {
- $.each(userDetail.instruments, function(index, userInstrument) {
- $('tr[data-instrument-id="' + userInstrument.instrument_id + '"] select.proficiency_selector', content_root).val(userInstrument.proficiency_level)
- })
- }
-
- context.JK.dropdown($('select', content_root));
- }
-
- function isUserInstrument(instrument, userInstruments) {
- var isUserInstrument = false;
- if(!userInstruments) return false;
-
- $.each(userInstruments, function(index, userInstrument) {
- if(instrument.id == userInstrument.instrument_id) {
- isUserInstrument = true;
- return false;
- }
- })
- return isUserInstrument;
+ function beforeShow(data) {
+ userId = data.id;
+ }
+
+ function afterShow(data) {
+ resetForm();
+ renderAccountProfile();
+ }
+
+ function resetForm() {
+ // remove all display errors
+ $('#account-profile-content-scroller form .error-text').remove()
+ $('#account-profile-content-scroller form .error').removeClass("error")
+ }
+
+ function populateAccountProfile(userDetail, instruments) {
+ var template = context.JK.fillTemplate($('#template-account-profile').html(), {
+ country: userDetail.country,
+ region: userDetail.state,
+ city: userDetail.city,
+ first_name: userDetail.first_name,
+ last_name: userDetail.last_name,
+ photoUrl: context.JK.resolveAvatarUrl(userDetail.photo_url),
+ user_instruments: userDetail.instruments,
+ birth_date : userDetail.birth_date,
+ gender: userDetail.gender,
+ subscribe_email: userDetail.subscribe_email ? "checked=checked" : ""
+ });
+
+ var content_root = $('#account-profile-content-scroller')
+ content_root.html(template);
+
+ // now use javascript to fix up values too hard to do with templating
+ // set gender
+ $('select[name=gender]', content_root).val(userDetail.gender)
+
+ // set birth_date
+ if(userDetail.birth_date) {
+ var birthDateFields = userDetail.birth_date.split('-')
+ var birthDateYear = birthDateFields[0];
+ var birthDateMonth = birthDateFields[1];
+ var birthDateDay = birthDateFields[2];
+
+ $('select#user_birth_date_1i', content_root).val(parseInt(birthDateYear));
+ $('select#user_birth_date_2i', content_root).val(parseInt(birthDateMonth));
+ $('select#user_birth_date_3i', content_root).val(parseInt(birthDateDay));
+ }
+
+ loadGenres(userDetail.genres);
+
+ // update instruments
+ $.each(instruments, function(index, instrument) {
+ var template = context.JK.fillTemplate($('#account-profile-instrument').html(), {
+ checked : isUserInstrument(instrument, userDetail.instruments) ? "checked=\"checked\"" :"",
+ description : instrument.description,
+ id : instrument.id
+ })
+ $('.instrument_selector', content_root).append(template);
+ })
+ // and fill in the proficiency for the instruments that the user can play
+ if(userDetail.instruments) {
+ $.each(userDetail.instruments, function(index, userInstrument) {
+ $('tr[data-instrument-id="' + userInstrument.instrument_id + '"] select.proficiency_selector', content_root).val(userInstrument.proficiency_level)
+ });
+ }
+
+ context.JK.dropdown($('select', content_root));
+ }
+
+ function isUserInstrument(instrument, userInstruments) {
+ var isUserInstrument = false;
+ if(!userInstruments) return false;
+
+ $.each(userInstruments, function(index, userInstrument) {
+ if (instrument.id == userInstrument.instrument_id) {
+ isUserInstrument = true;
+ return false;
}
+ });
+ return isUserInstrument;
+ }
function loadGenres(selectedGenres) {
$("#user-genres").empty();
@@ -125,6 +125,7 @@
});
});
}
+
function resetGenres() {
$('input[type=checkbox]:checked', '#user-genres').each(function (i) {
$(this).removeAttr("checked");
@@ -141,455 +142,448 @@
return genres;
}
- function populateAccountProfileLocation(userDetail, regions, cities) {
- populateRegions(regions, userDetail.state);
- populateCities(cities, userDetail.city);
+ function populateAccountProfileLocation(userDetail, regions, cities) {
+ populateRegions(regions, userDetail.state);
+ populateCities(cities, userDetail.city);
+ }
+
+ function populateCountries(countries, userCountry) {
+
+ // countries has the format ["US", ...]
+ var foundCountry = false;
+ var countrySelect = getCountryElement();
+ countrySelect.children().remove();
+
+ var nilOption = $(nilOptionStr);
+ nilOption.text(nilOptionText);
+ countrySelect.append(nilOption);
+
+ $.each(countries, function(index, country) {
+ if(!country) return;
+
+ var option = $(nilOptionStr);
+ option.text(country);
+ option.attr("value", country);
+
+ if(country == userCountry) {
+ foundCountry = true;
}
+ countrySelect.append(option);
+ });
- function populateCountries(countries, userCountry) {
+ if(!foundCountry) {
+ // in this case, the user has a country that is not in the database
+ // this can happen in a development/test scenario, but let's assume it can
+ // happen in production too.
+ var option = $(nilOptionStr);
+ option.text(userCountry);
+ option.attr("value", userCountry);
+ countrySelect.append(option);
+ }
- // countries has the format ["US", ...]
+ countrySelect.val(userCountry);
+ countrySelect.attr("disabled", null)
- var foundCountry = false;
- var countrySelect = getCountryElement();
- countrySelect.children().remove();
+ context.JK.dropdown(countrySelect);
+ }
- var nilOption = $(nilOptionStr);
- nilOption.text(nilOptionText);
- countrySelect.append(nilOption);
- $.each(countries, function(index, country) {
- if(!country) return;
+ function populateCountriesx(countriesx, userCountry) {
- var option = $(nilOptionStr);
- option.text(country);
- option.attr("value", country);
+ // countriesx has the format [{countrycode: "US", countryname: "United States"}, ...]
- if(country == userCountry) {
- foundCountry = true;
- }
+ var foundCountry = false;
+ var countrySelect = getCountryElement();
+ countrySelect.children().remove();
- countrySelect.append(option);
- });
+ var nilOption = $(nilOptionStr);
+ nilOption.text(nilOptionText);
+ countrySelect.append(nilOption);
- if(!foundCountry) {
- // in this case, the user has a country that is not in the database
- // this can happen in a development/test scenario, but let's assume it can
- // happen in production too.
- var option = $(nilOptionStr);
- option.text(userCountry);
- option.attr("value", userCountry);
- countrySelect.append(option);
- }
+ $.each(countriesx, function(index, countryx) {
+ if (!countryx.countrycode) return;
- countrySelect.val(userCountry);
- countrySelect.attr("disabled", null)
+ var option = $(nilOptionStr);
+ option.text(countryx.countryname);
+ option.attr("value", countryx.countrycode);
- context.JK.dropdown(countrySelect);
+ if(countryx.countrycode == userCountry) {
+ foundCountry = true;
}
+ countrySelect.append(option);
+ });
- function populateCountriesx(countriesx, userCountry) {
+ if(!foundCountry) {
+ // in this case, the user has a country that is not in the database
+ // this can happen in a development/test scenario, but let's assume it can
+ // happen in production too.
+ var option = $(nilOptionStr);
+ option.text(userCountry);
+ option.attr("value", userCountry);
+ countrySelect.append(option);
+ }
- // countriesx has the format [{countrycode: "US", countryname: "United States"}, ...]
+ countrySelect.val(userCountry);
+ countrySelect.attr("disabled", null);
- var foundCountry = false;
- var countrySelect = getCountryElement();
- countrySelect.children().remove();
+ context.JK.dropdown(countrySelect);
+ }
- var nilOption = $(nilOptionStr);
- nilOption.text(nilOptionText);
- countrySelect.append(nilOption);
+ function populateRegions(regions, userRegion) {
+ var regionSelect = getRegionElement()
+ regionSelect.children().remove()
- $.each(countriesx, function(index, countryx) {
- if(!countryx.countrycode) return;
+ var nilOption = $(nilOptionStr);
+ nilOption.text(nilOptionText);
+ regionSelect.append(nilOption);
- var option = $(nilOptionStr);
- option.text(countryx.countryname);
- option.attr("value", countryx.countrycode);
+ $.each(regions, function(index, region) {
+ if(!region) return;
- if(countryx.countrycode == userCountry) {
- foundCountry = true;
- }
+ var option = $(nilOptionStr);
+ option.text(region['name']);
+ option.attr("value", region['region']);
- countrySelect.append(option);
- });
+ regionSelect.append(option);
+ })
- if(!foundCountry) {
- // in this case, the user has a country that is not in the database
- // this can happen in a development/test scenario, but let's assume it can
- // happen in production too.
- var option = $(nilOptionStr);
- option.text(userCountry);
- option.attr("value", userCountry);
- countrySelect.append(option);
- }
+ regionSelect.val(userRegion)
+ regionSelect.attr("disabled", null)
- countrySelect.val(userCountry);
- countrySelect.attr("disabled", null)
+ context.JK.dropdown(regionSelect);
+ }
- context.JK.dropdown(countrySelect);
+ function populateCities(cities, userCity) {
+ var citySelect = getCityElement();
+ citySelect.children().remove();
+
+ var nilOption = $(nilOptionStr);
+ nilOption.text(nilOptionText);
+ citySelect.append(nilOption);
+
+ $.each(cities, function(index, city) {
+ if(!city) return;
+
+ var option = $(nilOptionStr);
+ option.text(city);
+ option.attr("value", city);
+
+ citySelect.append(option);
+ });
+
+ citySelect.val(userCity);
+ citySelect.attr("disabled", null);
+
+ context.JK.dropdown(citySelect);
+ }
+
+ /****************** MAIN PORTION OF SCREEN *****************/
+ // events for main screen
+ function events() {
+ $('#account-profile-content-scroller').on('click', '#account-edit-profile-cancel', function(evt) { evt.stopPropagation(); navToAccount(); return false; } );
+ $('#account-profile-content-scroller').on('click', '#account-edit-profile-submit', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } );
+ $('#account-profile-content-scroller').on('submit', '#account-edit-email-form', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } );
+ $('#account-profile-content-scroller').on('click', '#account-change-avatar', function(evt) { evt.stopPropagation(); navToAvatar(); return false; } );
+ }
+
+ function renderAccountProfile() {
+ $.when(api.getUserDetail(), api.getInstruments())
+ .done(function(userDetailResponse, instrumentsResponse) {
+ var userDetail = userDetailResponse[0];
+ recentUserDetail = userDetail // store userDetail for later
+ // show page; which can be done quickly at this point
+ populateAccountProfile(userDetail,
+ instrumentsResponse[0]);
+
+ selectLocation = new context.JK.SelectLocation(getCountryElement(), getRegionElement(), getCityElement(), app);
+ selectLocation.load(userDetail.country, userDetail.state, userDetail.city)
+ });
+
+ context.JK.dropdown($('select'));
+ }
+
+ function navToAccount() {
+ resetForm();
+ window.location = '/client#/account';
+ }
+
+ function navToAvatar() {
+ resetForm();
+ window.location = '/client#/account/profile/avatar';
+ }
+
+ function handleUpdateProfile() {
+ resetForm();
+
+ var country = getCountryElement().val();
+ var region = getRegionElement().val();
+ var city = getCityElement().val();
+ var firstName = getFirstNameElement().val();
+ var lastName = getLastNameElement().val();
+ var gender = getGenderElement().val();
+ var subscribeEmail = getSubscribeEmail().is(':checked');
+ var birthDate = getBirthDate();
+ var instruments = getInstrumentsValue();
+ var genres = getSelectedGenres();
+
+ api.updateUser({
+ country: country,
+ state: region,
+ city: city,
+ first_name: firstName,
+ last_name: lastName,
+ gender: gender,
+ birth_date: birthDate,
+ instruments: instruments,
+ genres: genres,
+ subscribe_email: subscribeEmail
+ })
+ .done(postUpdateProfileSuccess)
+ .fail(postUpdateProfileFailure)
+ }
+
+ function postUpdateProfileSuccess(response) {
+ app.notify(
+ { title: "Profile Changed",
+ text: "You have updated your profile successfully."
+ },
+ null,
+ true);
+
+ $document.triggerHandler(EVENTS.USER_UPDATED, response);
+ }
+
+ function postUpdateProfileFailure(xhr, textStatus, errorMessage) {
+
+ var errors = JSON.parse(xhr.responseText)
+
+ if(xhr.status == 422) {
+ var first_name = context.JK.format_errors("first_name", errors);
+ var last_name = context.JK.format_errors("last_name", errors);
+ var country = context.JK.format_errors("country", errors);
+ var state = context.JK.format_errors("state", errors);
+ var city = context.JK.format_errors("city", errors);
+ var birth_date = context.JK.format_errors("birth_date", errors);
+ var gender = context.JK.format_errors("birth_date", errors);
+ var subscribeEmail = context.JK.format_errors("subscribe_email", errors);
+ var instruments = context.JK.format_errors("musician_instruments", errors)
+
+ if(first_name != null) {
+ getFirstNameElement().closest('div.field').addClass('error').end().after(first_name);
}
-
- function populateRegions(regions, userRegion) {
- var regionSelect = getRegionElement()
- regionSelect.children().remove()
-
- var nilOption = $(nilOptionStr);
- nilOption.text(nilOptionText);
- regionSelect.append(nilOption);
-
- $.each(regions, function(index, region) {
- if(!region) return;
-
- var option = $(nilOptionStr)
- option.text(region['name'])
- option.attr("value", region['region'])
-
- regionSelect.append(option)
- })
-
- regionSelect.val(userRegion)
- regionSelect.attr("disabled", null)
-
- context.JK.dropdown(regionSelect);
+ if(last_name != null) {
+ getLastNameElement().closest('div.field').addClass('error').end().after(last_name);
}
- function populateCities(cities, userCity) {
- var citySelect = getCityElement();
- citySelect.children().remove();
-
- var nilOption = $(nilOptionStr);
- nilOption.text(nilOptionText);
- citySelect.append(nilOption);
-
- $.each(cities, function(index, city) {
- if(!city) return;
-
- var option = $(nilOptionStr)
- option.text(city)
- option.attr("value", city)
-
- citySelect.append(option)
- })
-
- citySelect.val(userCity)
- citySelect.attr("disabled", null)
-
- context.JK.dropdown(citySelect);
+ if(country != null) {
+ getCountryElement().closest('div.field').addClass('error').end().after(country);
}
- /****************** MAIN PORTION OF SCREEN *****************/
- // events for main screen
- function events() {
- $('#account-profile-content-scroller').on('click', '#account-edit-profile-cancel', function(evt) { evt.stopPropagation(); navToAccount(); return false; } );
- $('#account-profile-content-scroller').on('click', '#account-edit-profile-submit', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } );
- $('#account-profile-content-scroller').on('submit', '#account-edit-email-form', function(evt) { evt.stopPropagation(); handleUpdateProfile(); return false; } );
- $('#account-profile-content-scroller').on('click', '#account-change-avatar', function(evt) { evt.stopPropagation(); navToAvatar(); return false; } );
- }
- function renderAccountProfile() {
-
- $.when( api.getUserDetail(),
- api.getInstruments())
- .done(function(userDetailResponse, instrumentsResponse) {
- var userDetail = userDetailResponse[0];
- recentUserDetail = userDetail // store userDetail for later
- // show page; which can be done quickly at this point
- populateAccountProfile(userDetail,
- instrumentsResponse[0]);
-
- selectLocation = new context.JK.SelectLocation(getCountryElement(), getRegionElement(), getCityElement(), app);
- selectLocation.load(userDetail.country, userDetail.state, userDetail.city)
- })
- context.JK.dropdown($('select'));
+ if(state != null) {
+ getRegionElement().closest('div.field').addClass('error').end().after(state);
}
- function navToAccount() {
- resetForm();
- window.location = '/client#/account';
+ if(city != null) {
+ getCityElement().closest('div.field').addClass('error').end().after(city);
}
- function navToAvatar() {
- resetForm();
- window.location = '/client#/account/profile/avatar';
+ if(birth_date != null) {
+ getYearElement().closest('div.field').addClass('error').end().after(birth_date);
}
- function handleUpdateProfile() {
-
- resetForm();
-
- var country = getCountryElement().val();
- var region = getRegionElement().val();
- var city = getCityElement().val();
- var firstName = getFirstNameElement().val();
- var lastName = getLastNameElement().val();
- var gender = getGenderElement().val();
- var subscribeEmail = getSubscribeEmail().is(':checked');
- var birthDate = getBirthDate();
- var instruments = getInstrumentsValue();
- var genres = getSelectedGenres();
-
- api.updateUser({
- country: country,
- state: region,
- city: city,
- first_name: firstName,
- last_name: lastName,
- gender: gender,
- birth_date: birthDate,
- instruments: instruments,
- genres: genres,
- subscribe_email: subscribeEmail
- })
- .done(postUpdateProfileSuccess)
- .fail(postUpdateProfileFailure)
+ if(subscribeEmail != null) {
+ getSubscribeEmail().closest('div.field').addClass('error').end().after(subscribeEmail);
}
- function postUpdateProfileSuccess(response) {
- app.notify(
- { title: "Profile Changed",
- text: "You have updated your profile successfully."
- },
- null,
- true);
-
- $document.triggerHandler(EVENTS.USER_UPDATED, response);
-
+ if(gender != null) {
+ getGenderElement().closest('div.field').addClass('error').end().after(gender);
}
- function postUpdateProfileFailure(xhr, textStatus, errorMessage) {
-
- var errors = JSON.parse(xhr.responseText)
-
- if(xhr.status == 422) {
-
- var first_name = context.JK.format_errors("first_name", errors);
- var last_name = context.JK.format_errors("last_name", errors);
- var country = context.JK.format_errors("country", errors);
- var state = context.JK.format_errors("state", errors);
- var city = context.JK.format_errors("city", errors);
- var birth_date = context.JK.format_errors("birth_date", errors);
- var gender = context.JK.format_errors("birth_date", errors);
- var subscribeEmail = context.JK.format_errors("subscribe_email", errors);
- var instruments = context.JK.format_errors("musician_instruments", errors)
-
- if(first_name != null) {
- getFirstNameElement().closest('div.field').addClass('error').end().after(first_name);
- }
-
- if(last_name != null) {
- getLastNameElement().closest('div.field').addClass('error').end().after(last_name);
- }
-
- if(country != null) {
- getCountryElement().closest('div.field').addClass('error').end().after(country);
- }
-
- if(state != null) {
- getRegionElement().closest('div.field').addClass('error').end().after(state);
- }
-
- if(city != null) {
- getCityElement().closest('div.field').addClass('error').end().after(city);
- }
-
- if(birth_date != null) {
- getYearElement().closest('div.field').addClass('error').end().after(birth_date);
- }
-
- if(subscribeEmail != null) {
- getSubscribeEmail().closest('div.field').addClass('error').end().after(subscribeEmail);
- }
-
- if(gender != null) {
- getGenderElement().closest('div.field').addClass('error').end().after(gender);
- }
-
- if(instruments != null) {
- getInstrumentsElement().closest('div.field').addClass('error').append(instruments);
- }
- }
- else {
- app.ajaxError(xhr, textStatus, errorMessage)
- }
+ if(instruments != null) {
+ getInstrumentsElement().closest('div.field').addClass('error').append(instruments);
}
+ }
+ else {
+ app.ajaxError(xhr, textStatus, errorMessage)
+ }
+ }
- function handleCountryChanged() {
- var selectedCountry = getCountryElement().val()
- var selectedRegion = getRegionElement().val()
- var cityElement = getCityElement();
+ function handleCountryChanged() {
+ var selectedCountry = getCountryElement().val()
+ var selectedRegion = getRegionElement().val()
+ var cityElement = getCityElement();
- updateRegionList(selectedCountry, getRegionElement());
- updateCityList(selectedCountry, null, cityElement);
- }
+ updateRegionList(selectedCountry, getRegionElement());
+ updateCityList(selectedCountry, null, cityElement);
+ }
- function updateRegionList(selectedCountry, regionElement) {
- // only update region
- if (selectedCountry) {
- // set city disabled while updating
- regionElement.attr('disabled', true);
- loadingRegionsData = true;
+ function updateRegionList(selectedCountry, regionElement) {
+ // only update region
+ if (selectedCountry) {
+ // set city disabled while updating
+ regionElement.attr('disabled', true);
+ loadingRegionsData = true;
- regionElement.children().remove()
- regionElement.append($(nilOptionStr).text('loading...'))
+ regionElement.children().remove()
+ regionElement.append($(nilOptionStr).text('loading...'))
- api.getRegions({ country: selectedCountry })
- .done(getRegionsDone)
- .error(function(err) {
- regionElement.children().remove()
- regionElement.append($(nilOptionStr).text(nilOptionText))
- })
- .always(function () {
- loadingRegionsData = false;
- })
- }
- else {
- regionElement.children().remove()
- regionElement.append($(nilOptionStr).text(nilOptionText))
- }
- }
+ api.getRegions({ country: selectedCountry })
+ .done(getRegionsDone)
+ .error(function(err) {
+ regionElement.children().remove()
+ regionElement.append($(nilOptionStr).text(nilOptionText))
+ })
+ .always(function () {
+ loadingRegionsData = false;
+ });
+ }
+ else {
+ regionElement.children().remove()
+ regionElement.append($(nilOptionStr).text(nilOptionText))
+ }
+ }
- function updateCityList(selectedCountry, selectedRegion, cityElement) {
- logger.debug("updating city list: selectedCountry %o, selectedRegion %o", selectedCountry, selectedRegion);
+ function updateCityList(selectedCountry, selectedRegion, cityElement) {
+ logger.debug("updating city list: selectedCountry %o, selectedRegion %o", selectedCountry, selectedRegion);
- // only update cities
- if (selectedCountry && selectedRegion) {
- // set city disabled while updating
- cityElement.attr('disabled', true);
- loadingCitiesData = true;
+ // only update cities
+ if (selectedCountry && selectedRegion) {
+ // set city disabled while updating
+ cityElement.attr('disabled', true);
+ loadingCitiesData = true;
- cityElement.children().remove()
- cityElement.append($(nilOptionStr).text('loading...'))
+ cityElement.children().remove();
+ cityElement.append($(nilOptionStr).text('loading...'));
- api.getCities({ country: selectedCountry, region: selectedRegion })
- .done(getCitiesDone)
- .error(function(err) {
- cityElement.children().remove()
- cityElement.append($(nilOptionStr).text(nilOptionText))
- })
- .always(function () {
- loadingCitiesData = false;
- })
- }
- else {
- cityElement.children().remove();
- cityElement.append($(nilOptionStr).text(nilOptionText));
- context.JK.dropdown(cityElement);
- }
- }
+ api.getCities({ country: selectedCountry, region: selectedRegion })
+ .done(getCitiesDone)
+ .error(function(err) {
+ cityElement.children().remove();
+ cityElement.append($(nilOptionStr).text(nilOptionText));
+ })
+ .always(function () {
+ loadingCitiesData = false;
+ });
+ }
+ else {
+ cityElement.children().remove();
+ cityElement.append($(nilOptionStr).text(nilOptionText));
+ context.JK.dropdown(cityElement);
+ }
+ }
- function handleRegionChanged() {
- var selectedCountry = getCountryElement().val()
- var selectedRegion = getRegionElement().val()
- var cityElement = getCityElement();
+ function handleRegionChanged() {
+ var selectedCountry = getCountryElement().val()
+ var selectedRegion = getRegionElement().val()
+ var cityElement = getCityElement();
- updateCityList(selectedCountry, selectedRegion, cityElement);
- }
+ updateCityList(selectedCountry, selectedRegion, cityElement);
+ }
- function getCitiesDone(data) {
- populateCities(data['cities'], recentUserDetail.city);
- }
+ function getCitiesDone(data) {
+ populateCities(data['cities'], recentUserDetail.city);
+ }
- function getRegionsDone(data) {
- populateRegions(data['regions'], recentUserDetail.state);
- updateCityList(getCountryElement().val(), getRegionElement().val(), getCityElement());
- }
+ function getRegionsDone(data) {
+ populateRegions(data['regions'], recentUserDetail.state);
+ updateCityList(getCountryElement().val(), getRegionElement().val(), getCityElement());
+ }
- function getCountryElement() {
- return $('#account-profile-content-scroller select[name=country]');
- }
+ function getCountryElement() {
+ return $('#account-profile-content-scroller select[name=country]');
+ }
- function getRegionElement() {
- return $('#account-profile-content-scroller select[name=region]');
- }
+ function getRegionElement() {
+ return $('#account-profile-content-scroller select[name=region]');
+ }
- function getCityElement() {
- return $('#account-profile-content-scroller select[name=city]');
- }
+ function getCityElement() {
+ return $('#account-profile-content-scroller select[name=city]');
+ }
- function getFirstNameElement() {
- return $('#account-profile-content-scroller input[name=first_name]');
- }
+ function getFirstNameElement() {
+ return $('#account-profile-content-scroller input[name=first_name]');
+ }
- function getLastNameElement() {
- return $('#account-profile-content-scroller input[name=last_name]');
- }
+ function getLastNameElement() {
+ return $('#account-profile-content-scroller input[name=last_name]');
+ }
- function getGenderElement() {
- return $('#account-profile-content-scroller select[name=gender]');
- }
+ function getGenderElement() {
+ return $('#account-profile-content-scroller select[name=gender]');
+ }
- function getMonthElement() {
- return $('#account-profile-content-scroller select#user_birth_date_2i');
- }
+ function getMonthElement() {
+ return $('#account-profile-content-scroller select#user_birth_date_2i');
+ }
- function getDayElement() {
- return $('#account-profile-content-scroller select#user_birth_date_3i');
- }
+ function getDayElement() {
+ return $('#account-profile-content-scroller select#user_birth_date_3i');
+ }
- function getYearElement() {
- return $('#account-profile-content-scroller select#user_birth_date_1i');
- }
+ function getYearElement() {
+ return $('#account-profile-content-scroller select#user_birth_date_1i');
+ }
- function getSubscribeEmail() {
- return $('#account-profile-content-scroller input[name=subscribe_email]');
- }
+ function getSubscribeEmail() {
+ return $('#account-profile-content-scroller input[name=subscribe_email]');
+ }
- function getInstrumentsElement() {
- return $('#account-profile-content-scroller .instrument_selector');
- }
+ function getInstrumentsElement() {
+ return $('#account-profile-content-scroller .instrument_selector');
+ }
+ function getBirthDate() {
+ var month = getMonthElement().val()
+ var day = getDayElement().val()
+ var year = getYearElement().val()
- function getBirthDate() {
- var month = getMonthElement().val()
- var day = getDayElement().val()
- var year = getYearElement().val()
+ if(month != null && month.length > 0 && day != null && day.length > 0 && year != null && year.length > 0) {
+ return month + "-" + day + "-" + year;
+ }
+ else {
+ return null;
+ }
+ }
- if(month != null && month.length > 0 && day != null && day.length > 0 && year != null && year.length > 0) {
- return month + "-" + day + "-" + year;
- }
- else {
- return null;
- }
- }
+ // looks in instrument_selector parent element, and gathers up all
+ // selected elements, and the proficiency level declared
+ function getInstrumentsValue() {
+ var instrumentsParentElement = getInstrumentsElement();
- // looks in instrument_selector parent element, and gathers up all
- // selected elements, and the proficiency level declared
- function getInstrumentsValue() {
- var instrumentsParentElement = getInstrumentsElement();
+ var instruments = []
+ $('input[type=checkbox]:checked', instrumentsParentElement).each(function(i) {
- var instruments = []
- $('input[type=checkbox]:checked', instrumentsParentElement).each(function(i) {
+ var instrumentElement = $(this).closest('tr');
+ // traverse up to common parent of this instrument, and pick out proficiency selector
+ var proficiency = $('select.proficiency_selector', instrumentElement).val()
- var instrumentElement = $(this).closest('tr');
- // traverse up to common parent of this instrument, and pick out proficiency selector
- var proficiency = $('select.proficiency_selector', instrumentElement).val()
+ instruments.push({
+ instrument_id: instrumentElement.attr('data-instrument-id'),
+ proficiency_level: proficiency,
+ priority : i
+ });
+ });
- instruments.push({
- instrument_id: instrumentElement.attr('data-instrument-id'),
- proficiency_level: proficiency,
- priority : i
- })
- });
+ return instruments;
+ }
- return instruments;
- }
+ function initialize() {
+ var screenBindings = {
+ 'beforeShow': beforeShow,
+ 'afterShow': afterShow
+ };
+ app.bindScreen('account/profile', screenBindings);
+ events();
+ }
- function initialize() {
- var screenBindings = {
- 'beforeShow': beforeShow,
- 'afterShow': afterShow
- };
- app.bindScreen('account/profile', screenBindings);
- events();
- }
-
- this.initialize = initialize;
- this.beforeShow = beforeShow;
- this.afterShow = afterShow;
- return this;
- };
+ this.initialize = initialize;
+ this.beforeShow = beforeShow;
+ this.afterShow = afterShow;
+ return this;
+ };
})(window,jQuery);
\ No newline at end of file