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