2016-01-15 17:59:55 +00:00
|
|
|
(function (context, $) {
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
context.JK = context.JK || {};
|
2016-01-15 17:59:55 +00:00
|
|
|
context.JK.AccountProfileScreen = function (app) {
|
2015-03-04 04:16:13 +00:00
|
|
|
var $document = $(document);
|
|
|
|
|
var logger = context.JK.logger;
|
|
|
|
|
var EVENTS = context.JK.EVENTS;
|
2016-05-01 03:12:25 +00:00
|
|
|
var NAMED_MESSAGES = context.JK.NAMED_MESSAGES;
|
2015-03-04 04:16:13 +00:00
|
|
|
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 = '<option value=""></option>';
|
|
|
|
|
var nilOptionText = 'n/a';
|
2015-03-04 07:02:48 +00:00
|
|
|
var $screen = $('#account-profile-basics');
|
2015-04-01 00:35:38 +00:00
|
|
|
var $avatar = $screen.find('#avatar');
|
|
|
|
|
var $country = $screen.find('#country');
|
|
|
|
|
var $region = $screen.find('#region');
|
|
|
|
|
var $city = $screen.find('#city');
|
|
|
|
|
var $firstName = $screen.find('#first-name');
|
|
|
|
|
var $lastName = $screen.find('#last-name');
|
|
|
|
|
var $gender = $screen.find('#gender');
|
|
|
|
|
var $biography = $screen.find('#biography');
|
|
|
|
|
var $subscribe = $screen.find('#subscribe');
|
|
|
|
|
|
2015-06-05 17:55:55 +00:00
|
|
|
var $btnCancel = $screen.find('.account-edit-profile-cancel');
|
|
|
|
|
var $btnSubmit = $screen.find('.account-edit-profile-submit');
|
2015-03-21 14:04:46 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function beforeShow(data) {
|
2016-01-15 17:59:55 +00:00
|
|
|
userId = data.id;
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function afterShow(data) {
|
2016-01-15 17:59:55 +00:00
|
|
|
if (window.ProfileStore.solo) {
|
|
|
|
|
$btnSubmit.text('SAVE & RETURN TO PROFILE');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$btnSubmit.text('SAVE & NEXT');
|
|
|
|
|
}
|
|
|
|
|
resetForm();
|
|
|
|
|
renderAccountProfile();
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-17 03:54:33 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function resetForm() {
|
|
|
|
|
// remove all display errors
|
|
|
|
|
$('#account-profile-content-scroller form .error-text').remove()
|
|
|
|
|
$('#account-profile-content-scroller form .error').removeClass("error")
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 07:02:48 +00:00
|
|
|
function populateAccountProfile(userDetail) {
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-04-01 00:35:38 +00:00
|
|
|
$avatar.attr('src', context.JK.resolveAvatarUrl(userDetail.photo_url));
|
|
|
|
|
$country.val(userDetail.country);
|
|
|
|
|
$region.val(userDetail.state);
|
|
|
|
|
$city.val(userDetail.city);
|
|
|
|
|
$firstName.val(userDetail.first_name);
|
|
|
|
|
$lastName.val(userDetail.last_name);
|
|
|
|
|
$gender.val(userDetail.gender);
|
|
|
|
|
$biography.val(userDetail.biography);
|
2015-03-04 04:16:13 +00:00
|
|
|
|
2015-04-01 00:35:38 +00:00
|
|
|
if (userDetail.subscribe_email) {
|
|
|
|
|
$subscribe.attr('checked', 'checked');
|
|
|
|
|
}
|
2015-03-04 07:02:48 +00:00
|
|
|
|
2015-04-01 00:35:38 +00:00
|
|
|
var content_root = $('#account-profile-content-scroller');
|
2015-03-04 04:16:13 +00:00
|
|
|
|
|
|
|
|
// set birth_date
|
2016-01-15 17:59:55 +00:00
|
|
|
if (userDetail.birth_date) {
|
2015-03-04 04:16:13 +00:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function populateAccountProfileLocation(userDetail, regions, cities) {
|
2016-01-15 17:59:55 +00:00
|
|
|
populateRegions(regions, userDetail.state);
|
|
|
|
|
populateCities(cities, userDetail.city);
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function populateCountries(countries, userCountry) {
|
2013-08-10 19:33:02 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
// countries has the format ["US", ...]
|
|
|
|
|
var foundCountry = false;
|
|
|
|
|
var countrySelect = getCountryElement();
|
|
|
|
|
countrySelect.children().remove();
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var nilOption = $(nilOptionStr);
|
|
|
|
|
nilOption.text(nilOptionText);
|
|
|
|
|
countrySelect.append(nilOption);
|
2013-08-10 19:33:02 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
$.each(countries, function (index, country) {
|
|
|
|
|
if (!country) return;
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var option = $(nilOptionStr);
|
|
|
|
|
option.text(country);
|
|
|
|
|
option.attr("value", country);
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (country == userCountry) {
|
2015-03-04 04:16:13 +00:00
|
|
|
foundCountry = true;
|
2014-03-18 03:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
countrySelect.append(option);
|
|
|
|
|
});
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (!foundCountry) {
|
2015-03-04 04:16:13 +00:00
|
|
|
// 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);
|
|
|
|
|
}
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
countrySelect.val(userCountry);
|
|
|
|
|
countrySelect.attr("disabled", null)
|
|
|
|
|
}
|
2014-03-18 03:20:41 +00:00
|
|
|
|
|
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function populateCountriesx(countriesx, userCountry) {
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
// countriesx has the format [{countrycode: "US", countryname: "United States"}, ...]
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var foundCountry = false;
|
|
|
|
|
var countrySelect = getCountryElement();
|
|
|
|
|
countrySelect.children().remove();
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var nilOption = $(nilOptionStr);
|
|
|
|
|
nilOption.text(nilOptionText);
|
|
|
|
|
countrySelect.append(nilOption);
|
2014-03-18 03:20:41 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
$.each(countriesx, function (index, countryx) {
|
2015-03-04 04:16:13 +00:00
|
|
|
if (!countryx.countrycode) return;
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var option = $(nilOptionStr);
|
|
|
|
|
option.text(countryx.countryname);
|
|
|
|
|
option.attr("value", countryx.countrycode);
|
2014-02-10 22:43:09 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (countryx.countrycode == userCountry) {
|
2015-03-04 04:16:13 +00:00
|
|
|
foundCountry = true;
|
2013-07-09 03:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
countrySelect.append(option);
|
|
|
|
|
});
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (!foundCountry) {
|
2015-03-04 04:16:13 +00:00
|
|
|
// 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);
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
countrySelect.val(userCountry);
|
|
|
|
|
countrySelect.attr("disabled", null);
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function populateRegions(regions, userRegion) {
|
|
|
|
|
var regionSelect = getRegionElement()
|
|
|
|
|
regionSelect.children().remove()
|
2014-02-10 22:43:09 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var nilOption = $(nilOptionStr);
|
|
|
|
|
nilOption.text(nilOptionText);
|
|
|
|
|
regionSelect.append(nilOption);
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
$.each(regions, function (index, region) {
|
|
|
|
|
if (!region) return;
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var option = $(nilOptionStr);
|
|
|
|
|
option.text(region['name']);
|
|
|
|
|
option.attr("value", region['region']);
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
regionSelect.append(option);
|
|
|
|
|
})
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
regionSelect.val(userRegion)
|
|
|
|
|
regionSelect.attr("disabled", null)
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function populateCities(cities, userCity) {
|
|
|
|
|
var citySelect = getCityElement();
|
|
|
|
|
citySelect.children().remove();
|
2014-02-10 22:43:09 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var nilOption = $(nilOptionStr);
|
|
|
|
|
nilOption.text(nilOptionText);
|
|
|
|
|
citySelect.append(nilOption);
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
$.each(cities, function (index, city) {
|
|
|
|
|
if (!city) return;
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var option = $(nilOptionStr);
|
|
|
|
|
option.text(city);
|
|
|
|
|
option.attr("value", city);
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
citySelect.append(option);
|
|
|
|
|
});
|
2013-05-23 13:53:37 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
citySelect.val(userCity);
|
|
|
|
|
citySelect.attr("disabled", null);
|
|
|
|
|
}
|
2014-07-31 12:49:13 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
/****************** MAIN PORTION OF SCREEN *****************/
|
|
|
|
|
// events for main screen
|
|
|
|
|
function events() {
|
2016-01-15 17:59:55 +00:00
|
|
|
$btnCancel.click(function (evt) {
|
2015-03-21 14:04:46 +00:00
|
|
|
evt.stopPropagation();
|
2016-01-13 02:37:00 +00:00
|
|
|
window.ProfileActions.cancelProfileEdit()
|
2015-03-21 14:04:46 +00:00
|
|
|
return false;
|
|
|
|
|
});
|
2016-01-15 17:59:55 +00:00
|
|
|
|
|
|
|
|
$('#account-profile-content-scroller').on('click', '#account-change-avatar', function (evt) {
|
|
|
|
|
evt.stopPropagation();
|
|
|
|
|
navToAvatar();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2015-05-07 23:01:12 +00:00
|
|
|
|
|
|
|
|
enableSubmits();
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2016-05-01 03:12:25 +00:00
|
|
|
function teacherGuidance() {
|
|
|
|
|
|
|
|
|
|
if(recentUserDetail && recentUserDetail.is_a_teacher) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
var $header = $('#account-edit-profile-form h2')
|
|
|
|
|
context.JK.HelpBubbleHelper.teacherMusicianProfile($header, $screen);
|
|
|
|
|
}, 2000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-04 04:16:13 +00:00
|
|
|
function renderAccountProfile() {
|
2016-01-15 17:59:55 +00:00
|
|
|
|
2015-03-13 01:34:20 +00:00
|
|
|
$.when(api.getUserProfile())
|
2016-01-15 17:59:55 +00:00
|
|
|
.done(function (userDetail) {
|
2015-03-04 07:02:48 +00:00
|
|
|
recentUserDetail = userDetail;
|
|
|
|
|
populateAccountProfile(userDetail);
|
2016-05-01 03:12:25 +00:00
|
|
|
teacherGuidance();
|
2015-03-04 04:16:13 +00:00
|
|
|
selectLocation = new context.JK.SelectLocation(getCountryElement(), getRegionElement(), getCityElement(), app);
|
|
|
|
|
selectLocation.load(userDetail.country, userDetail.state, userDetail.city)
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function navToAccount() {
|
|
|
|
|
resetForm();
|
2015-03-19 01:42:18 +00:00
|
|
|
window.location = '/client#/profile/' + context.JK.currentUserId;
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function navToAvatar() {
|
|
|
|
|
resetForm();
|
|
|
|
|
window.location = '/client#/account/profile/avatar';
|
|
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function handleUpdateProfile() {
|
2015-05-07 23:01:12 +00:00
|
|
|
disableSubmits();
|
2015-03-04 04:16:13 +00:00
|
|
|
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();
|
2015-03-04 07:02:48 +00:00
|
|
|
var biography = $biography.val();
|
2015-03-04 04:16:13 +00:00
|
|
|
|
|
|
|
|
api.updateUser({
|
|
|
|
|
country: country,
|
|
|
|
|
state: region,
|
|
|
|
|
city: city,
|
|
|
|
|
first_name: firstName,
|
|
|
|
|
last_name: lastName,
|
|
|
|
|
gender: gender,
|
|
|
|
|
birth_date: birthDate,
|
2015-03-04 07:02:48 +00:00
|
|
|
biography: biography,
|
2015-03-04 04:16:13 +00:00
|
|
|
subscribe_email: subscribeEmail
|
|
|
|
|
})
|
2016-01-15 17:59:55 +00:00
|
|
|
.done(postUpdateProfileSuccess)
|
|
|
|
|
.fail(postUpdateProfileFailure)
|
|
|
|
|
.always(enableSubmits)
|
2015-05-07 23:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function enableSubmits() {
|
2016-01-15 17:59:55 +00:00
|
|
|
$btnSubmit.click(function (evt) {
|
2015-05-07 23:01:12 +00:00
|
|
|
evt.stopPropagation();
|
|
|
|
|
handleUpdateProfile();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2016-01-15 17:59:55 +00:00
|
|
|
$btnSubmit.removeClass("disabled");
|
|
|
|
|
$('#account-profile-content-scroller').on('submit', '#account-edit-email-form', function (evt) {
|
|
|
|
|
evt.stopPropagation();
|
|
|
|
|
handleUpdateProfile();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
$("#account-edit-email-form").removeClass("disabled");
|
2015-05-07 23:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableSubmits() {
|
|
|
|
|
$("#account-edit-email-form").addClass("disabled")
|
|
|
|
|
$("#account-edit-email-form").off("click")
|
|
|
|
|
$btnSubmit.addClass("disabled")
|
|
|
|
|
$btnSubmit.off("click")
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function postUpdateProfileSuccess(response) {
|
|
|
|
|
$document.triggerHandler(EVENTS.USER_UPDATED, response);
|
2016-01-13 02:37:00 +00:00
|
|
|
window.ProfileActions.editProfileNext('experience');
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function postUpdateProfileFailure(xhr, textStatus, errorMessage) {
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
var errors = JSON.parse(xhr.responseText)
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (xhr.status == 422) {
|
2015-03-04 04:16:13 +00:00
|
|
|
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);
|
2015-03-04 07:02:48 +00:00
|
|
|
var biography = context.JK.format_errors("biography", errors);
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (first_name != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getFirstNameElement().closest('div.field').addClass('error').end().after(first_name);
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (last_name != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getLastNameElement().closest('div.field').addClass('error').end().after(last_name);
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (country != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getCountryElement().closest('div.field').addClass('error').end().after(country);
|
|
|
|
|
}
|
2013-10-22 17:38:21 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (state != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getRegionElement().closest('div.field').addClass('error').end().after(state);
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (city != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getCityElement().closest('div.field').addClass('error').end().after(city);
|
2013-05-16 17:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (birth_date != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getYearElement().closest('div.field').addClass('error').end().after(birth_date);
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (subscribeEmail != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getSubscribeEmail().closest('div.field').addClass('error').end().after(subscribeEmail);
|
2013-07-09 03:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (gender != null) {
|
2015-03-04 04:16:13 +00:00
|
|
|
getGenderElement().closest('div.field').addClass('error').end().after(gender);
|
2013-07-09 03:05:05 +00:00
|
|
|
}
|
2016-01-15 18:35:04 +00:00
|
|
|
|
|
|
|
|
if (biography != null) {
|
|
|
|
|
getBiographyElement().closest('div.field').addClass('error').end().after(biography);
|
|
|
|
|
}
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
app.ajaxError(xhr, textStatus, errorMessage)
|
2016-01-15 17:59:55 +00:00
|
|
|
}
|
2015-03-04 04:16:13 +00:00
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function handleCountryChanged() {
|
|
|
|
|
var selectedCountry = getCountryElement().val()
|
|
|
|
|
var selectedRegion = getRegionElement().val()
|
|
|
|
|
var cityElement = getCityElement();
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
updateRegionList(selectedCountry, getRegionElement());
|
|
|
|
|
updateCityList(selectedCountry, null, cityElement);
|
|
|
|
|
}
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
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...'))
|
|
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
api.getRegions({country: selectedCountry})
|
2015-03-04 04:16:13 +00:00
|
|
|
.done(getRegionsDone)
|
2016-01-15 17:59:55 +00:00
|
|
|
.error(function (err) {
|
2015-03-04 04:16:13 +00:00
|
|
|
regionElement.children().remove()
|
|
|
|
|
regionElement.append($(nilOptionStr).text(nilOptionText))
|
|
|
|
|
})
|
|
|
|
|
.always(function () {
|
|
|
|
|
loadingRegionsData = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
regionElement.children().remove()
|
|
|
|
|
regionElement.append($(nilOptionStr).text(nilOptionText))
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
cityElement.children().remove();
|
|
|
|
|
cityElement.append($(nilOptionStr).text('loading...'));
|
|
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
api.getCities({country: selectedCountry, region: selectedRegion})
|
2015-03-04 04:16:13 +00:00
|
|
|
.done(getCitiesDone)
|
2016-01-15 17:59:55 +00:00
|
|
|
.error(function (err) {
|
|
|
|
|
cityElement.children().remove();
|
|
|
|
|
cityElement.append($(nilOptionStr).text(nilOptionText));
|
2015-03-04 04:16:13 +00:00
|
|
|
})
|
|
|
|
|
.always(function () {
|
2016-01-15 17:59:55 +00:00
|
|
|
loadingCitiesData = false;
|
2015-03-04 04:16:13 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cityElement.children().remove();
|
|
|
|
|
cityElement.append($(nilOptionStr).text(nilOptionText));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-09 03:05:05 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function handleRegionChanged() {
|
|
|
|
|
var selectedCountry = getCountryElement().val()
|
|
|
|
|
var selectedRegion = getRegionElement().val()
|
|
|
|
|
var cityElement = getCityElement();
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
updateCityList(selectedCountry, selectedRegion, cityElement);
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getCitiesDone(data) {
|
|
|
|
|
populateCities(data['cities'], recentUserDetail.city);
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getRegionsDone(data) {
|
|
|
|
|
populateRegions(data['regions'], recentUserDetail.state);
|
|
|
|
|
updateCityList(getCountryElement().val(), getRegionElement().val(), getCityElement());
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getCountryElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select[name=country]');
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getRegionElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select[name=region]');
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getCityElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select[name=city]');
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getFirstNameElement() {
|
|
|
|
|
return $('#account-profile-content-scroller input[name=first_name]');
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getLastNameElement() {
|
|
|
|
|
return $('#account-profile-content-scroller input[name=last_name]');
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getGenderElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select[name=gender]');
|
|
|
|
|
}
|
2013-10-22 17:38:21 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getMonthElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select#user_birth_date_2i');
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getDayElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select#user_birth_date_3i');
|
|
|
|
|
}
|
2013-05-19 01:50:08 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getYearElement() {
|
|
|
|
|
return $('#account-profile-content-scroller select#user_birth_date_1i');
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getSubscribeEmail() {
|
|
|
|
|
return $('#account-profile-content-scroller input[name=subscribe_email]');
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2016-01-15 18:35:04 +00:00
|
|
|
function getBiographyElement() {
|
|
|
|
|
return $('#account-profile-content-scroller textarea[name=biography]');
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function getBirthDate() {
|
2018-01-10 02:56:06 +00:00
|
|
|
var monthElement = getMonthElement()
|
|
|
|
|
if(!monthElement)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-03-04 04:16:13 +00:00
|
|
|
var month = getMonthElement().val()
|
|
|
|
|
var day = getDayElement().val()
|
|
|
|
|
var year = getYearElement().val()
|
|
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
if (month != null && month.length > 0 && day != null && day.length > 0 && year != null && year.length > 0) {
|
2015-03-04 04:16:13 +00:00
|
|
|
return month + "-" + day + "-" + year;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-18 18:04:04 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
function initialize() {
|
|
|
|
|
var screenBindings = {
|
|
|
|
|
'beforeShow': beforeShow,
|
|
|
|
|
'afterShow': afterShow
|
|
|
|
|
};
|
|
|
|
|
app.bindScreen('account/profile', screenBindings);
|
|
|
|
|
events();
|
|
|
|
|
}
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2015-03-04 04:16:13 +00:00
|
|
|
this.initialize = initialize;
|
|
|
|
|
this.beforeShow = beforeShow;
|
|
|
|
|
this.afterShow = afterShow;
|
|
|
|
|
return this;
|
|
|
|
|
};
|
2013-05-16 17:45:10 +00:00
|
|
|
|
2016-01-15 17:59:55 +00:00
|
|
|
})(window, jQuery);
|