Reload page when locale for user changes, also cache it in cookie
This commit is contained in:
parent
a15836c50a
commit
3c303e5a86
|
@ -127,6 +127,11 @@ Travis.Router = Ember.Router.extend
|
||||||
showAccount: Ember.Route.transitionTo('root.profile.account')
|
showAccount: Ember.Route.transitionTo('root.profile.account')
|
||||||
showUserProfile: Ember.Route.transitionTo('root.profile.account.profile')
|
showUserProfile: Ember.Route.transitionTo('root.profile.account.profile')
|
||||||
|
|
||||||
|
reload: ->
|
||||||
|
url = @get('location').getURL()
|
||||||
|
@transitionTo 'loading'
|
||||||
|
@route(url)
|
||||||
|
|
||||||
signedIn: ->
|
signedIn: ->
|
||||||
!!Travis.app.get('auth.user')
|
!!Travis.app.get('auth.user')
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@ require 'ext/ember/namespace'
|
||||||
StatsLayoutView: Travis.View.extend(templateName: 'layouts/simple')
|
StatsLayoutView: Travis.View.extend(templateName: 'layouts/simple')
|
||||||
ApplicationView: Travis.View.extend
|
ApplicationView: Travis.View.extend
|
||||||
templateName: 'application'
|
templateName: 'application'
|
||||||
|
localeDidChange: (->
|
||||||
|
if locale = Travis.app.get('auth.user.locale')
|
||||||
|
Travis.setLocale(locale)
|
||||||
|
Travis.app.get('router').reload()
|
||||||
|
).observes('Travis.app.auth.user.locale')
|
||||||
click: (event) ->
|
click: (event) ->
|
||||||
# TODO: this solves the case of closing menus and popups,
|
# TODO: this solves the case of closing menus and popups,
|
||||||
# but I would like to rewrite it later, not sure how
|
# but I would like to rewrite it later, not sure how
|
||||||
|
|
26
assets/scripts/lib/travis/cookie.coffee
Normal file
26
assets/scripts/lib/travis/cookie.coffee
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# From http://www.quirksmode.org/js/cookies.html
|
||||||
|
Travis.cookie = {
|
||||||
|
set: (name, value, days) ->
|
||||||
|
if days
|
||||||
|
date = new Date()
|
||||||
|
date.setTime date.getTime() + (days * 24 * 60 * 60 * 1000)
|
||||||
|
expires = "; expires=" + date.toGMTString()
|
||||||
|
else
|
||||||
|
expires = ""
|
||||||
|
document.cookie = name + "=" + value + expires + "; path=/"
|
||||||
|
|
||||||
|
get: (name) ->
|
||||||
|
nameEQ = name + "="
|
||||||
|
ca = document.cookie.split(";")
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
while i < ca.length
|
||||||
|
c = ca[i]
|
||||||
|
c = c.substring(1, c.length) while c.charAt(0) is " "
|
||||||
|
return c.substring(nameEQ.length, c.length) if c.indexOf(nameEQ) is 0
|
||||||
|
i++
|
||||||
|
null
|
||||||
|
|
||||||
|
erase: (name) ->
|
||||||
|
createCookie name, "", -1
|
||||||
|
}
|
|
@ -34,9 +34,17 @@ require 'ext/ember/namespace'
|
||||||
|
|
||||||
INTERVALS: { sponsors: -1, times: -1, updateTimes: 1000 }
|
INTERVALS: { sponsors: -1, times: -1, updateTimes: 1000 }
|
||||||
|
|
||||||
|
setLocale: (locale) ->
|
||||||
|
return unless locale
|
||||||
|
|
||||||
|
I18n.locale = locale
|
||||||
|
@cookie.set('locale', locale, 365)
|
||||||
|
|
||||||
run: (attrs) ->
|
run: (attrs) ->
|
||||||
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
|
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
|
||||||
|
|
||||||
|
@setLocale @cookie.get('locale')
|
||||||
|
|
||||||
Ember.run.next this, ->
|
Ember.run.next this, ->
|
||||||
app = Travis.App.create(attrs || {})
|
app = Travis.App.create(attrs || {})
|
||||||
# TODO: router expects the classes for controllers on main namespace, so
|
# TODO: router expects the classes for controllers on main namespace, so
|
||||||
|
@ -50,5 +58,6 @@ require 'ext/ember/namespace'
|
||||||
$ => app.initialize()
|
$ => app.initialize()
|
||||||
|
|
||||||
require 'travis/ajax'
|
require 'travis/ajax'
|
||||||
|
require 'travis/cookie'
|
||||||
require 'app'
|
require 'app'
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
ab2d40c2
|
2ff3d2f6
|
Loading…
Reference in New Issue
Block a user