1
0
Fork 0
oldhaven/public/js/beathaven/settings.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2011-06-21 20:44:19 +00:00
var Settings = {
2011-06-26 11:45:51 +00:00
user: null,
2011-06-22 07:23:07 +00:00
2011-06-21 23:29:18 +00:00
getAccountInfo: function(callback) {
Session.query('/user/update', {}, callback);
},
saveAccountInfo: function(params, callback) {
Session.query('/user/update', params, callback);
},
loadFormData: function(form) {
if (form == 'account') {
2011-06-26 11:45:51 +00:00
$('.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);
}
2011-06-21 23:29:18 +00:00
}
}
2011-06-21 20:44:19 +00:00
}
$('.settings').live('click', function() {
Ajax.loadSettingsPage();
2011-06-21 23:29:18 +00:00
});
2011-06-21 21:51:20 +00:00
$('.settings-container .tabs .tab').live('click', function(){
if (!$(this).hasClass('active')) {
$('.settings-container .tabs .tab').removeClass('active');
$(this).addClass('active');
2011-06-21 23:29:18 +00:00
$('.form-container').html($('.forms .'+ $(this).attr('data-fieldset')).html());
Settings.loadFormData($(this).attr('data-fieldset'));
2011-06-21 21:51:20 +00:00
}
2011-06-22 07:23:07 +00:00
});
$('.lastfm-connect').live('click', function(){
2011-06-26 11:45:51 +00:00
window.open(Settings.user.lastfm_login_url);
2011-06-21 23:29:18 +00:00
});
$('.settings-container .form input').live('blur', function(){
2011-06-22 07:23:07 +00:00
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%') +'!');
});
}
2011-06-21 20:44:19 +00:00
})