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

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2011-06-27 20:43:54 +00:00
var Settings;
Settings = (function() {
function Settings() {}
Settings.prototype.getAccountInfo = function(callback) {
return _session.query('/user/update/', {}, callback);
};
Settings.prototype.saveAccountInfo = function(params, callback) {
return _session.query('/user/update', params, callback);
};
Settings.prototype.loadFormData = function(form) {
if (form === 'account') {
$('.settings-container .form input[name$="username"]').val(_session.getUser().name);
return $('.settings-container .form input[name$="email"]').val(_session.getUser().email);
} else if (form === 'lastfm') {
if (_session.getUser().lastfm_username) {
return $('.form-container input[name$="username"]').first().val(_session.getUser().lastfm_username);
2011-06-27 18:41:36 +00:00
}
}
2011-06-27 20:43:54 +00:00
};
return Settings;
})();
$('.settings').live('click', function() {
return _ajax.go('/settings/');
});
$('.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());
return _settings.loadFormData($(this).attr('data-fieldset'));
}
});
$('.lastfm-connect').live('click', function() {
return window.open(_session.getUser().lastfm_login_url);
});
$('.settings-container .form input').live('blur', function() {
var active_tab, 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()
};
return _settings.saveAccountInfo(params, function() {
return $('#header-container .hello .greating').text('Hi there, ' + (params.username.length > 0 ? params.username : '%username%') + '!');
});
}
});