1
0
Fork 0
oldhaven/app/assets/javascripts/settings.coffee

64 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2011-09-07 23:47:11 +00:00
class window.Settings
2011-09-09 23:30:03 +00:00
getAccountInfo: (callback) ->
_session.query '/user/update/', {}, callback
false
saveAccountInfo: (params, callback) ->
_session.query '/user/update', params, callback
false
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
$('.settings-container .form select').val _session.getUser().lang
else if form == 'lastfm'
if _session.getUser().lastfm_username
$('.form-container input[name$="username"]').first().val _session.getUser().lastfm_username
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
2011-09-09 23:30:03 +00:00
$('#preferences') .live 'click', ->
_ajax.go('/settings/');
false
2011-06-27 18:41:36 +00:00
$('.settings-container .tabs .tab').live 'click', ->
2011-09-09 23:30:03 +00:00
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'
false
2011-06-27 18:41:36 +00:00
$('.lastfm-connect') .live 'click', ->
2011-09-09 23:30:03 +00:00
window.lastfm_popup = window.open _session.getUser().lastfm_login_url
setTimeout _settings.updateLastfmLogin, 100
false
2011-06-30 05:12:52 +00:00
$('.settings-container .form input, .settings-container .form select').live 'blur', ->
2011-09-09 23:30:03 +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()
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
_settings.saveAccountInfo params, ->
if lang_changed
window.location.reload()
$('.header-container .hello .greating span').text (if params.username.length > 0 then params.username else '%username%')
false
false