2011-09-07 23:47:11 +00:00
|
|
|
class window.Settings
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
getAccountInfo: (callback) ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_session.query '/user/update/', {}, callback
|
2011-06-29 04:11:54 +00:00
|
|
|
false
|
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-29 04:11:54 +00:00
|
|
|
false
|
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-30 05:12:52 +00:00
|
|
|
$('.settings-container .form select').val _session.getUser().lang
|
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-29 04:11:54 +00:00
|
|
|
false
|
|
|
|
|
|
|
|
updateLastfmLogin: ->
|
|
|
|
if window.lastfm_popup.closed
|
|
|
|
_session.query '/user/auth', {}, (ar) ->
|
|
|
|
_session.setUser ar.user
|
|
|
|
_settings.loadFormData 'lastfm'
|
|
|
|
else
|
|
|
|
setTimeout _settings.updateLastfmLogin, 100
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
$('.settings') .live 'click', ->
|
2011-06-27 20:43:54 +00:00
|
|
|
_ajax.go('/settings/');
|
2011-06-29 04:11:54 +00:00
|
|
|
false
|
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-29 04:11:54 +00:00
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
|
|
|
$('.lastfm-connect') .live 'click', ->
|
2011-06-29 04:11:54 +00:00
|
|
|
window.lastfm_popup = window.open _session.getUser().lastfm_login_url
|
|
|
|
setTimeout _settings.updateLastfmLogin, 100
|
|
|
|
false
|
2011-06-27 18:41:36 +00:00
|
|
|
|
2011-06-30 05:12:52 +00:00
|
|
|
$('.settings-container .form input, .settings-container .form select').live 'blur', ->
|
2011-06-27 18:41:36 +00:00
|
|
|
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-30 05:12:52 +00:00
|
|
|
lang: $('.settings-container .form select').first().val()
|
|
|
|
lang_changed = params.lang != _session.getUser().lang
|
|
|
|
if lang_changed
|
|
|
|
if not confirm _beathaven.ls 'WINDOW_LANG_RELOAD', params.lang
|
|
|
|
$('.settings-container .form select').val _session.getUser().lang
|
2011-06-27 20:43:54 +00:00
|
|
|
_settings.saveAccountInfo params, ->
|
2011-06-30 05:12:52 +00:00
|
|
|
if lang_changed
|
|
|
|
window.location.reload()
|
2011-06-29 04:11:54 +00:00
|
|
|
$('.header-container .hello .greating span').text (if params.username.length > 0 then params.username else '%username%')
|
|
|
|
false
|
|
|
|
false
|