
Browsers disable local storage and session storage when cookies are disabled - any call to one of those will cause an error. This commit provides fallback storage, which will store items in memory.
77 lines
2.0 KiB
CoffeeScript
77 lines
2.0 KiB
CoffeeScript
require 'travis/ajax'
|
|
require 'travis/model'
|
|
|
|
@Travis.User = Travis.Model.extend
|
|
name: DS.attr('string')
|
|
email: DS.attr('string')
|
|
login: DS.attr('string')
|
|
token: DS.attr('string')
|
|
locale: DS.attr('string')
|
|
gravatarId: DS.attr('string')
|
|
isSyncing: DS.attr('boolean')
|
|
syncedAt: DS.attr('string')
|
|
repoCount: DS.attr('number')
|
|
|
|
init: ->
|
|
@poll() if @get('isSyncing')
|
|
@_super()
|
|
|
|
Ember.run.next this, ->
|
|
transaction = @get('store').transaction()
|
|
transaction.add this
|
|
|
|
urlGithub: (->
|
|
"https://github.com/#{@get('login')}"
|
|
).property()
|
|
|
|
permissions: (->
|
|
unless @permissions
|
|
@permissions = Ember.ArrayProxy.create(content: [])
|
|
Travis.ajax.get('/users/permissions', (data) => @permissions.set('content', data.permissions))
|
|
@permissions
|
|
).property()
|
|
|
|
updateLocale: (locale) ->
|
|
@setWithSession('locale', locale)
|
|
|
|
transaction = @get('transaction')
|
|
transaction.commit()
|
|
|
|
self = this
|
|
observer = ->
|
|
unless self.get('isSaving')
|
|
self.removeObserver 'isSaving', observer
|
|
transaction = self.get('store').transaction()
|
|
transaction.add self
|
|
|
|
@addObserver 'isSaving', observer
|
|
|
|
type: (->
|
|
'user'
|
|
).property()
|
|
|
|
sync: ->
|
|
self = this
|
|
Travis.ajax.post('/users/sync', {}, ->
|
|
self.setWithSession('isSyncing', true)
|
|
self.poll()
|
|
)
|
|
|
|
poll: ->
|
|
Travis.ajax.get '/users', (data) =>
|
|
if data.user.is_syncing
|
|
Ember.run.later(this, this.poll.bind(this), 3000)
|
|
else
|
|
@set('isSyncing', false)
|
|
@setWithSession('syncedAt', data.user.synced_at)
|
|
Travis.trigger('user:synced', data.user)
|
|
|
|
# need to pass any param to trigger findQuery
|
|
Travis.Account.find(foo: '')
|
|
|
|
setWithSession: (name, value) ->
|
|
@set(name, value)
|
|
user = JSON.parse(Travis.sessionStorage.getItem('travis.user'))
|
|
user[$.underscore(name)] = @get(name)
|
|
Travis.sessionStorage.setItem('travis.user', JSON.stringify(user))
|