Keep application class at TravisApplication and move it to separate file

It helps when application class needs to be reopened before creating
application
This commit is contained in:
Piotr Sarnacki 2013-03-20 00:00:03 +01:00
parent c0d23f5579
commit f87fe183e4
2 changed files with 68 additions and 69 deletions

View File

@ -1,4 +1,66 @@
# $.mockjaxSettings.log = false
# Ember.LOG_BINDINGS = true
# Ember.ENV.RAISE_ON_DEPRECATION = true
# Pusher.log = -> console.log(arguments)
unless window.TravisApplication
window.TravisApplication = Em.Application.extend(Ember.Evented,
authStateBinding: 'auth.state'
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
setup: ->
@store = Travis.Store.create(
adapter: Travis.RestAdapter.create()
)
@store.loadMany(Travis.Sponsor, Travis.SPONSORS)
@slider = new Travis.Slider()
@pusher = new Travis.Pusher(Travis.config.pusher_key)
@tailing = new Travis.Tailing()
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
reset: ->
@store.destroy()
@setup()
@_super.apply(this, arguments);
lookup: ->
@__container__.lookup.apply this, arguments
storeAfterSignInPath: (path) ->
@get('auth').storeAfterSignInPath(path)
autoSignIn: (path) ->
@get('auth').autoSignIn()
signIn: ->
@get('auth').signIn()
signOut: ->
@get('auth').signOut()
receive: ->
@store.receive.apply(@store, arguments)
toggleSidebar: ->
$('body').toggleClass('maximized')
# TODO gotta force redraws here :/
element = $('<span></span>')
$('#top .profile').append(element)
Em.run.later (-> element.remove()), 10
element = $('<span></span>')
$('#repo').append(element)
Em.run.later (-> element.remove()), 10
setLocale: (locale) ->
return unless locale
I18n.locale = locale
Travis.set('locale', locale)
defaultLocale: 'en'
ready: ->
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
I18n.fallbacks = true
@setLocale 'locale', @get('defaultLocale')
currentDate: ->
new Date()
)

View File

@ -1,5 +1,6 @@
require 'ext/jquery'
require 'ext/ember/namespace'
require 'app'
window.ENV ||= {}
window.ENV.RAISE_ON_DEPRECATION = true
@ -31,71 +32,7 @@ Storage = Em.Object.extend
clear: ->
@set('storage', {})
window.Travis = Em.Application.extend(Ember.Evented,
authStateBinding: 'auth.state'
signedIn: (-> @get('authState') == 'signed-in' ).property('authState')
setup: ->
@store = Travis.Store.create(
adapter: Travis.RestAdapter.create()
)
@store.loadMany(Travis.Sponsor, Travis.SPONSORS)
@slider = new Travis.Slider()
@pusher = new Travis.Pusher(Travis.config.pusher_key)
@tailing = new Travis.Tailing()
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
reset: ->
@store.destroy()
@setup()
@_super.apply(this, arguments);
lookup: ->
@__container__.lookup.apply this, arguments
storeAfterSignInPath: (path) ->
@get('auth').storeAfterSignInPath(path)
autoSignIn: (path) ->
@get('auth').autoSignIn()
signIn: ->
@get('auth').signIn()
signOut: ->
@get('auth').signOut()
receive: ->
@store.receive.apply(@store, arguments)
toggleSidebar: ->
$('body').toggleClass('maximized')
# TODO gotta force redraws here :/
element = $('<span></span>')
$('#top .profile').append(element)
Em.run.later (-> element.remove()), 10
element = $('<span></span>')
$('#repo').append(element)
Em.run.later (-> element.remove()), 10
setLocale: (locale) ->
return unless locale
I18n.locale = locale
Travis.set('locale', locale)
defaultLocale: 'en'
ready: ->
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
I18n.fallbacks = true
@setLocale 'locale', @get('defaultLocale')
currentDate: ->
new Date()
).create()
window.Travis = TravisApplication.create()
Travis.deferReadiness()