Created
September 15, 2012 20:40
-
-
Save odigity/3729651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ember.js Application Setup | |
var App = Ember.Application.create(); | |
App.ApplicationController = Ember.Controller.extend(); | |
App.ApplicationView = Ember.View.extend({ templateName: 'application' }); | |
App.store = DS.Store.create({ | |
// adapter: DS.RESTAdapter.create({bulkCommit: false}), | |
adapter: DS.FixtureAdapter.create(), | |
revision: 4 | |
}); | |
// Ember.js Models | |
App.formatDate = function (date) { return date && (date.toLocaleDateString() + " " + date.toLocaleTimeString()); }; | |
App.Call = DS.Model.extend({ | |
user_id: DS.attr('number'), | |
result: DS.attr('string'), | |
created_at: DS.attr('date'), | |
person: DS.belongsTo('App.Person') | |
}); | |
App.List = DS.Model.extend({ | |
name: DS.attr('string'), | |
description: DS.attr('string'), | |
created_at: DS.attr('date'), | |
updated_at: DS.attr('date'), | |
people: DS.hasMany('App.Person') | |
}); | |
App.Person = DS.Model.extend({ | |
name: DS.attr('string'), | |
address: DS.attr('string'), | |
phone: DS.attr('string'), | |
note: DS.attr('string'), | |
completed: DS.attr('boolean'), | |
result: DS.attr('string'), | |
last_called_at: DS.attr('date'), | |
list: DS.belongsTo('App.List'), | |
calls: DS.hasMany('App.Call'), | |
last_called_at_formatted: function () { | |
return App.formatDate(this.get('last_called_at')); | |
}.property('last_called_at') | |
}); | |
App.List.FIXTURES = [{ | |
id: 1, | |
name: 'Cool List', | |
description: 'a very cool list', | |
people: [2, 3] | |
}]; | |
App.Person.FIXTURES = [{ | |
id: 2, | |
name: 'Joe Blow', | |
address: '123 Main St', | |
phone: '123-456-7890', | |
last_called_at: new Date('2012-01-01T12:34:56Z') | |
}, | |
{ | |
id: 3, | |
name: 'Jane Doe', | |
address: '456 Main St', | |
phone: '098-765-4321' | |
}]; | |
// Ember.js Views | |
App.ListsController = Ember.ArrayController.extend(); | |
App.ListsView = Ember.View.extend({ templateName: 'lists' }); | |
App.ListController = Ember.ObjectController.extend(); | |
App.ListView = Ember.View.extend({ templateName: 'list' }); | |
// Ember.js Router | |
App.router = Ember.Router.create({ | |
enableLogging: true, | |
root: Ember.Route.extend({ | |
index: Ember.Route.extend({ | |
route: '/', | |
redirectsTo: 'lists' | |
}), | |
lists: Ember.Route.extend({ | |
route: '/lists', | |
connectOutlets: function (router) { | |
router.get('applicationController').connectOutlet('lists', App.store.findAll(App.List)); | |
}, | |
showList: Ember.Route.transitionTo('list') | |
}), | |
list: Ember.Route.extend({ | |
route: '/lists/:id', | |
serialize: function(router, context){ | |
return {id: context.get('id')}; | |
}, | |
deserialize: function(router, urlParams){ | |
return App.store.find(App.List, urlParams.id); | |
}, | |
connectOutlets: function (router, context) { | |
router.get('applicationController').connectOutlet('list', context); | |
} | |
}), | |
showLists: Ember.Route.transitionTo('lists') | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment