Created
July 23, 2013 18:23
-
-
Save narkeeso/6064821 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
App = Ember.Application.create({ | |
LOG_TRANSITIONS: true | |
}); | |
// ROUTES | |
// Routes determine the naming convention for controllers, route, and models | |
App.Router.map(function() { | |
this.resource('dashboard', { path: '/onboarding' }); | |
this.resource('onboarding', { path: '/onboarding/:form_id' }, function() { | |
this.route('step1'); | |
this.route('step2'); | |
this.route('step3'); | |
}); | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
redirect: function() { | |
this.transitionTo('dashboard'); | |
} | |
}); | |
App.DashboardRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Form.findAll(); | |
} | |
}); | |
App.OnboardingRoute = Ember.Route.extend({ | |
model: function(params) { | |
return App.Form.find(params.form_id); | |
}, | |
afterModel: function() { | |
this.transitionTo('onboarding.step1'); | |
}, | |
// Use renderTemplate to get more control over outlets | |
renderTemplate: function() { | |
this.render('onboarding'); | |
this.render('onboardingNav', { outlet: 'onboardingNav' }); | |
} | |
}); | |
// CONTROLLERS | |
App.DashboardController = Ember.ArrayController.extend({ | |
create: function(company_name) { | |
var newForm = App.Form.create({ 'restaurant_company': { 'name': company_name } }); | |
newForm.save(); | |
}, | |
remove: function(form) { | |
form.deleteRecord(); | |
} | |
}); | |
App.OnboardingController = Ember.ObjectController.extend({ | |
}); | |
App.OnboardingStep1Controller = Ember.ObjectController.extend({ | |
needs: "onboarding", | |
form: null, | |
formBinding: "controllers.onboarding", | |
update: function() { | |
var updateForm = this.get('controllers.onboarding.model'); | |
updateForm.save(); | |
} | |
}); | |
// MODELS | |
var attr = Ember.attr, hasMany = Ember.hasMany; | |
App.Form = Ember.Model.extend({ | |
id: attr(), | |
firstName: attr(), | |
lastName: attr(), | |
phone: attr(), | |
emailAddress: attr(), | |
password: attr(), | |
restaurantCompany: Ember.belongsTo('App.Company', { key: 'restaurant_company', embedded: true }), | |
fullName: function() { | |
return this.get('first_name') + ' ' + this.get('last_name'); | |
}.property('first_name', 'last_name') | |
}); | |
App.Company = Ember.Model.extend({ | |
'id': attr(), | |
'name': attr(), | |
'phone': attr() | |
}); | |
// ADAPTER | |
App.Form.primaryKey = "_id"; | |
App.Form.url = "http://localhost:3000/forms"; | |
App.Form.adapter = Ember.RESTAdapter.create(); | |
App.Form.collectionKey = "objects"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment