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

38 lines
1.5 KiB
CoffeeScript

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.getUser().name
$('.settings-container .form input[name$="email"]').val _session.getUser().email
else if form == 'lastfm'
if _session.getUser().lastfm_username
$('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username
$('.settings') .live 'click', ->
_ajax.go('/settings/');
$('.settings-container .tabs .tab').live 'click', ->
if not $(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.getUser().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%')+ '!'