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

52 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2011-09-07 23:47:11 +00:00
class window.Session
2011-09-09 23:30:03 +00:00
vk_params: null
user: null
constructor: (params) ->
attrs = ['expire', 'mid', 'secret', 'sid', 'sig']
_params = {}
for key in attrs
if params[key]?
_params[key] = params[key]
@vk_params = _params
setUser: (user) ->
2011-11-27 09:56:10 +00:00
log "Setting user ..."
2011-09-09 23:30:03 +00:00
@user = user
2011-11-27 09:56:10 +00:00
log "Hello, #{if user.name? then user.name else "%username%"}!"
2011-09-09 23:30:03 +00:00
false
getUser: ->
@user
query: (url, params, callback) ->
q_params = $.extend {}, @vk_params, params
2011-10-20 18:05:16 +00:00
q_params.authenticity_token = $('meta[name="csrf-token"]').attr('content')
2011-09-09 23:30:03 +00:00
$.post url, q_params, callback
false
2011-09-14 19:51:51 +00:00
secureLoad: (url, callback) ->
q_params = $.extend {}, @vk_params
$('#content').load url, q_params, callback
false
2011-09-09 23:30:03 +00:00
reloadSession: ->
2011-11-26 21:30:43 +00:00
log "Reloading session ..."
2011-09-09 23:30:03 +00:00
_session.query '/user/auth', {}, (ar) ->
_session.setUser ar.user
false
false
displayAuthorizedContent: ->
$('.playlist, .player').show()
$('.ad_here, #login').hide()
2011-11-27 18:17:09 +00:00
$('.authorized-action').show()
$('#authorized').css display: 'block'
hideAuthorizedContent: ->
$('.playlist, .player, #authorized').hide()
$('.ad_here').show()
2011-11-27 18:17:09 +00:00
$('.authorized-action').hide()
$('#login').css display: 'block'