53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
var Settings = {
|
|
|
|
user: null,
|
|
|
|
getAccountInfo: function(callback) {
|
|
Session.query('/user/update', {}, callback);
|
|
},
|
|
|
|
saveAccountInfo: function(params, callback) {
|
|
Session.query('/user/update', params, callback);
|
|
},
|
|
|
|
loadFormData: function(form) {
|
|
if (form == 'account') {
|
|
$('.settings-container .form input[name$="username"]').val(Settings.user.name);
|
|
$('.settings-container .form input[name$="email"]').val(Settings.user.email);
|
|
} else if (form == 'lastfm') {
|
|
if (Settings.user.lastfm_username) {
|
|
$('.form-container input[name$="username"]').first().val(Settings.user.lastfm_username);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$('.settings').live('click', function() {
|
|
Ajax.loadSettingsPage();
|
|
});
|
|
|
|
$('.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'));
|
|
}
|
|
});
|
|
|
|
$('.lastfm-connect').live('click', function(){
|
|
window.open(Settings.user.lastfm_login_url);
|
|
});
|
|
|
|
$('.settings-container .form input').live('blur', function(){
|
|
var 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(),
|
|
};
|
|
Settings.saveAccountInfo(params, function(){
|
|
$('#header-container .hello .greating').text('Hi there, '+ (params.username.length > 0 ? params.username : '%username%') +'!');
|
|
});
|
|
}
|
|
}) |