oldhaven/app/assets/javascripts/settings.coffee

81 lines
2.3 KiB
CoffeeScript
Raw Normal View History

2011-09-08 03:47:11 +04:00
class window.Settings
2011-09-10 03:30:03 +04:00
getAccountInfo: (callback) ->
_session.query '/user/update/', {}, callback
false
saveAccountInfo: (params, callback) ->
_session.query '/user/update', params, callback
false
updateLastfmLogin: ->
2011-11-27 01:30:43 +04:00
log "Updating Last.fm info ..."
2011-09-10 03:30:03 +04:00
if window.lastfm_popup.closed
_session.query '/user/auth', {}, (ar) ->
_session.setUser ar.user
2011-11-29 21:03:28 +04:00
if _session.user.lastfm_username not in ["", null]
$('#settings .lastfm-off').hide()
$('#settings .lastfm-on').show()
$('#settings .lastfm-login').text _session.user.lastfm_username
false
2011-09-10 03:30:03 +04:00
else
setTimeout _settings.updateLastfmLogin, 100
false
2011-11-29 21:03:28 +04:00
setFormFields: ->
$('#settings input[name="name"]').val _session.user.name
$('#settings select[name="lang"] option[value="'+_session.user.lang+'"]').attr("selected", true)
$('select#lang').chosen()
if _session.user.lastfm_username not in ["", null]
$('#settings .lastfm-off').hide()
$('#settings .lastfm-on').show()
$('#settings .lastfm-login').text _session.user.lastfm_username
else
$('#settings .lastfm-on').hide()
$('#settings .lastfm-off').show()
false
updateSettings: ->
this.saveAccountInfo {
params:
name: $('#settings input[name="name"]').val()
lang: $('#settings select[name="lang"]').val()
}, (ar) ->
_session.setUser ar.user
$("#settings").modal 'hide'
2011-06-27 22:41:36 +04:00
2011-09-14 23:51:51 +04:00
$('#preferences').live 'click', ->
2011-11-29 21:03:28 +04:00
if _session.getUser().id?
$("#settings").modal 'show'
_settings.setFormFields()
false
$("#settings a.close-btn").live 'click', ->
$("#settings").modal 'hide'
2011-09-10 03:30:03 +04:00
false
2011-06-27 22:41:36 +04:00
2011-11-29 21:03:28 +04:00
$('#settings a.save-btn').live 'click', ->
_settings.updateSettings()
2011-09-10 03:30:03 +04:00
false
2011-06-27 22:41:36 +04:00
2011-09-14 23:51:51 +04:00
$('.lastfm-connect').live 'click', ->
2011-09-15 14:44:44 +04:00
window.lastfm_popup = window.open _session.getUser().lastfm_login_url, "lastfm_popup", "status=1,width=960,height=585"
2011-09-10 03:30:03 +04:00
setTimeout _settings.updateLastfmLogin, 100
false
2011-11-29 21:03:28 +04:00
$('.lastfm-disconnect').live 'click', ->
_settings.saveAccountInfo {
params:
lastfm_username: ""
lastfm_token: ""
}, (ar) ->
_session.setUser ar.user
$('#settings .lastfm-on').hide()
$('#settings .lastfm-off').show()
false
2011-09-14 23:51:51 +04:00
false
2011-09-15 09:42:41 +04:00
2011-11-29 21:03:28 +04:00
$ ->
$("#settings").modal keyboard: true, backdrop: true
2011-09-15 09:42:41 +04:00
false