Reload page when locale for user changes, also cache it in cookie

This commit is contained in:
Piotr Sarnacki 2012-10-10 22:37:42 +02:00
parent a15836c50a
commit 3c303e5a86
7 changed files with 48 additions and 3 deletions

View File

@ -127,6 +127,11 @@ Travis.Router = Ember.Router.extend
showAccount: Ember.Route.transitionTo('root.profile.account')
showUserProfile: Ember.Route.transitionTo('root.profile.account.profile')
reload: ->
url = @get('location').getURL()
@transitionTo 'loading'
@route(url)
signedIn: ->
!!Travis.app.get('auth.user')

View File

@ -18,6 +18,11 @@ require 'ext/ember/namespace'
StatsLayoutView: Travis.View.extend(templateName: 'layouts/simple')
ApplicationView: Travis.View.extend
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) ->
# TODO: this solves the case of closing menus and popups,
# but I would like to rewrite it later, not sure how

View 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
}

View File

@ -34,9 +34,17 @@ require 'ext/ember/namespace'
INTERVALS: { sponsors: -1, times: -1, updateTimes: 1000 }
setLocale: (locale) ->
return unless locale
I18n.locale = locale
@cookie.set('locale', locale, 365)
run: (attrs) ->
location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!'
@setLocale @cookie.get('locale')
Ember.run.next this, ->
app = Travis.App.create(attrs || {})
# TODO: router expects the classes for controllers on main namespace, so
@ -50,5 +58,6 @@ require 'ext/ember/namespace'
$ => app.initialize()
require 'travis/ajax'
require 'travis/cookie'
require 'app'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
ab2d40c2
2ff3d2f6