1
0
Fork 0
oldhaven/app/coffeescripts/settings.coffee

41 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2011-06-27 18:41:36 +00:00
class Settings
getAccountInfo: (callback) ->
session.query '/user/update/', {}, callback
saveAccountInfo: (params, callback) ->
session.query '/user/update', params, callback
loadFormData: (form) ->
if form == 'account'
$('.settings-container .form input[name$="username"]').val session.user.name
$('.settings-container .form input[name$="email"]').val session.email
else if form == 'lastfm'
if @user.lastfm_username
$('.form-container input[name$="username"]').first().val session.lastfm_username
$ ->
window.settings = new Settings()
false
$('.settings') .live 'click', ->
ajax.loadSettingsPage();
$('.settings-container .tabs .tab').live 'click', ->
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', ->
window.open session.user.lastfm_login_url
$('.settings-container .form input').live 'blur', ->
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, ->
$('#header-container .hello .greating').text 'Hi there, ' +(if params.username.length > 0 then params.username else '%username%')+ '!'