41 lines
1.5 KiB
CoffeeScript
41 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.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%')+ '!'
|