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

55 lines
2.2 KiB
JavaScript
Raw Normal View History

2011-06-27 18:41:36 +00:00
/* DO NOT MODIFY. This file was compiled Mon, 27 Jun 2011 14:00:02 GMT from
* /Users/chez/Sites/beathaven/app/coffeescripts/settings.coffee
*/
(function() {
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.user.name);
return $('.settings-container .form input[name$="email"]').val(session.email);
} else if (form === 'lastfm') {
if (this.user.lastfm_username) {
return $('.form-container input[name$="username"]').first().val(session.lastfm_username);
}
}
};
return Settings;
})();
$('.settings').live('click', function() {
return 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());
return settings.loadFormData($(this).attr('data-fieldset'));
}
});
$('.lastfm-connect').live('click', function() {
return window.open(session.user.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%') + '!');
});
}
});
}).call(this);