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

42 lines
1.3 KiB
JavaScript

var Settings = {
getAccountInfo: function(callback) {
Session.query('/user/update', {}, callback);
},
saveAccountInfo: function(params, callback) {
Session.query('/user/update', params, callback);
},
loadFormData: function(form) {
if (form == 'account') {
this.getAccountInfo(function(data){
$('.settings-container .form input[name$="username"]').val(data.username);
$('.settings-container .form input[name$="email"]').val(data.email);
})
}
}
}
$('.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'));
}
});
$('.settings-container .form input').live('blur', function(){
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%') +'!');
});
})