79 lines
2.9 KiB
JavaScript
79 lines
2.9 KiB
JavaScript
var Settings;
|
|
Settings = (function() {
|
|
function Settings() {}
|
|
Settings.prototype.getAccountInfo = function(callback) {
|
|
_session.query('/user/update/', {}, callback);
|
|
return false;
|
|
};
|
|
Settings.prototype.saveAccountInfo = function(params, callback) {
|
|
_session.query('/user/update', params, callback);
|
|
return false;
|
|
};
|
|
Settings.prototype.loadFormData = function(form) {
|
|
if (form === 'account') {
|
|
$('.settings-container .form input[name$="username"]').val(_session.getUser().name);
|
|
$('.settings-container .form input[name$="email"]').val(_session.getUser().email);
|
|
$('.settings-container .form select').val(_session.getUser().lang);
|
|
} else if (form === 'lastfm') {
|
|
if (_session.getUser().lastfm_username) {
|
|
$('.form-container input[name$="username"]').first().val(_session.getUser().lastfm_username);
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
Settings.prototype.updateLastfmLogin = function() {
|
|
if (window.lastfm_popup.closed) {
|
|
_session.query('/user/auth', {}, function(ar) {
|
|
_session.setUser(ar.user);
|
|
return _settings.loadFormData('lastfm');
|
|
});
|
|
} else {
|
|
setTimeout(_settings.updateLastfmLogin, 100);
|
|
}
|
|
return false;
|
|
};
|
|
return Settings;
|
|
})();
|
|
$('.settings').live('click', function() {
|
|
_ajax.go('/settings/');
|
|
return false;
|
|
});
|
|
$('.settings-container .tabs .tab').live('click', function() {
|
|
if (!$(this).hasClass('active')) {
|
|
$('.settings-container .tabs .tab').removeClass('active');
|
|
$(this).addClass('active');
|
|
$('.form-container').html($('.forms .' + $(this).attr('data-fieldset')).html());
|
|
_settings.loadFormData($(this).attr('data-fieldset'));
|
|
}
|
|
return false;
|
|
});
|
|
$('.lastfm-connect').live('click', function() {
|
|
window.lastfm_popup = window.open(_session.getUser().lastfm_login_url);
|
|
setTimeout(_settings.updateLastfmLogin, 100);
|
|
return false;
|
|
});
|
|
$('.settings-container .form input, .settings-container .form select').live('blur', function() {
|
|
var active_tab, lang_changed, params;
|
|
active_tab = $('.settings-container .tabs .tab.active').attr('data-fieldset');
|
|
if (active_tab === 'account') {
|
|
params = {
|
|
username: $('.settings-container .form input[name$="username"]').first().val(),
|
|
email: $('.settings-container .form input[name$="email"]').first().val(),
|
|
lang: $('.settings-container .form select').first().val()
|
|
};
|
|
lang_changed = params.lang !== _session.getUser().lang;
|
|
if (lang_changed) {
|
|
if (!confirm(_beathaven.ls('WINDOW_LANG_RELOAD', params.lang))) {
|
|
$('.settings-container .form select').val(_session.getUser().lang);
|
|
}
|
|
}
|
|
_settings.saveAccountInfo(params, function() {
|
|
if (lang_changed) {
|
|
window.location.reload();
|
|
}
|
|
$('.header-container .hello .greating span').text((params.username.length > 0 ? params.username : '%username%'));
|
|
return false;
|
|
});
|
|
}
|
|
return false;
|
|
}); |