Skip to content

Instantly share code, notes, and snippets.

@kevinansfield
Created February 20, 2013 14:17
Show Gist options
  • Select an option

  • Save kevinansfield/4995819 to your computer and use it in GitHub Desktop.

Select an option

Save kevinansfield/4995819 to your computer and use it in GitHub Desktop.
App.CurrentUserController = Ember.ObjectController.extend
isSignedIn: (->
@get('content') != null
).property('@content')
App.ApplicationController = Ember.Controller.extend
needs: ['currentUser']
isHome: (->
@get('currentRoute') == 'home'
).property('currentRoute')
isNewsfeed: (->
@get('currentRoute') == 'newsfeed'
).property('currentRoute')
isProfile: (->
@get('currentRoute') == 'profile'
).property('currentRoute')
isMessages: (->
@get('currentRoute') == 'messages'
).property('currentRoute')
isNotifications: (->
@get('currentRoute') == 'notifications'
).property('currentRoute')
isAccount: (->
@get('currentRoute') == 'account'
).property('currentRoute')
App.UserController = Ember.ObjectController.extend
needs: ['currentUser']
profile: (->
@content.get('current_profile')
).property('content.current_profile')
App.UserFullController = Ember.ObjectController.extend
needs: 'user'
Ember.Application.initializer
name: 'currentUser'
initialize: (container) ->
store = container.lookup('store:main')
attributes = $('meta[name="current-user"]').attr('content')
if attributes
object = store.load(App.User, JSON.parse(attributes))
user = App.User.find(object.id)
controller = container.lookup('controller:currentUser').set('content', user)
App.User = DS.Model.extend
username: DS.attr('string')
email: DS.attr('string')
current_profile: DS.belongsTo('App.Profile')
profiles: DS.hasMany('App.Profile')
App.Profile = DS.Model.extend
firstName: DS.attr('string')
lastName: DS.attr('string')
gender: DS.attr('string')
aboutMe: DS.attr('string')
location: DS.attr('string')
education: DS.attr('string')
occupation: DS.attr('string')
user: DS.belongsTo('App.User')
fullName: (->
firstName = @get('firstName') || ''
lastName = @get('lastName') || ''
firstName + ' ' + lastName
).property('firstName', 'lastName')
App.Router.map ->
@resource 'user', {path: '/user/:user_id'}, ->
@route 'full'
App.UserRoute = Ember.Route.extend
setupController: (controller, model) ->
if model.get('id') == @controllerFor('currentUser').get('id')
@controllerFor('application').set('currentRoute', 'profile')
else
@controllerFor('application').set('currentRoute', '')
App.UserFullRoute = Ember.Route.extend
renderTemplate: ->
@render outlet: 'overlay'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment